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

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

[elpa] externals/cape de4532bbce: Add cape-file-directory (Fix #43)


From: ELPA Syncer
Subject: [elpa] externals/cape de4532bbce: Add cape-file-directory (Fix #43)
Date: Fri, 3 Jun 2022 07:57:19 -0400 (EDT)

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

    Add cape-file-directory (Fix #43)
---
 cape.el | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/cape.el b/cape.el
index 995af85a28..3caec45bd7 100644
--- a/cape.el
+++ b/cape.el
@@ -78,6 +78,10 @@ Any other non-nil value only checks some other buffers, as 
per
                  (const :tag "some" some)
                  (other :tag "all" t)))
 
+(defcustom cape-file-directory nil
+  "Base directory used by `cape-file."
+  :type '(choice (const nil) string function))
+
 (defcustom cape-file-directory-must-exist t
   "The parent directory must exist for file completion."
   :type 'integer)
@@ -128,12 +132,14 @@ The buffers are scanned for completion candidates by 
`cape-line'."
 
 (defun cape--nonessential-table (table)
   "Mark completion TABLE as `non-essential'."
-  (lambda (str pred action)
-    (let ((non-essential t))
-      (let ((result (funcall table str pred action)))
-        (when (and (eq action 'completion--unquote) (functionp (cadr result)))
-          (cl-callf cape--nonessential-table (cadr result)))
-        result))))
+  (let ((dir default-directory))
+    (lambda (str pred action)
+      (let ((default-directory dir)
+            (non-essential t))
+        (let ((result (funcall table str pred action)))
+          (when (and (eq action 'completion--unquote) (functionp (cadr 
result)))
+            (cl-callf cape--nonessential-table (cadr result)))
+          result)))))
 
 (cl-defun cape--table-with-properties (table &key category (sort t) 
&allow-other-keys)
   "Create completion TABLE with properties.
@@ -235,7 +241,11 @@ If INTERACTIVE is nil the function acts like a Capf."
   (if interactive
       (let ((cape-file-directory-must-exist))
         (cape--interactive #'cape-file))
-    (let* ((bounds (cape--bounds 'filename))
+    (let* ((default-directory (pcase cape-file-directory
+                                ('nil default-directory)
+                                ((pred stringp) cape-file-directory)
+                                (_ (funcall cape-file-directory))))
+           (bounds (cape--bounds 'filename))
            (non-essential t)
            (file (buffer-substring (car bounds) (cdr bounds))))
       (when (or (not cape-file-directory-must-exist)



reply via email to

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