emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master b3cca57 057/348: Make ivy prompt face overriding modular


From: Oleh Krehel
Subject: [elpa] master b3cca57 057/348: Make ivy prompt face overriding modular
Date: Sat, 8 Apr 2017 11:03:24 -0400 (EDT)

branch: master
commit b3cca57f27423a7c859557b01b7c4e3f8f16b89d
Author: Kaushal Modi <address@hidden>
Commit: Kaushal Modi <address@hidden>

    Make ivy prompt face overriding modular
    
    * ivy--insert-prompt: The ivy--set-match-props calls inside this
    function have been moved to the new variable
    ivy--prompt-text-prop-override-function.  That way, a user can override
    this variable using add-function, if needed.
    * ivy--set-match-props: To add granular control to text property
      overrides, now function accepts an optional fourth argument SUBEXP.  By
      default, the PROPS text property is applied to the whole input string
      STR if it matches the regexp MATCH.  Now it is possible to apply the
      text property only to a sub-expression.  The default behavior is
      retained.
---
 ivy.el | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/ivy.el b/ivy.el
index 30d9f0a..093ae1b 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1920,6 +1920,17 @@ depending on the number of candidates."
     (goto-char (minibuffer-prompt-end))
     (delete-region (line-end-position) (point-max))))
 
+(defvar ivy--prompt-text-prop-override-function
+  (lambda (prompt std-props)
+    (ivy--set-match-props prompt "confirm"
+                          `(face ivy-confirm-face ,@std-props))
+    (ivy--set-match-props prompt "match required"
+                          `(face ivy-match-required-face ,@std-props))
+    prompt)
+  "Function to override the text properties of the default ivy prompt.
+Called with two arguments, PROMPT and STD-PROPS.
+The returned value should be the updated PROMPT.")
+
 (defun ivy--insert-prompt ()
   "Update the prompt according to `ivy--prompt'."
   (when ivy--prompt
@@ -1973,20 +1984,21 @@ depending on the number of candidates."
           (set-text-properties 0 (length n-str)
                                `(face minibuffer-prompt ,@std-props)
                                n-str)
-          (ivy--set-match-props n-str "confirm"
-                                `(face ivy-confirm-face ,@std-props))
-          (ivy--set-match-props n-str "match required"
-                                `(face ivy-match-required-face ,@std-props))
+          (setq n-str (funcall ivy--prompt-text-prop-override-function
+                               n-str std-props))
           (insert n-str))
         ;; get out of the prompt area
         (constrain-to-field nil (point-max))))))
 
-(defun ivy--set-match-props (str match props)
-  "Set STR text properties that match MATCH to PROPS."
+(defun ivy--set-match-props (str match props &optional subexp)
+  "Set STR text properties for regexp group SUBEXP that match MATCH to PROPS.
+If SUBEXP is nil, the text properties are applied to the whole match."
+  (when (null subexp)
+    (setq subexp 0))
   (when (string-match match str)
     (set-text-properties
-     (match-beginning 0)
-     (match-end 0)
+     (match-beginning subexp)
+     (match-end subexp)
      props
      str)))
 



reply via email to

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