Mercurial > emacs
comparison lisp/minibuffer.el @ 97476:354026fc6299
(completion-boundaries): Doc fix.
(display-completion-list): New arg BASE-SIZE, to specify an
overriding base-size.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Thu, 14 Aug 2008 23:44:41 +0000 |
parents | e99e1b5c726e |
children | 6c4680239c3f |
comparison
equal
deleted
inserted
replaced
97475:2ac804a70140 | 97476:354026fc6299 |
---|---|
71 STRING is the string on which completion will be performed. | 71 STRING is the string on which completion will be performed. |
72 SUFFIX is the string after point. | 72 SUFFIX is the string after point. |
73 The result is of the form (START . END) where START is the position | 73 The result is of the form (START . END) where START is the position |
74 in STRING of the beginning of the completion field and END is the position | 74 in STRING of the beginning of the completion field and END is the position |
75 in SUFFIX of the end of the completion field. | 75 in SUFFIX of the end of the completion field. |
76 I.e. START is the same as the `completion-base-size'. | |
77 E.g. for simple completion tables, the result is always (0 . (length SUFFIX)) | 76 E.g. for simple completion tables, the result is always (0 . (length SUFFIX)) |
78 and for file names the result is the positions delimited by | 77 and for file names the result is the positions delimited by |
79 the closest directory separators." | 78 the closest directory separators." |
80 (let ((boundaries (if (functionp table) | 79 (let ((boundaries (if (functionp table) |
81 (funcall table string pred (cons 'boundaries suffix))))) | 80 (funcall table string pred (cons 'boundaries suffix))))) |
813 str))) | 812 str))) |
814 elem) | 813 elem) |
815 completions) | 814 completions) |
816 base-size)))) | 815 base-size)))) |
817 | 816 |
818 (defun display-completion-list (completions &optional common-substring) | 817 (defun display-completion-list (completions &optional common-substring base-size) |
819 "Display the list of completions, COMPLETIONS, using `standard-output'. | 818 "Display the list of completions, COMPLETIONS, using `standard-output'. |
820 Each element may be just a symbol or string | 819 Each element may be just a symbol or string |
821 or may be a list of two strings to be printed as if concatenated. | 820 or may be a list of two strings to be printed as if concatenated. |
822 If it is a list of two strings, the first is the actual completion | 821 If it is a list of two strings, the first is the actual completion |
823 alternative, the second serves as annotation. | 822 alternative, the second serves as annotation. |
824 `standard-output' must be a buffer. | 823 `standard-output' must be a buffer. |
825 The actual completion alternatives, as inserted, are given `mouse-face' | 824 The actual completion alternatives, as inserted, are given `mouse-face' |
826 properties of `highlight'. | 825 properties of `highlight'. |
827 At the end, this runs the normal hook `completion-setup-hook'. | 826 At the end, this runs the normal hook `completion-setup-hook'. |
828 It can find the completion buffer in `standard-output'. | 827 It can find the completion buffer in `standard-output'. |
829 The obsolete optional second arg COMMON-SUBSTRING is a string. | 828 |
830 It is used to put faces, `completions-first-difference' and | 829 The optional arg COMMON-SUBSTRING, if non-nil, should be a string |
831 `completions-common-part' on the completion buffer. The | 830 specifying a common substring for adding the faces |
832 `completions-common-part' face is put on the common substring | 831 `completions-first-difference' and `completions-common-part' to |
833 specified by COMMON-SUBSTRING." | 832 the completions buffer. |
833 | |
834 The optional arg BASE-SIZE, if non-nil, which should be an | |
835 integer that specifies the value of `completion-base-size' for | |
836 the completion buffer." | |
834 (if common-substring | 837 (if common-substring |
835 (setq completions (completion-hilit-commonality | 838 (setq completions (completion-hilit-commonality |
836 completions (length common-substring)))) | 839 completions (length common-substring)))) |
837 (if (not (bufferp standard-output)) | 840 (if (not (bufferp standard-output)) |
838 ;; This *never* (ever) happens, so there's no point trying to be clever. | 841 ;; This *never* (ever) happens, so there's no point trying to be clever. |
839 (with-temp-buffer | 842 (with-temp-buffer |
840 (let ((standard-output (current-buffer)) | 843 (let ((standard-output (current-buffer)) |
841 (completion-setup-hook nil)) | 844 (completion-setup-hook nil)) |
842 (display-completion-list completions)) | 845 (display-completion-list completions common-substring base-size)) |
843 (princ (buffer-string))) | 846 (princ (buffer-string))) |
844 | 847 |
845 (with-current-buffer standard-output | 848 (with-current-buffer standard-output |
846 (goto-char (point-max)) | 849 (goto-char (point-max)) |
847 (if (null completions) | 850 (if (null completions) |
848 (insert "There are no possible completions of what you have typed.") | 851 (insert "There are no possible completions of what you have typed.") |
849 | 852 |
850 (insert "Possible completions are:\n") | 853 (insert "Possible completions are:\n") |
851 (let ((last (last completions))) | 854 (let ((last (last completions))) |
852 ;; Get the base-size from the tail of the list. | 855 ;; If BASE-SIZE is unspecified, set it from the tail of the list. |
853 (set (make-local-variable 'completion-base-size) (or (cdr last) 0)) | 856 (set (make-local-variable 'completion-base-size) |
857 (or base-size (cdr last) 0)) | |
854 (setcdr last nil)) ;Make completions a properly nil-terminated list. | 858 (setcdr last nil)) ;Make completions a properly nil-terminated list. |
855 (completion--insert-strings completions)))) | 859 (completion--insert-strings completions)))) |
856 | 860 |
857 ;; The hilit used to be applied via completion-setup-hook, so there | 861 ;; The hilit used to be applied via completion-setup-hook, so there |
858 ;; may still be some code that uses completion-common-substring. | 862 ;; may still be some code that uses completion-common-substring. |
859 (let ((completion-common-substring common-substring)) | 863 (with-no-warnings |
860 (run-hooks 'completion-setup-hook)) | 864 (let ((completion-common-substring common-substring)) |
865 (run-hooks 'completion-setup-hook))) | |
861 nil) | 866 nil) |
862 | 867 |
863 (defun minibuffer-completion-help () | 868 (defun minibuffer-completion-help () |
864 "Display a list of possible completions of the current minibuffer contents." | 869 "Display a list of possible completions of the current minibuffer contents." |
865 (interactive) | 870 (interactive) |