diff options
| author | Lars Ingebrigtsen | 2022-05-10 05:09:15 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-10 05:09:15 +0200 |
| commit | 2d0085f756572856a2ed8d1bf043b59195a3e3f3 (patch) | |
| tree | 9eb62f61091e543dec6bec739562c929afaa7165 | |
| parent | 4c4eda4c314e1226a9e95f4c733416de4df21245 (diff) | |
| download | emacs-2d0085f756572856a2ed8d1bf043b59195a3e3f3.tar.gz emacs-2d0085f756572856a2ed8d1bf043b59195a3e3f3.zip | |
Make dabbrev use the buffer's file name as a source for completions
* lisp/dabbrev.el (dabbrev--find-expansion): Include the buffer's
file name in the completions (bug#8163).
| -rw-r--r-- | lisp/dabbrev.el | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index b04128cf677..8f8d553cdab 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el | |||
| @@ -551,8 +551,9 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 551 | (if (not (or (eq dabbrev--last-buffer dabbrev--last-buffer-found) | 551 | (if (not (or (eq dabbrev--last-buffer dabbrev--last-buffer-found) |
| 552 | (minibuffer-window-active-p (selected-window)))) | 552 | (minibuffer-window-active-p (selected-window)))) |
| 553 | (progn | 553 | (progn |
| 554 | (message "Expansion found in `%s'" | 554 | (when (buffer-name dabbrev--last-buffer) |
| 555 | (buffer-name dabbrev--last-buffer)) | 555 | (message "Expansion found in `%s'" |
| 556 | (buffer-name dabbrev--last-buffer))) | ||
| 556 | (setq dabbrev--last-buffer-found dabbrev--last-buffer)) | 557 | (setq dabbrev--last-buffer-found dabbrev--last-buffer)) |
| 557 | (message nil)) | 558 | (message nil)) |
| 558 | (if (and (or (eq (current-buffer) dabbrev--last-buffer) | 559 | (if (and (or (eq (current-buffer) dabbrev--last-buffer) |
| @@ -770,17 +771,38 @@ of the start of the occurrence." | |||
| 770 | (make-progress-reporter | 771 | (make-progress-reporter |
| 771 | "Scanning for dabbrevs..." | 772 | "Scanning for dabbrevs..." |
| 772 | (- (length dabbrev--friend-buffer-list)) 0 0 1 1.5)))) | 773 | (- (length dabbrev--friend-buffer-list)) 0 0 1 1.5)))) |
| 773 | ;; Walk through the buffers till we find a match. | 774 | (let ((file-name (buffer-file-name)) |
| 774 | (let (expansion) | 775 | file-name-buffer) |
| 775 | (while (and (not expansion) dabbrev--friend-buffer-list) | 776 | (unwind-protect |
| 776 | (setq dabbrev--last-buffer (pop dabbrev--friend-buffer-list)) | 777 | (progn |
| 777 | (set-buffer dabbrev--last-buffer) | 778 | ;; Include the file name components into the abbrev |
| 778 | (progress-reporter-update dabbrev--progress-reporter | 779 | ;; list (because if you have a file name "foobar", it's |
| 779 | (- (length dabbrev--friend-buffer-list))) | 780 | ;; somewhat likely that you'll be talking about foobar |
| 780 | (setq dabbrev--last-expansion-location (point-min)) | 781 | ;; stuff in the file itself). |
| 781 | (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case))) | 782 | (when file-name |
| 782 | (progress-reporter-done dabbrev--progress-reporter) | 783 | (setq file-name-buffer (generate-new-buffer " *abbrev-file*")) |
| 783 | expansion))))) | 784 | (with-current-buffer file-name-buffer |
| 785 | (dolist (part (file-name-split file-name)) | ||
| 786 | (insert part "\n"))) | ||
| 787 | (setq dabbrev--friend-buffer-list | ||
| 788 | (append dabbrev--friend-buffer-list | ||
| 789 | (list file-name-buffer)))) | ||
| 790 | ;; Walk through the buffers till we find a match. | ||
| 791 | (let (expansion) | ||
| 792 | (while (and (not expansion) dabbrev--friend-buffer-list) | ||
| 793 | (setq dabbrev--last-buffer | ||
| 794 | (pop dabbrev--friend-buffer-list)) | ||
| 795 | (set-buffer dabbrev--last-buffer) | ||
| 796 | (progress-reporter-update | ||
| 797 | dabbrev--progress-reporter | ||
| 798 | (- (length dabbrev--friend-buffer-list))) | ||
| 799 | (setq dabbrev--last-expansion-location (point-min)) | ||
| 800 | (setq expansion (dabbrev--try-find | ||
| 801 | abbrev nil 1 ignore-case))) | ||
| 802 | (progress-reporter-done dabbrev--progress-reporter) | ||
| 803 | expansion)) | ||
| 804 | (when (buffer-live-p file-name-buffer) | ||
| 805 | (kill-buffer file-name-buffer)))))))) | ||
| 784 | 806 | ||
| 785 | ;; Compute the list of buffers to scan. | 807 | ;; Compute the list of buffers to scan. |
| 786 | ;; If dabbrev-search-these-buffers-only, then the current buffer | 808 | ;; If dabbrev-search-these-buffers-only, then the current buffer |