Changeset 4200 for trunk/lisp/complete.el
- Timestamp:
- 04/07/07 15:49:28 (2 years ago)
- Files:
-
- trunk/lisp/complete.el (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lisp/complete.el
r4196 r4200 187 187 188 188 (define-key global-map [remap lisp-complete-symbol] 'PC-lisp-complete-symbol))))) 189 190 (defvar PC-do-completion-end nil 191 "Internal variable used by `PC-do-completion'.") 189 192 190 193 ;;;###autoload … … 240 243 'choose-completion-string-functions 241 244 (lambda (choice buffer mini-p base-size) 242 (if mini-p (goto-char (point-max))) 245 (if mini-p (goto-char (point-max)) 246 ;; Need a similar hack for the non-minibuffer-case -- gm. 247 (when PC-do-completion-end 248 (goto-char PC-do-completion-end) 249 (setq PC-do-completion-end nil))) 243 250 nil)) 244 251 ;; Build the env-completion and mapping table. … … 417 424 (pred minibuffer-completion-predicate) 418 425 (filename (funcall PC-completion-as-file-name-predicate)) 419 (dirname nil) ; non-nil only if a filename is being completed426 (dirname nil) ; non-nil only if a filename is being completed 420 427 ;; The following used to be "(dirlength 0)" which caused the erasure of 421 428 ;; the entire buffer text before `point' when inserting a completion … … 682 689 (if (and (< (point) end) 683 690 (and (looking-at " ") 684 (memq (aref prefix i)691 (memq (aref prefix i) 685 692 PC-delims-list))) 686 693 ;; replace " " by the actual delimiter … … 690 697 ;; insert a new character 691 698 (progn 692 (and filename (looking-at "\\*")693 (progn694 (delete-char 1)695 (setq end (1- end))))699 (and filename (looking-at "\\*") 700 (progn 701 (delete-char 1) 702 (setq end (1- end)))) 696 703 (setq improved t) 697 (insert (substring prefix i (1+ i)))704 (insert (substring prefix i (1+ i))) 698 705 (setq end (1+ end))))) 699 706 (setq i (1+ i))) … … 730 737 ;; We changed it... would it be complete without the space? 731 738 (if (test-completion (buffer-substring 1 (1- end)) 732 table pred)739 table pred) 733 740 (delete-region (1- end) end))) 734 741 … … 744 751 (eq last-command this-command)) 745 752 (eq mode 'help)) 746 (with-output-to-temp-buffer "*Completions*" 747 (display-completion-list (sort helpposs 'string-lessp)) 748 (with-current-buffer standard-output 749 ;; Record which part of the buffer we are completing 750 ;; so that choosing a completion from the list 751 ;; knows how much old text to replace. 752 (setq completion-base-size dirlength))) 753 (let ((prompt-end (minibuffer-prompt-end))) 754 (with-output-to-temp-buffer "*Completions*" 755 (display-completion-list (sort helpposs 'string-lessp)) 756 (with-current-buffer standard-output 757 ;; Record which part of the buffer we are completing 758 ;; so that choosing a completion from the list 759 ;; knows how much old text to replace. 760 ;; This was briefly nil in the non-dirname case. 761 ;; However, if one calls PC-lisp-complete-symbol 762 ;; on "(ne-f" with point on the hyphen, PC offers 763 ;; all completions starting with "(ne", some of 764 ;; which do not match the "-f" part (maybe it 765 ;; should not, but it does). In such cases, 766 ;; completion gets confused trying to figure out 767 ;; how much to replace, so we tell it explicitly 768 ;; (ie, the number of chars in the buffer before beg). 769 ;; 770 ;; Note that choose-completion-string-functions 771 ;; plays around with point. 772 (setq completion-base-size (if dirname 773 dirlength 774 (- beg prompt-end)) 775 PC-do-completion-end end)))) 753 776 (PC-temp-minibuffer-message " [Next char not unique]")) 754 777 nil))))) … … 800 823 unread-command-events '(7)))))))) 801 824 825 ;; Does not need to be buffer-local (?) because only used when one 826 ;; PC-l-c-s immediately follows another. 827 (defvar PC-lisp-complete-end nil 828 "Internal variable used by `PC-lisp-complete-symbol'.") 802 829 803 830 (defun PC-lisp-complete-symbol () … … 812 839 (interactive) 813 840 (let* ((end (point)) 841 ;; To complete the word under point, rather than just the portion 842 ;; before point, use this: 843 ;;; (save-excursion 844 ;;; (with-syntax-table lisp-mode-syntax-table 845 ;;; (forward-sexp 1) 846 ;;; (point)))) 814 847 (beg (save-excursion 815 848 (with-syntax-table lisp-mode-syntax-table … … 826 859 (symbol-plist sym)))))) 827 860 (PC-not-minibuffer t)) 828 (PC-do-completion nil beg end))) 861 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-03/msg01211.html 862 ;; 863 ;; This deals with cases like running PC-l-c-s on "M-: (n-f". 864 ;; The first call to PC-l-c-s expands this to "(ne-f", and moves 865 ;; point to the hyphen [1]. If one calls PC-l-c-s immediately after, 866 ;; then without the last-command check, one is offered all 867 ;; completions of "(ne", which is presumably not what one wants. 868 ;; 869 ;; This is arguably (at least, it seems to be the existing intended 870 ;; behaviour) what one _does_ want if point has been explicitly 871 ;; positioned on the hyphen. Note that if PC-do-completion (qv) binds 872 ;; completion-base-size to nil, then completion does not replace the 873 ;; correct amount of text in such cases. 874 ;; 875 ;; Neither of these problems occur when using PC for filenames in the 876 ;; minibuffer, because in that case PC-do-completion is called without 877 ;; an explicit value for END, and so uses (point-max). This is fine for 878 ;; a filename, because the end of the filename must be at the end of 879 ;; the minibuffer. The same is not true for lisp symbols. 880 ;; 881 ;; [1] An alternate fix would be to not move point to the hyphen 882 ;; in such cases, but that would make the behaviour different from 883 ;; that for filenames. It seems PC moves point to the site of the 884 ;; first difference between the possible completions. 885 ;; 886 ;; Alternatively alternatively, maybe end should be computed in 887 ;; the same way as beg. That would change the behaviour though. 888 (if (equal last-command 'PC-lisp-complete-symbol) 889 (PC-do-completion nil beg PC-lisp-complete-end) 890 (if PC-lisp-complete-end 891 (move-marker PC-lisp-complete-end end) 892 (setq PC-lisp-complete-end (copy-marker end t))) 893 (PC-do-completion nil beg end)))) 829 894 830 895 (defun PC-complete-as-file-name () … … 1027 1092 (let* ((string (ad-get-arg 0)) 1028 1093 (action (ad-get-arg 2)) 1029 (name ( substring string (match-beginning 1) (match-end 1)))1094 (name (match-string 1 string)) 1030 1095 (str2 (substring string (match-beginning 0))) 1031 1096 (completion-table 1032 (mapcar (lambda (x) (format "<%s>" x)) 1097 (mapcar (lambda (x) 1098 (format (if (string-match "/\\'" x) "<%s" "<%s>") x)) 1033 1099 (PC-include-file-all-completions 1034 1100 name (PC-include-file-path)))))
