diff options
| author | Stefan Monnier | 2000-09-29 02:17:56 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-09-29 02:17:56 +0000 |
| commit | cc7e4da0a580a2a52d35cd50e0b98f2139528c1d (patch) | |
| tree | 93f33ca34838ab859865c5ad41dc55caa90c442a | |
| parent | ef779078e24d9a7a2a22c6dcc1a5fbc225a555b4 (diff) | |
| download | emacs-cc7e4da0a580a2a52d35cd50e0b98f2139528c1d.tar.gz emacs-cc7e4da0a580a2a52d35cd50e0b98f2139528c1d.zip | |
(partial-completion-mode) <defcustom>: Remove.
(partial-completion-mode): Use define-minor-mode.
(PC-do-completion): Understand `completion-auto-help = delay'
to mean to popup the completion buffer only the second time.
(PC-include-file-all-completions, PC-include-file-all-completions)
(PC-include-file-all-completions): Don't quote lambda.
| -rw-r--r-- | lisp/complete.el | 132 |
1 files changed, 52 insertions, 80 deletions
diff --git a/lisp/complete.el b/lisp/complete.el index ff32d07a9a6..2a759122d6d 100644 --- a/lisp/complete.el +++ b/lisp/complete.el | |||
| @@ -98,22 +98,6 @@ | |||
| 98 | :group 'minibuffer | 98 | :group 'minibuffer |
| 99 | :group 'convenience) | 99 | :group 'convenience) |
| 100 | 100 | ||
| 101 | ;;;###autoload | ||
| 102 | (defcustom partial-completion-mode nil | ||
| 103 | "Toggle Partial Completion mode. | ||
| 104 | When Partial Completion mode is enabled, TAB (or M-TAB if `PC-meta-flag' is | ||
| 105 | nil) is enhanced so that if some string is divided into words and each word is | ||
| 106 | delimited by a character in `PC-word-delimiters', partial words are completed | ||
| 107 | as much as possible and `*' characters are treated likewise in file names. | ||
| 108 | This variable should be set only with \\[customize], which is equivalent | ||
| 109 | to using the function `partial-completion-mode'." | ||
| 110 | :set (lambda (symbol value) | ||
| 111 | (partial-completion-mode (or value 0))) | ||
| 112 | :initialize 'custom-initialize-default | ||
| 113 | :type 'boolean | ||
| 114 | :group 'partial-completion | ||
| 115 | :require 'complete) | ||
| 116 | |||
| 117 | (defcustom PC-first-char 'find-file | 101 | (defcustom PC-first-char 'find-file |
| 118 | "*Control how the first character of a string is to be interpreted. | 102 | "*Control how the first character of a string is to be interpreted. |
| 119 | If nil, the first character of a string is not taken literally if it is a word | 103 | If nil, the first character of a string is not taken literally if it is a word |
| @@ -164,54 +148,6 @@ If nil, means use the colon-separated path in the variable $INCPATH instead." | |||
| 164 | 148 | ||
| 165 | (defvar PC-old-read-file-name-internal nil) | 149 | (defvar PC-old-read-file-name-internal nil) |
| 166 | 150 | ||
| 167 | ;;;###autoload | ||
| 168 | (defun partial-completion-mode (&optional arg) | ||
| 169 | "Toggle Partial Completion mode. | ||
| 170 | With prefix ARG, turn Partial Completion mode on if ARG is positive. | ||
| 171 | |||
| 172 | When Partial Completion mode is enabled, TAB (or M-TAB if `PC-meta-flag' is | ||
| 173 | nil) is enhanced so that if some string is divided into words and each word is | ||
| 174 | delimited by a character in `PC-word-delimiters', partial words are completed | ||
| 175 | as much as possible. | ||
| 176 | |||
| 177 | For example, M-x p-c-m expands to M-x partial-completion-mode since no other | ||
| 178 | command begins with that sequence of characters, and | ||
| 179 | \\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no | ||
| 180 | other file in that directory begin with that sequence of characters. | ||
| 181 | |||
| 182 | Unless `PC-disable-includes' is non-nil, the \"<...>\" sequence is interpreted | ||
| 183 | specially in \\[find-file]. For example, | ||
| 184 | \\[find-file] <sys/time.h> RET finds the file /usr/include/sys/time.h. | ||
| 185 | See also the variable `PC-include-file-path'." | ||
| 186 | (interactive "P") | ||
| 187 | (let ((on-p (if arg | ||
| 188 | (> (prefix-numeric-value arg) 0) | ||
| 189 | (not partial-completion-mode)))) | ||
| 190 | ;; Deal with key bindings... | ||
| 191 | (PC-bindings on-p) | ||
| 192 | ;; Deal with include file feature... | ||
| 193 | (cond ((not on-p) | ||
| 194 | (remove-hook 'find-file-not-found-hooks 'PC-look-for-include-file)) | ||
| 195 | ((not PC-disable-includes) | ||
| 196 | (add-hook 'find-file-not-found-hooks 'PC-look-for-include-file))) | ||
| 197 | ;; ... with some underhand redefining. | ||
| 198 | (cond ((and (not on-p) (functionp PC-old-read-file-name-internal)) | ||
| 199 | (fset 'read-file-name-internal PC-old-read-file-name-internal)) | ||
| 200 | ((and (not PC-disable-includes) (not PC-old-read-file-name-internal)) | ||
| 201 | (setq PC-old-read-file-name-internal | ||
| 202 | (symbol-function 'read-file-name-internal)) | ||
| 203 | (fset 'read-file-name-internal | ||
| 204 | 'PC-read-include-file-name-internal))) | ||
| 205 | (when (and on-p (null PC-env-vars-alist)) | ||
| 206 | (setq PC-env-vars-alist | ||
| 207 | (mapcar (lambda (string) | ||
| 208 | (let ((d (string-match "=" string))) | ||
| 209 | (cons (concat "$" (substring string 0 d)) | ||
| 210 | (and d (substring string (1+ d)))))) | ||
| 211 | process-environment))) | ||
| 212 | ;; Finally set the mode variable. | ||
| 213 | (setq partial-completion-mode on-p))) | ||
| 214 | |||
| 215 | (defun PC-bindings (bind) | 151 | (defun PC-bindings (bind) |
| 216 | (let ((completion-map minibuffer-local-completion-map) | 152 | (let ((completion-map minibuffer-local-completion-map) |
| 217 | (must-match-map minibuffer-local-must-match-map)) | 153 | (must-match-map minibuffer-local-must-match-map)) |
| @@ -254,16 +190,50 @@ See also the variable `PC-include-file-path'." | |||
| 254 | 190 | ||
| 255 | (define-key global-map "\e\t" 'PC-lisp-complete-symbol))))) | 191 | (define-key global-map "\e\t" 'PC-lisp-complete-symbol))))) |
| 256 | 192 | ||
| 257 | ;; Because the `partial-completion-mode' option is defined before the | 193 | ;;;###autoload |
| 258 | ;; `partial-completion-mode' command and its callee, we give the former a | 194 | (define-minor-mode partial-completion-mode |
| 259 | ;; default `:initialize' keyword value. Otherwise, the `:set' keyword value | 195 | "Toggle Partial Completion mode. |
| 260 | ;; would be called to initialise the variable value, and that would call the | 196 | With prefix ARG, turn Partial Completion mode on if ARG is positive. |
| 261 | ;; as-yet undefined `partial-completion-mode' function. | 197 | |
| 262 | ;; Since the default `:initialize' keyword value (obviously) does not turn on | 198 | When Partial Completion mode is enabled, TAB (or M-TAB if `PC-meta-flag' is |
| 263 | ;; Partial Completion Mode, we do that here, once the `partial-completion-mode' | 199 | nil) is enhanced so that if some string is divided into words and each word is |
| 264 | ;; function and its callee are defined. | 200 | delimited by a character in `PC-word-delimiters', partial words are completed |
| 265 | (when partial-completion-mode | 201 | as much as possible and `*' characters are treated likewise in file names. |
| 266 | (partial-completion-mode t)) | 202 | |
| 203 | For example, M-x p-c-m expands to M-x partial-completion-mode since no other | ||
| 204 | command begins with that sequence of characters, and | ||
| 205 | \\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no | ||
| 206 | other file in that directory begin with that sequence of characters. | ||
| 207 | |||
| 208 | Unless `PC-disable-includes' is non-nil, the \"<...>\" sequence is interpreted | ||
| 209 | specially in \\[find-file]. For example, | ||
| 210 | \\[find-file] <sys/time.h> RET finds the file /usr/include/sys/time.h. | ||
| 211 | See also the variable `PC-include-file-path'." | ||
| 212 | nil nil nil :global t :group 'partial-completion | ||
| 213 | ;; Deal with key bindings... | ||
| 214 | (PC-bindings partial-completion-mode) | ||
| 215 | ;; Deal with include file feature... | ||
| 216 | (cond ((not partial-completion-mode) | ||
| 217 | (remove-hook 'find-file-not-found-hooks 'PC-look-for-include-file)) | ||
| 218 | ((not PC-disable-includes) | ||
| 219 | (add-hook 'find-file-not-found-hooks 'PC-look-for-include-file))) | ||
| 220 | ;; ... with some underhand redefining. | ||
| 221 | (cond ((and (not partial-completion-mode) | ||
| 222 | (functionp PC-old-read-file-name-internal)) | ||
| 223 | (fset 'read-file-name-internal PC-old-read-file-name-internal)) | ||
| 224 | ((and (not PC-disable-includes) (not PC-old-read-file-name-internal)) | ||
| 225 | (setq PC-old-read-file-name-internal | ||
| 226 | (symbol-function 'read-file-name-internal)) | ||
| 227 | (fset 'read-file-name-internal | ||
| 228 | 'PC-read-include-file-name-internal))) | ||
| 229 | (when (and partial-completion-mode (null PC-env-vars-alist)) | ||
| 230 | (setq PC-env-vars-alist | ||
| 231 | (mapcar (lambda (string) | ||
| 232 | (let ((d (string-match "=" string))) | ||
| 233 | (cons (concat "$" (substring string 0 d)) | ||
| 234 | (and d (substring string (1+ d)))))) | ||
| 235 | process-environment)))) | ||
| 236 | |||
| 267 | 237 | ||
| 268 | (defun PC-complete () | 238 | (defun PC-complete () |
| 269 | "Like minibuffer-complete, but allows \"b--di\"-style abbreviations. | 239 | "Like minibuffer-complete, but allows \"b--di\"-style abbreviations. |
| @@ -670,7 +640,9 @@ of `minibuffer-completion-table' and the minibuffer contents.") | |||
| 670 | (PC-is-complete-p (field-string) table pred)) | 640 | (PC-is-complete-p (field-string) table pred)) |
| 671 | 641 | ||
| 672 | ;; If totally ambiguous, display a list of completions | 642 | ;; If totally ambiguous, display a list of completions |
| 673 | (if (or completion-auto-help | 643 | (if (or (eq completion-auto-help t) |
| 644 | (and completion-auto-help | ||
| 645 | (eq last-command this-command)) | ||
| 674 | (eq mode 'help)) | 646 | (eq mode 'help)) |
| 675 | (with-output-to-temp-buffer "*Completions*" | 647 | (with-output-to-temp-buffer "*Completions*" |
| 676 | (display-completion-list (sort helpposs 'string-lessp)) | 648 | (display-completion-list (sort helpposs 'string-lessp)) |
| @@ -914,8 +886,8 @@ or properties are considered." | |||
| 914 | If optional third argument FULL is non-nil, returned pathnames should be | 886 | If optional third argument FULL is non-nil, returned pathnames should be |
| 915 | absolute rather than relative to some directory on the SEARCH-PATH." | 887 | absolute rather than relative to some directory on the SEARCH-PATH." |
| 916 | (setq search-path | 888 | (setq search-path |
| 917 | (mapcar '(lambda (dir) | 889 | (mapcar (lambda (dir) |
| 918 | (if dir (file-name-as-directory dir) default-directory)) | 890 | (if dir (file-name-as-directory dir) default-directory)) |
| 919 | search-path)) | 891 | search-path)) |
| 920 | (if (file-name-absolute-p file) | 892 | (if (file-name-absolute-p file) |
| 921 | ;; It's an absolute file name, so don't need search-path | 893 | ;; It's an absolute file name, so don't need search-path |
| @@ -929,7 +901,7 @@ absolute rather than relative to some directory on the SEARCH-PATH." | |||
| 929 | ;; Append subdirectory part to each element of search-path | 901 | ;; Append subdirectory part to each element of search-path |
| 930 | (if subdir | 902 | (if subdir |
| 931 | (setq search-path | 903 | (setq search-path |
| 932 | (mapcar '(lambda (dir) (concat dir subdir)) | 904 | (mapcar (lambda (dir) (concat dir subdir)) |
| 933 | search-path) | 905 | search-path) |
| 934 | file )) | 906 | file )) |
| 935 | ;; Make list of completions in each directory on search-path | 907 | ;; Make list of completions in each directory on search-path |
| @@ -940,14 +912,14 @@ absolute rather than relative to some directory on the SEARCH-PATH." | |||
| 940 | (progn | 912 | (progn |
| 941 | (setq file-lists | 913 | (setq file-lists |
| 942 | (cons | 914 | (cons |
| 943 | (mapcar '(lambda (file) (concat subdir file)) | 915 | (mapcar (lambda (file) (concat subdir file)) |
| 944 | (file-name-all-completions ndfile | 916 | (file-name-all-completions ndfile |
| 945 | (car search-path))) | 917 | (car search-path))) |
| 946 | file-lists)))) | 918 | file-lists)))) |
| 947 | (setq search-path (cdr search-path)))) | 919 | (setq search-path (cdr search-path)))) |
| 948 | ;; Compress out duplicates while building complete list (slloooow!) | 920 | ;; Compress out duplicates while building complete list (slloooow!) |
| 949 | (let ((sorted (sort (apply 'nconc file-lists) | 921 | (let ((sorted (sort (apply 'nconc file-lists) |
| 950 | '(lambda (x y) (not (string-lessp x y))))) | 922 | (lambda (x y) (not (string-lessp x y))))) |
| 951 | compressed) | 923 | compressed) |
| 952 | (while sorted | 924 | (while sorted |
| 953 | (if (equal (car sorted) (car compressed)) nil | 925 | (if (equal (car sorted) (car compressed)) nil |