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

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

[elpa] externals/consult 116e30998e 2/2: Deprecate consult-project-root-


From: ELPA Syncer
Subject: [elpa] externals/consult 116e30998e 2/2: Deprecate consult-project-root-function (Fix #529)
Date: Sun, 27 Feb 2022 17:57:27 -0500 (EST)

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

    Deprecate consult-project-root-function (Fix #529)
    
    The function has been renamed to consult-project-function, since the 
signature
    has changed. The function must accept a MAY-PROMPT argument now. Note that 
the
    function is set to consult--default-project-function by default, which uses
    project-current from project.el to determine the current project.
---
 CHANGELOG.org    |  1 +
 README.org       | 14 +++++++-------
 consult-imenu.el | 10 +++++-----
 consult.el       | 39 +++++++++++++++++++--------------------
 4 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index aa2a322bbd..98447b6b6b 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -12,6 +12,7 @@
 - Add =consult-register-prefix= option.
 - Introduced a generic and extensible =consult-register= implementation.
 - Lazy marker creation in =consult-line/outline= (performance improvements)
+- Deprecate =consult-project-root-function= in favor of 
=consult-project-function=.
 
 * Version 0.15 (2022-01-31)
 
diff --git a/README.org b/README.org
index ec481379e4..05e42b3a8f 100644
--- a/README.org
+++ b/README.org
@@ -256,7 +256,7 @@ their descriptions.
    =filter-string= is passed to the /fast/ Emacs filtering to further narrow 
down
    the list of matches. This is particularly useful if you are using an 
advanced
    completion style like orderless. =consult-grep= supports preview. If the
-   =consult-project-root-function= returns non-nil, =consult-grep= searches the
+   =consult-project-function= returns non-nil, =consult-grep= searches the
    current project directory. Otherwise the =default-directory= is searched. If
    =consult-grep= is invoked with prefix argument =C-u M-s g=, you can specify 
the
    directory manually.
@@ -886,18 +886,18 @@ configuration examples.
      ;; You may want to use `embark-prefix-help-command' or which-key instead.
      ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") 
#'consult-narrow-help)
 
-     ;; By default `consult-project-root-function' uses `project-root' from 
project.el.
+     ;; By default `consult-project-function' uses `project-root' from 
project.el.
      ;; Optionally configure a different project root function.
      ;; There are multiple reasonable alternatives to chose from.
      ;;;; 1. project.el (the default)
-     ;; (setq consult-project-root-function 
#'consult--project-root-default-function)
+     ;; (setq consult-project-function #'consult--default-project--function)
      ;;;; 2. projectile.el (projectile-project-root)
      ;; (autoload 'projectile-project-root "projectile")
-     ;; (setq consult-project-root-function #'projectile-project-root)
+     ;; (setq consult-project-function (lambda (_) (projectile-project-root)))
      ;;;; 3. vc.el (vc-root-dir)
-     ;; (setq consult-project-root-function #'vc-root-dir)
+     ;; (setq consult-project-function (lambda (_) (vc-root-dir)))
      ;;;; 4. locate-dominating-file
-     ;; (setq consult-project-root-function (lambda () (locate-dominating-file 
"." ".git")))
+     ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." 
".git")))
    )
  #+end_src
 
@@ -947,7 +947,7 @@ configuration examples.
  | consult-preview-max-size         | Files larger than this size are not 
previewed         |
  | consult-preview-raw-size         | Files larger than this size are 
previewed in raw form |
  | consult-project-buffer-sources   | List of virtual project buffer sources   
             |
- | consult-project-root-function    | Function which returns current project 
root           |
+ | consult-project-function         | Function which returns current project 
root           |
  | consult-recent-file-filter       | Filter for =consult-recent-file=         
               |
  | consult-register-prefix          | Prefix string for register keys during 
completion     |
  | consult-ripgrep-args             | Command line arguments for ripgrep       
             |
diff --git a/consult-imenu.el b/consult-imenu.el
index 2ce241342f..c2d83a05c9 100644
--- a/consult-imenu.el
+++ b/consult-imenu.el
@@ -107,10 +107,10 @@ TYPES is the mode-specific types configuration."
   (let* ((imenu-use-markers t)
          ;; Generate imenu, see `imenu--make-index-alist'.
          (items (imenu--truncate-items
-                (save-excursion
-                  (save-restriction
-                    (widen)
-                    (funcall imenu-create-index-function)))))
+                 (save-excursion
+                   (save-restriction
+                     (widen)
+                     (funcall imenu-create-index-function)))))
          (config (cdr (seq-find (lambda (x) (derived-mode-p (car x))) 
consult-imenu-config))))
     ;; Fix toplevel items, e.g., emacs-lisp-mode toplevel items are functions
     (when-let (toplevel (plist-get config :toplevel))
@@ -216,7 +216,7 @@ See also `consult-imenu-multi'."
   "Select item from the imenus of all buffers from the same project.
 
 In order to determine the buffers belonging to the same project, the
-`consult-project-root-function' is used. Only the buffers with the
+`consult-project-function' is used. Only the buffers with the
 same major mode as the current buffer are used. See also
 `consult-imenu' for more details. In order to search a subset of buffers,
 QUERY can be set to a plist according to `consult--buffer-query'."
diff --git a/consult.el b/consult.el
index b06d6c28df..aca106e5e6 100644
--- a/consult.el
+++ b/consult.el
@@ -78,10 +78,14 @@ The key must be either a string or a vector.
 This is the key representation accepted by `define-key'."
   :type '(choice key-sequence (const nil)))
 
-(defcustom consult-project-root-function
-  #'consult--project-root-default-function
-  "Function which returns project root directory.
+(defvar consult-project-root-function nil)
+(make-obsolete-variable 'consult-project-root-function "Deprecated in favor of 
`consult-project-function'." "0.15")
 
+(defcustom consult-project-function
+  #'consult--default-project-function
+  "Function which returns project root directory.
+The function takes one boolargument MAY-PROMPT. If MAY-PROMPT is non-nil,
+the function may ask the prompt the user for a project directory.
 The root directory is used by `consult-buffer' and `consult-grep'."
   :type '(choice function (const nil)))
 
@@ -824,7 +828,7 @@ only the last two path components are shown.
 
 If DIR is a string, it is returned.
 If DIR is a true value, the user is asked.
-Then the `consult-project-root-function' is tried.
+Then the `consult-project-function' is tried.
 Otherwise the `default-directory' is returned."
   (let* ((dir
           (cond
@@ -848,7 +852,7 @@ Otherwise the `default-directory' is returned."
       (t (format "%s (%s): " prompt (consult--abbreviate-directory dir))))
      edir)))
 
-(defun consult--project-root-default-function (&optional may-prompt)
+(defun consult--default-project-function (may-prompt)
   "Return project root directory.
 When no project is found and MAY-PROMPT is non-nil ask the user."
   (when-let (proj (project-current may-prompt))
@@ -859,13 +863,8 @@ When no project is found and MAY-PROMPT is non-nil ask the 
user."
 (defun consult--project-root (&optional may-prompt)
   "Return project root as absolute path.
 When no project is found and MAY-PROMPT is non-nil ask the user."
-  (when-let (root (and consult-project-root-function
-                       (if may-prompt
-                           (condition-case nil
-                               (funcall consult-project-root-function t)
-                             (wrong-number-of-arguments
-                              (funcall consult-project-root-function)))
-                         (funcall consult-project-root-function))))
+  (when-let (root (and consult-project-function
+                       (funcall consult-project-function may-prompt)))
     (expand-file-name root)))
 
 (defun consult--project-name (dir)
@@ -4055,7 +4054,7 @@ If NORECORD is non-nil, do not record the buffer switch 
in the buffer list."
     :face     consult-buffer
     :history  buffer-name-history
     :state    ,#'consult--buffer-state
-    :enabled  ,(lambda () consult-project-root-function)
+    :enabled  ,(lambda () consult-project-function)
     :items
     ,(lambda ()
        (consult--buffer-query :sort 'visibility
@@ -4071,7 +4070,7 @@ If NORECORD is non-nil, do not record the buffer switch 
in the buffer list."
     :face     consult-file
     :history  file-name-history
     :state    ,#'consult--file-state
-    :enabled  ,(lambda () (and consult-project-root-function
+    :enabled  ,(lambda () (and consult-project-function
                                recentf-mode))
     :items
     ,(lambda ()
@@ -4146,7 +4145,7 @@ The command supports recent files, bookmarks, views and 
project files as
 virtual buffers. Buffers are previewed. Narrowing to buffers (b), files (f),
 bookmarks (m) and project files (p) is supported via the corresponding
 keys. In order to determine the project-specific files and buffers, the
-`consult-project-root-function' is used. The virtual buffer SOURCES
+`consult-project-function' is used. The virtual buffer SOURCES
 default to `consult-buffer-sources'. See `consult--multi' for the
 configuration of the virtual buffer sources."
   (interactive)
@@ -4175,14 +4174,14 @@ configuration of the virtual buffer sources."
   ;; project. But who does that? Working on the first level on project A
   ;; and on the second level on project B and on the third level on project C?
   ;; You mustn't be afraid to dream a little bigger, darling.
-  `(let ((consult-project-root-function
+  `(let ((consult-project-function
           (let ((root (or (consult--project-root t) (user-error "No project 
found")))
                 (depth (recursion-depth))
-                (orig consult-project-root-function))
-            (lambda (&rest args)
+                (orig consult-project-function))
+            (lambda (may-prompt)
               (if (= depth (recursion-depth))
                   root
-                (apply orig args))))))
+                (funcall orig may-prompt))))))
      ,@body))
 
 ;;;###autoload
@@ -4434,7 +4433,7 @@ Here we give a few example inputs:
 The symbol at point is added to the future history. If `consult-grep'
 is called interactively with a prefix argument, the user can specify
 the directory to search in. By default the project directory is used
-if `consult-project-root-function' is defined and returns non-nil.
+if `consult-project-function' is defined and returns non-nil.
 Otherwise the `default-directory' is searched."
   (interactive "P")
   (consult--grep "Grep" #'consult--grep-builder dir initial))



reply via email to

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