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

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

[elpa] externals/consult d8e86fa53b: consult-customize: Evaluate setting


From: ELPA Syncer
Subject: [elpa] externals/consult d8e86fa53b: consult-customize: Evaluate settings at runtime (Fix #437)
Date: Wed, 30 Mar 2022 06:57:24 -0400 (EDT)

branch: externals/consult
commit d8e86fa53b60d80cee0a0efa8721175d0ae90a97
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    consult-customize: Evaluate settings at runtime (Fix #437)
---
 CHANGELOG.org   |  8 +++++++-
 README.org      | 16 ++++++++++++++++
 consult-xref.el |  2 +-
 consult.el      | 37 +++++++++++++++++++++++++------------
 4 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 3e333d8a34..b36197412a 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -2,9 +2,15 @@
 #+author: Daniel Mendler
 #+language: en
 
-* Develop
+* Development
 
 - =consult-goto-line=: Use =goto-line-history= on Emacs 28
+- =consult-customize=: Evaluate settings at runtime. This change makes it 
possible
+  to use =thing-at-point= to overwrite the =:initial= and =:add-history= 
settings.
+- =consult--read-config= renamed to =consult--customize-alist= and changed the
+  format. The configuration is an alist. The car must be a command symbol. The
+  cdr must be a plist of key/expressions pairs, where the expressions evaluate
+  to the actual configuration value.
 
 * Version 0.16 (2022-03-08)
 
diff --git a/README.org b/README.org
index 577177cfc0..ce47d32c20 100644
--- a/README.org
+++ b/README.org
@@ -1000,6 +1000,22 @@ configuration examples.
     :preview-key (list (kbd "<S-down>") (kbd "<S-up>")))
  #+end_src
 
+ The configuration values are evaluated at runtime, just before the completion
+ session is started. Therefore you can use for example =thing-at-point= to 
adjust
+ the initial input or the future hitory.
+
+ #+begin_src emacs-lisp
+   (consult-customize
+    consult-line
+    :add-history (seq-some #'thing-at-point '(region symbol)))
+
+   (defalias 'consult-line-thing-at-point 'consult-line)
+
+   (consult-customize
+    consult-line-thing-at-point
+    :initial (thing-at-point 'symbol))
+ #+end_src
+
  Generally it is possible to modify commands for your individual needs by the
  following techniques:
 
diff --git a/consult-xref.el b/consult-xref.el
index bee3f02d5b..4677aae57c 100644
--- a/consult-xref.el
+++ b/consult-xref.el
@@ -99,7 +99,7 @@ FETCHER and ALIST arguments."
           #'consult--read
           candidates
           (append
-           (alist-get #'consult-xref consult--read-config)
+           (consult--customize-get #'consult-xref)
            (list
             :prompt "Go to xref: "
             :history 'consult-xref--history
diff --git a/consult.el b/consult.el
index 00bed2ed89..efef61af18 100644
--- a/consult.el
+++ b/consult.el
@@ -443,13 +443,14 @@ Used by `consult-completion-in-region', `consult-yank' 
and `consult-history'.")
 The function must return a list of regular expressions and a highlighter
 function.")
 
-(defvar consult--read-config nil
+(defvar consult--customize-alist nil
   "Command configuration alist for fine-grained configuration.
 
-Each element of the list must have the form (command-name plist...). The 
options
-set here will be passed to `consult--read', when called from the corresponding
-command. Note that the options depend on the private `consult--read' API and
-should not be considered as stable as the public API.")
+Each element of the list must have the form (command-name plist...). The
+options set here will be evaluated and passed to `consult--read', when
+called from the corresponding command. Note that the options depend on
+the private `consult--read' API and should not be considered as stable
+as the public API.")
 
 (defvar consult--buffer-display #'switch-to-buffer
   "Buffer display function.")
@@ -504,15 +505,22 @@ We use invalid characters outside the Unicode range.")
 
 ;;;; Customization helper
 
+;; TODO remove obsolete function `consult--customize-set'.
+;; The function exists to avoid issues with precompiled configurations,
+;; which still refer to `consult--customize-set'.
 (defun consult--customize-set (cmds prop val)
   "Set property PROP to VAL of commands CMDS."
+  (consult--customize-put cmds prop `',val))
+
+(defun consult--customize-put (cmds prop form)
+  "Set property PROP to FORM of commands CMDS."
   (dolist (cmd cmds)
     (cond
      ((and (boundp cmd) (consp (symbol-value cmd)))
-      (set cmd (plist-put (symbol-value cmd) prop val)))
+      (set cmd (plist-put (symbol-value cmd) prop (eval form 'lexical))))
      ((functionp cmd)
-      (setf (alist-get cmd consult--read-config)
-            (plist-put (alist-get cmd consult--read-config) prop val)))
+      (setf (alist-get cmd consult--customize-alist)
+            (plist-put (alist-get cmd consult--customize-alist) prop form)))
      (t (user-error "%s is neither a Consult command nor a Consult source"
                     cmd))))
   nil)
@@ -526,10 +534,15 @@ pairs."
       (let ((cmds (seq-take-while (lambda (x) (not (keywordp x))) args)))
         (setq args (seq-drop-while (lambda (x) (not (keywordp x))) args))
         (while (keywordp (car args))
-          (push `(consult--customize-set ',cmds ,(car args) ,(cadr args)) 
setter)
+          (push `(consult--customize-put ',cmds ,(car args) ',(cadr args)) 
setter)
           (setq args (cddr args)))))
     (macroexp-progn setter)))
 
+(defun consult--customize-get (&optional cmd)
+  "Get configuration from `consult--customize-alist' for CMD."
+  (mapcar (lambda (x) (eval x 'lexical))
+          (alist-get (or cmd this-command) consult--customize-alist)))
+
 ;;;; Helper functions and macros
 
 (defun consult--command-split (str)
@@ -2101,7 +2114,7 @@ INHERIT-INPUT-METHOD, if non-nil the minibuffer inherits 
the input method."
           state preview-key sort lookup group inherit-input-method)
   (apply #'consult--read-1 candidates
          (append
-          (alist-get this-command consult--read-config)
+          (consult--customize-get)
           options
           (list :prompt "Select: "
                 :preview-key consult-preview-key
@@ -2327,7 +2340,7 @@ KEYMAP is a command-specific keymap."
           keymap state preview-key transform inherit-input-method)
   (apply #'consult--prompt-1
          (append
-          (alist-get this-command consult--read-config)
+          (consult--customize-get)
           options
           (list :prompt "Input: "
                 :preview-key consult-preview-key
@@ -2385,7 +2398,7 @@ These configuration options are supported:
     * :require-match - Require matches when completing (def: nil)
     * :prompt - The prompt string shown in the minibuffer"
   (barf-if-buffer-read-only)
-  (cl-letf* ((config (alist-get #'consult-completion-in-region 
consult--read-config))
+  (cl-letf* ((config (consult--customize-get #'consult-completion-in-region))
              ;; Overwrite both the local and global value of 
`completion-styles', such that the
              ;; `completing-read' minibuffer sees the overwritten value in any 
case. This is
              ;; necessary if `completion-styles' is buffer-local.



reply via email to

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