[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 1ed6707 2/4: Improve uniquify-files in corner case
From: |
Stephen Leake |
Subject: |
[elpa] master 1ed6707 2/4: Improve uniquify-files in corner case |
Date: |
Wed, 6 Feb 2019 19:42:01 -0500 (EST) |
branch: master
commit 1ed670767339d2300f6818c2b7df4df6b36723c0
Author: Stephen Leake <address@hidden>
Commit: Stephen Leake <address@hidden>
Improve uniquify-files in corner case
* packages/uniquify-files/uniquify-files.el (uniq-file--dir-match):
Include trailing directories.
(locate-uniquified-file-iter, -2): Set completion-category-overrides.
* packages/uniquify-files/uniquify-files-test.el:
(test-uniq-file-all-completions-noface-1): Add test of corner case.
---
packages/uniquify-files/uniquify-files-test.el | 4 ++++
packages/uniquify-files/uniquify-files.el | 24 ++++++++++++++++--------
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/packages/uniquify-files/uniquify-files-test.el
b/packages/uniquify-files/uniquify-files-test.el
index 8950cbd..4dc1923 100644
--- a/packages/uniquify-files/uniquify-files-test.el
+++ b/packages/uniquify-files/uniquify-files-test.el
@@ -356,6 +356,10 @@
"foo-file4.text<Alice/alice-3/>"
"foo-file4.text<Bob/alice-3/>")))
+ (should (equal (sort (uniq-file-all-completions "foo-file4.text<Bob" table
nil nil) #'string-lessp)
+ (list
+ "foo-file4.text<Bob/alice-3/>")))
+
(should (equal (uniq-file-all-completions "f-file5" table nil nil)
(list "foo-file5.text")))
diff --git a/packages/uniquify-files/uniquify-files.el
b/packages/uniquify-files/uniquify-files.el
index b36ec11..59575c2 100644
--- a/packages/uniquify-files/uniquify-files.el
+++ b/packages/uniquify-files/uniquify-files.el
@@ -191,17 +191,20 @@ Match 1 is the filename, match 2 is the relative
directory.")
(regex (completion-pcm--pattern->regex pattern)))
;; `regex' is anchored at the beginning; delete the anchor to
- ;; match a directory in the middle of ABS. Also extend
- ;; the match to the bounding '/'.
+ ;; match a directory in the middle of ABS.
(setq regex (substring regex 2))
+
+ ;; Include the preceding and following '/' .
(unless (= ?/ (aref regex 0))
(setq regex (concat "/" regex)))
(unless (= ?/ (aref regex (1- (length regex))))
(setq regex (concat regex "[^/]*/" )))
(when (string-match regex abs);; Should never fail, but gives obscure
error if it does
- ;; Drop the leading '/'
- (substring (match-string 0 abs) 1))
+
+ ;; Drop the leading '/', include all trailing directories;
+ ;; consider Bob/alice-3/foo, Alice/alice-3/foo.
+ (substring abs (1+ (match-beginning 0))))
))
(t
@@ -792,10 +795,15 @@ file name is included in the result if PRED returns
non-nil. DEFAULT is the default for completion.
In the user input string, `*' is treated as a wildcard."
- (completing-read (format (concat (or prompt "file") " (%s): ") default)
- (apply-partially #'uniq-file-completion-table iter)
- predicate t nil nil default)
- )
+ (let* ((table (apply-partially #'uniq-file-completion-table iter))
+ (table-styles (cdr (assq 'styles (completion-metadata "" table nil))))
+ (completion-category-overrides
+ (list (list 'project-file (cons 'styles table-styles)))))
+
+ (completing-read (format (concat (or prompt "file") " (%s): ") default)
+ table
+ predicate t nil nil default)
+ ))
(defun locate-uniquified-file-iter-2 (iter &optional predicate default prompt)
"Same as `locate-uniquified-file-iter', but the internal