emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/icomplete-vertical d1b38d8 08/20: Add icomplete--format-function


From: Jimmy Aguilar Mena
Subject: feature/icomplete-vertical d1b38d8 08/20: Add icomplete--format-function to format items.
Date: Thu, 24 Sep 2020 22:58:20 -0400 (EDT)

branch: feature/icomplete-vertical
commit d1b38d80f41390218f7bb99523900ebb66b340a3
Author: Jimmy Aguilar Mena <spacibba@aol.com>
Commit: Jimmy Aguilar Mena <spacibba@aol.com>

    Add icomplete--format-function to format items.
    
    Add custom icomplete-item-format to accept functions, string formats and
    nil.
---
 lisp/icomplete.el | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index a357935..ebf251c 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -149,9 +149,17 @@ icompletion is occurring."
   :version "28.1")
 
 
-(defcustom icomplete-item-format "%s"
-  "Indicator bounds for match in the minibuffer when require-match."
-  :type 'string
+(defcustom icomplete-item-format nil
+  "Format to use in every completion item.
+
+When this variable is a string the items are added using the
+format function.  When this variable is a function the items are
+calling the function and passing it as a parameter.  The function
+is passed to mapcar and should receive one string argument and
+return a string."
+  :type '(choice (string :tag "String format")
+                (function :tag "Format function")
+                (const :tag "None" nil))
   :version "28.1")
 
 (defvar icomplete--separator nil
@@ -450,6 +458,14 @@ completions:
          (md (completion--field-metadata beg)))
     (alist-get 'category (cdr md))))
 
+(defun icomplete--format-function (item)
+  (cond
+   ((stringp icomplete-item-format)
+    (format icomplete-item-format item))
+   ((functionp icomplete-item-format)
+    (funcall icomplete-item-format item))
+   (t item)))
+
 ;;;_ > icomplete-simple-completing-p ()
 (defun icomplete-simple-completing-p ()
   "Non-nil if current window is a minibuffer that's doing simple completion.
@@ -950,9 +966,7 @@ minibuffer completion."
            (concat determ
                     (format icomplete--list-indicators
                            (mapconcat
-                             (lambda (item)
-                               (format icomplete-item-format item))
-                             prospects icomplete--separator)))
+                             #'icomplete--format-function prospects 
icomplete--separator)))
          (concat determ " [Matched]"))))))
 
 ;;; Iswitchb compatibility



reply via email to

[Prev in Thread] Current Thread [Next in Thread]