diff options
| author | Andreas Politz | 2017-10-26 08:59:05 +0200 |
|---|---|---|
| committer | Andreas Politz | 2017-11-04 21:48:54 +0100 |
| commit | d3233b437eb8757e3c5abc1b50f100ea53ca9e15 (patch) | |
| tree | 369c0951484e63f15ef1ff882bc1c0047fca76af | |
| parent | bd886c6f566cb1e79e388305f8be05e55753b730 (diff) | |
| download | emacs-d3233b437eb8757e3c5abc1b50f100ea53ca9e15.tar.gz emacs-d3233b437eb8757e3c5abc1b50f100ea53ca9e15.zip | |
Make filecache use extended completion
* lisp/filecache.el (file-cache-minibuffer-complete): Use
completion-try-completion and completion-all-completions.
* etc/NEWS: Add news entry.
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/filecache.el | 111 |
2 files changed, 61 insertions, 56 deletions
| @@ -103,6 +103,12 @@ less verbose by removing non-essential information. | |||
| 103 | dimensions, instead of always using 16 pixels. As a result, Tetris, | 103 | dimensions, instead of always using 16 pixels. As a result, Tetris, |
| 104 | Snake and Pong are more playable on HiDPI displays. | 104 | Snake and Pong are more playable on HiDPI displays. |
| 105 | 105 | ||
| 106 | ** Filecache | ||
| 107 | |||
| 108 | --- | ||
| 109 | *** Completing filenames in the minibuffer via 'C-TAB' now uses the | ||
| 110 | styles as configured by the variable 'completion-styles'. | ||
| 111 | |||
| 106 | 112 | ||
| 107 | * New Modes and Packages in Emacs 27.1 | 113 | * New Modes and Packages in Emacs 27.1 |
| 108 | 114 | ||
diff --git a/lisp/filecache.el b/lisp/filecache.el index 38a434b11ba..aac4f488cd9 100644 --- a/lisp/filecache.el +++ b/lisp/filecache.el | |||
| @@ -566,68 +566,67 @@ the directories that the name is available in. With a prefix argument, | |||
| 566 | the name is considered already unique; only the second substitution | 566 | the name is considered already unique; only the second substitution |
| 567 | \(directories) is done." | 567 | \(directories) is done." |
| 568 | (interactive "P") | 568 | (interactive "P") |
| 569 | (let* | 569 | (let* ((completion-ignore-case file-cache-completion-ignore-case) |
| 570 | ( | 570 | (case-fold-search file-cache-case-fold-search) |
| 571 | (completion-ignore-case file-cache-completion-ignore-case) | 571 | (string (file-name-nondirectory (minibuffer-contents))) |
| 572 | (case-fold-search file-cache-case-fold-search) | 572 | (completion (completion-try-completion |
| 573 | (string (file-name-nondirectory (minibuffer-contents))) | 573 | string file-cache-alist nil 0))) |
| 574 | (completion-string (try-completion string file-cache-alist)) | ||
| 575 | (completion-list) | ||
| 576 | (len) | ||
| 577 | (file-cache-string)) | ||
| 578 | (cond | 574 | (cond |
| 579 | ;; If it's the only match, replace the original contents | 575 | ;; If it's the only match, replace the original contents |
| 580 | ((or arg (eq completion-string t)) | 576 | ((or arg (eq completion t)) |
| 581 | (setq file-cache-string (file-cache-file-name string)) | 577 | (let ((file-name (file-cache-file-name string))) |
| 582 | (if (string= file-cache-string (minibuffer-contents)) | 578 | (if (string= file-name (minibuffer-contents)) |
| 583 | (minibuffer-message file-cache-sole-match-message) | 579 | (minibuffer-message file-cache-sole-match-message) |
| 584 | (delete-minibuffer-contents) | 580 | (delete-minibuffer-contents) |
| 585 | (insert file-cache-string) | 581 | (insert file-name) |
| 586 | (if file-cache-multiple-directory-message | 582 | (if file-cache-multiple-directory-message |
| 587 | (minibuffer-message file-cache-multiple-directory-message)))) | 583 | (minibuffer-message file-cache-multiple-directory-message))))) |
| 588 | 584 | ||
| 589 | ;; If it's the longest match, insert it | 585 | ;; If it's the longest match, insert it |
| 590 | ((stringp completion-string) | 586 | ((consp completion) |
| 591 | ;; If we've already inserted a unique string, see if the user | 587 | (let ((newstring (car completion)) |
| 592 | ;; wants to use that one | 588 | (newpoint (cdr completion))) |
| 593 | (if (and (string= string completion-string) | 589 | ;; If we've already inserted a unique string, see if the user |
| 594 | (assoc-string string file-cache-alist | 590 | ;; wants to use that one |
| 595 | file-cache-ignore-case)) | 591 | (if (and (string= string newstring) |
| 596 | (if (and (eq last-command this-command) | 592 | (assoc-string string file-cache-alist |
| 597 | (string= file-cache-last-completion completion-string)) | 593 | file-cache-ignore-case)) |
| 598 | (progn | 594 | (if (and (eq last-command this-command) |
| 599 | (delete-minibuffer-contents) | 595 | (string= file-cache-last-completion newstring)) |
| 600 | (insert (file-cache-file-name completion-string)) | 596 | (progn |
| 601 | (setq file-cache-last-completion nil)) | 597 | (delete-minibuffer-contents) |
| 602 | (minibuffer-message file-cache-non-unique-message) | 598 | (insert (file-cache-file-name newstring)) |
| 603 | (setq file-cache-last-completion string)) | 599 | (setq file-cache-last-completion nil)) |
| 604 | (setq file-cache-last-completion string) | 600 | (minibuffer-message file-cache-non-unique-message) |
| 605 | (setq completion-list (all-completions string file-cache-alist) | 601 | (setq file-cache-last-completion string)) |
| 606 | len (length completion-list)) | 602 | (setq file-cache-last-completion string) |
| 607 | (if (> len 1) | 603 | (let* ((completion-list (completion-all-completions |
| 608 | (progn | 604 | newstring file-cache-alist nil newpoint)) |
| 609 | (goto-char (point-max)) | 605 | (base-size (cdr (last completion-list)))) |
| 610 | (insert | 606 | (when base-size |
| 611 | (substring completion-string (length string))) | 607 | (setcdr (last completion-list) nil)) |
| 612 | ;; Add our own setup function to the Completions Buffer | 608 | (if (> (length completion-list) 1) |
| 613 | (let ((completion-setup-hook | 609 | (progn |
| 614 | (append completion-setup-hook | 610 | (delete-region (- (point-max) (length string)) (point-max)) |
| 615 | (list 'file-cache-completion-setup-function)))) | 611 | (save-excursion (insert newstring)) |
| 616 | (with-output-to-temp-buffer file-cache-completions-buffer | 612 | (forward-char newpoint) |
| 617 | (display-completion-list | 613 | ;; Add our own setup function to the Completions Buffer |
| 618 | (completion-hilit-commonality completion-list | 614 | (let ((completion-setup-hook |
| 619 | (length string)))))) | 615 | (append completion-setup-hook |
| 620 | (setq file-cache-string (file-cache-file-name completion-string)) | 616 | (list 'file-cache-completion-setup-function)))) |
| 621 | (if (string= file-cache-string (minibuffer-contents)) | 617 | (with-output-to-temp-buffer file-cache-completions-buffer |
| 622 | (minibuffer-message file-cache-sole-match-message) | 618 | (display-completion-list |
| 623 | (delete-minibuffer-contents) | 619 | (completion-hilit-commonality completion-list newpoint))))) |
| 624 | (insert file-cache-string) | 620 | (let ((file-name (file-cache-file-name newstring))) |
| 625 | (if file-cache-multiple-directory-message | 621 | (if (string= file-name (minibuffer-contents)) |
| 626 | (minibuffer-message file-cache-multiple-directory-message))) | 622 | (minibuffer-message file-cache-sole-match-message) |
| 627 | ))) | 623 | (delete-minibuffer-contents) |
| 624 | (insert file-name) | ||
| 625 | (if file-cache-multiple-directory-message | ||
| 626 | (minibuffer-message file-cache-multiple-directory-message))))))))) | ||
| 628 | 627 | ||
| 629 | ;; No match | 628 | ;; No match |
| 630 | ((eq completion-string nil) | 629 | ((eq completion nil) |
| 631 | (minibuffer-message file-cache-no-match-message))))) | 630 | (minibuffer-message file-cache-no-match-message))))) |
| 632 | 631 | ||
| 633 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 632 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |