diff options
| author | Glenn Morris | 2007-03-27 03:17:42 +0000 |
|---|---|---|
| committer | Glenn Morris | 2007-03-27 03:17:42 +0000 |
| commit | 8dbe4a8cca6ca7972ad942dee9cce2c36a40ebe4 (patch) | |
| tree | 1aaf9a3a51a7a9d1af698f3fb5c347eda236bdb4 | |
| parent | 6afdff63e597da2d0e9fed9e474d819fec161a5b (diff) | |
| download | emacs-8dbe4a8cca6ca7972ad942dee9cce2c36a40ebe4.tar.gz emacs-8dbe4a8cca6ca7972ad942dee9cce2c36a40ebe4.zip | |
(PC-do-completion): Compute completion-base-size in
the non-filename case, rather than setting to nil.
(PC-lisp-complete-end): New variable.
(PC-lisp-complete-symbol): Use PC-lisp-complete-end to store the
original end in a series of consecutive invocations.
| -rw-r--r-- | lisp/complete.el | 76 |
1 files changed, 60 insertions, 16 deletions
diff --git a/lisp/complete.el b/lisp/complete.el index e86d71c16be..15ee5112ea7 100644 --- a/lisp/complete.el +++ b/lisp/complete.el | |||
| @@ -416,7 +416,7 @@ of `minibuffer-completion-table' and the minibuffer contents.") | |||
| 416 | (let* ((table minibuffer-completion-table) | 416 | (let* ((table minibuffer-completion-table) |
| 417 | (pred minibuffer-completion-predicate) | 417 | (pred minibuffer-completion-predicate) |
| 418 | (filename (funcall PC-completion-as-file-name-predicate)) | 418 | (filename (funcall PC-completion-as-file-name-predicate)) |
| 419 | (dirname nil) ; non-nil only if a filename is being completed | 419 | (dirname nil) ; non-nil only if a filename is being completed |
| 420 | ;; The following used to be "(dirlength 0)" which caused the erasure of | 420 | ;; The following used to be "(dirlength 0)" which caused the erasure of |
| 421 | ;; the entire buffer text before `point' when inserting a completion | 421 | ;; the entire buffer text before `point' when inserting a completion |
| 422 | ;; into a buffer. | 422 | ;; into a buffer. |
| @@ -681,7 +681,7 @@ of `minibuffer-completion-table' and the minibuffer contents.") | |||
| 681 | (forward-char 1) | 681 | (forward-char 1) |
| 682 | (if (and (< (point) end) | 682 | (if (and (< (point) end) |
| 683 | (and (looking-at " ") | 683 | (and (looking-at " ") |
| 684 | (memq (aref prefix i) | 684 | (memq (aref prefix i) |
| 685 | PC-delims-list))) | 685 | PC-delims-list))) |
| 686 | ;; replace " " by the actual delimiter | 686 | ;; replace " " by the actual delimiter |
| 687 | (progn | 687 | (progn |
| @@ -689,12 +689,12 @@ of `minibuffer-completion-table' and the minibuffer contents.") | |||
| 689 | (insert (substring prefix i (1+ i)))) | 689 | (insert (substring prefix i (1+ i)))) |
| 690 | ;; insert a new character | 690 | ;; insert a new character |
| 691 | (progn | 691 | (progn |
| 692 | (and filename (looking-at "\\*") | 692 | (and filename (looking-at "\\*") |
| 693 | (progn | 693 | (progn |
| 694 | (delete-char 1) | 694 | (delete-char 1) |
| 695 | (setq end (1- end)))) | 695 | (setq end (1- end)))) |
| 696 | (setq improved t) | 696 | (setq improved t) |
| 697 | (insert (substring prefix i (1+ i))) | 697 | (insert (substring prefix i (1+ i))) |
| 698 | (setq end (1+ end))))) | 698 | (setq end (1+ end))))) |
| 699 | (setq i (1+ i))) | 699 | (setq i (1+ i))) |
| 700 | (or pt (setq pt (point))) | 700 | (or pt (setq pt (point))) |
| @@ -729,7 +729,7 @@ of `minibuffer-completion-table' and the minibuffer contents.") | |||
| 729 | 729 | ||
| 730 | ;; We changed it... would it be complete without the space? | 730 | ;; We changed it... would it be complete without the space? |
| 731 | (if (test-completion (buffer-substring 1 (1- end)) | 731 | (if (test-completion (buffer-substring 1 (1- end)) |
| 732 | table pred) | 732 | table pred) |
| 733 | (delete-region (1- end) end))) | 733 | (delete-region (1- end) end))) |
| 734 | 734 | ||
| 735 | (if improved | 735 | (if improved |
| @@ -743,13 +743,25 @@ of `minibuffer-completion-table' and the minibuffer contents.") | |||
| 743 | (and completion-auto-help | 743 | (and completion-auto-help |
| 744 | (eq last-command this-command)) | 744 | (eq last-command this-command)) |
| 745 | (eq mode 'help)) | 745 | (eq mode 'help)) |
| 746 | (with-output-to-temp-buffer "*Completions*" | 746 | (let ((prompt-end (minibuffer-prompt-end))) |
| 747 | (display-completion-list (sort helpposs 'string-lessp)) | 747 | (with-output-to-temp-buffer "*Completions*" |
| 748 | (with-current-buffer standard-output | 748 | (display-completion-list (sort helpposs 'string-lessp)) |
| 749 | ;; Record which part of the buffer we are completing | 749 | (with-current-buffer standard-output |
| 750 | ;; so that choosing a completion from the list | 750 | ;; Record which part of the buffer we are completing |
| 751 | ;; knows how much old text to replace. | 751 | ;; so that choosing a completion from the list |
| 752 | (setq completion-base-size dirlength))) | 752 | ;; knows how much old text to replace. |
| 753 | ;; This was briefly nil in the non-dirname case. | ||
| 754 | ;; However, if one calls PC-lisp-complete-symbol | ||
| 755 | ;; on "(ne-f" with point on the hyphen, PC offers | ||
| 756 | ;; all completions starting with "(ne", some of | ||
| 757 | ;; which do not match the "-f" part (maybe it | ||
| 758 | ;; should not, but it does). In such cases, | ||
| 759 | ;; completion gets confused trying to figure out | ||
| 760 | ;; how much to replace, so we tell it explicitly | ||
| 761 | ;; (ie, the number of chars in the buffer before beg). | ||
| 762 | (setq completion-base-size (if dirname | ||
| 763 | dirlength | ||
| 764 | (- beg prompt-end)))))) | ||
| 753 | (PC-temp-minibuffer-message " [Next char not unique]")) | 765 | (PC-temp-minibuffer-message " [Next char not unique]")) |
| 754 | nil))))) | 766 | nil))))) |
| 755 | 767 | ||
| @@ -799,6 +811,8 @@ of `minibuffer-completion-table' and the minibuffer contents.") | |||
| 799 | (setq quit-flag nil | 811 | (setq quit-flag nil |
| 800 | unread-command-events '(7)))))))) | 812 | unread-command-events '(7)))))))) |
| 801 | 813 | ||
| 814 | (defvar PC-lisp-complete-end nil | ||
| 815 | "Internal variable used by `PC-lisp-complete-symbol'.") | ||
| 802 | 816 | ||
| 803 | (defun PC-lisp-complete-symbol () | 817 | (defun PC-lisp-complete-symbol () |
| 804 | "Perform completion on Lisp symbol preceding point. | 818 | "Perform completion on Lisp symbol preceding point. |
| @@ -825,7 +839,37 @@ or properties are considered." | |||
| 825 | (or (boundp sym) (fboundp sym) | 839 | (or (boundp sym) (fboundp sym) |
| 826 | (symbol-plist sym)))))) | 840 | (symbol-plist sym)))))) |
| 827 | (PC-not-minibuffer t)) | 841 | (PC-not-minibuffer t)) |
| 828 | (PC-do-completion nil beg end))) | 842 | ;; http://lists.gnu.org/archive/html/emacs-devel/2007-03/msg01211.html |
| 843 | ;; | ||
| 844 | ;; This deals with cases like running PC-l-c-s on "M-: (n-f". | ||
| 845 | ;; The first call to PC-l-c-s expands this to "(ne-f", and moves | ||
| 846 | ;; point to the hyphen [1]. If one calls PC-l-c-s immediately after, | ||
| 847 | ;; then without the last-command check, one is offered all | ||
| 848 | ;; completions of "(ne", which is presumably not what one wants. | ||
| 849 | ;; | ||
| 850 | ;; This is arguably (at least, it seems to be the existing intended | ||
| 851 | ;; behaviour) what one _does_ want if point has been explicitly | ||
| 852 | ;; positioned on the hyphen. Note that if PC-do-completion (qv) binds | ||
| 853 | ;; completion-base-size to nil, then completion does not replace the | ||
| 854 | ;; correct amount of text in such cases. | ||
| 855 | ;; | ||
| 856 | ;; Neither of these problems occur when using PC for filenames in the | ||
| 857 | ;; minibuffer, because in that case PC-do-completion is called without | ||
| 858 | ;; an explicit value for END, and so uses (point-max). This is fine for | ||
| 859 | ;; a filename, because the end of the filename must be at the end of | ||
| 860 | ;; the minibuffer. The same is not true for lisp symbols. | ||
| 861 | ;; | ||
| 862 | ;; [1] An alternate fix would be to not move point to the hyphen | ||
| 863 | ;; in such cases, but that would make the behaviour different from | ||
| 864 | ;; that for filenames. It seems PC moves point to the site of the | ||
| 865 | ;; first difference between the possible completions. | ||
| 866 | ;; | ||
| 867 | ;; Alternatively alternatively, maybe end should be computed in | ||
| 868 | ;; the same way as beg. That would change the behaviour though. | ||
| 869 | (if (equal last-command 'PC-lisp-complete-symbol) | ||
| 870 | (PC-do-completion nil beg PC-lisp-complete-end) | ||
| 871 | (setq PC-lisp-complete-end (point-marker)) | ||
| 872 | (PC-do-completion nil beg end)))) | ||
| 829 | 873 | ||
| 830 | (defun PC-complete-as-file-name () | 874 | (defun PC-complete-as-file-name () |
| 831 | "Perform completion on file names preceding point. | 875 | "Perform completion on file names preceding point. |