Mercurial > emacs
annotate lisp/complete.el @ 24047:5063ba89c767
(install): Install fns.el in ../bin, since Emacs
looks for it in exec-directory.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Mon, 11 Jan 1999 14:01:41 +0000 |
parents | 9ffaa505edc7 |
children | 2a7aa9cd6a19 |
rev | line source |
---|---|
15261 | 1 ;;; complete.el --- partial completion mechanism plus other goodies |
3725 | 2 |
3 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Dave Gillespie <daveg@synaptics.com> | |
22250
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
22142
diff
changeset
|
6 ;; Keywords: abbrev convenience |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
7 ;; Version: 2.03 |
3725 | 8 ;; Special thanks to Hallvard Furuseth for his many ideas and contributions. |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
15 ;; any later version. |
3725 | 16 |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
20 ;; GNU General Public License for more details. |
3725 | 21 |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
3725
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
3725 | 26 |
7942 | 27 ;;; Commentary: |
3725 | 28 |
29 ;; Extended completion for the Emacs minibuffer. | |
30 ;; | |
31 ;; The basic idea is that the command name or other completable text is | |
32 ;; divided into words and each word is completed separately, so that | |
33 ;; "M-x p-b" expands to "M-x print-buffer". If the entry is ambiguous | |
34 ;; each word is completed as much as possible and then the cursor is | |
35 ;; left at the first position where typing another letter will resolve | |
36 ;; the ambiguity. | |
37 ;; | |
38 ;; Word separators for this purpose are hyphen, space, and period. | |
39 ;; These would most likely occur in command names, Info menu items, | |
40 ;; and file names, respectively. But all word separators are treated | |
41 ;; alike at all times. | |
42 ;; | |
43 ;; This completion package replaces the old-style completer's key | |
44 ;; bindings for TAB, SPC, RET, and `?'. The old completer is still | |
45 ;; available on the Meta versions of those keys. If you set | |
46 ;; PC-meta-flag to nil, the old completion keys will be left alone | |
47 ;; and the partial completer will use the Meta versions of the keys. | |
48 | |
49 | |
22142 | 50 ;; Usage: M-x partial-completion-mode. During completable minibuffer entry, |
3725 | 51 ;; |
52 ;; TAB means to do a partial completion; | |
53 ;; SPC means to do a partial complete-word; | |
54 ;; RET means to do a partial complete-and-exit; | |
55 ;; ? means to do a partial completion-help. | |
56 ;; | |
57 ;; If you set PC-meta-flag to nil, then TAB, SPC, RET, and ? perform | |
58 ;; original Emacs completions, and M-TAB etc. do partial completion. | |
59 ;; To do this, put the command, | |
60 ;; | |
61 ;; (setq PC-meta-flag nil) | |
62 ;; | |
63 ;; in your .emacs file. To load partial completion automatically, put | |
64 ;; | |
22142 | 65 ;; (partial-completion-mode t) |
3725 | 66 ;; |
67 ;; in your .emacs file, too. Things will be faster if you byte-compile | |
68 ;; this file when you install it. | |
69 ;; | |
70 ;; As an extra feature, in cases where RET would not normally | |
71 ;; complete (such as `C-x b'), the M-RET key will always do a partial | |
72 ;; complete-and-exit. Thus `C-x b f.c RET' will select or create a | |
73 ;; buffer called "f.c", but `C-x b f.c M-RET' will select the existing | |
74 ;; buffer whose name matches that pattern (perhaps "filing.c"). | |
75 ;; (PC-meta-flag does not affect this behavior; M-RET used to be | |
76 ;; undefined in this situation.) | |
77 ;; | |
78 ;; The regular M-TAB (lisp-complete-symbol) command also supports | |
79 ;; partial completion in this package. | |
80 | |
81 ;; This package also contains a wildcard feature for C-x C-f (find-file). | |
82 ;; For example, `C-x C-f *.c RET' loads all .c files at once, exactly | |
83 ;; as if you had typed C-x C-f separately for each file. Completion | |
84 ;; is supported in connection with wildcards. Currently only the `*' | |
85 ;; wildcard character works. | |
86 | |
87 ;; File name completion does not do partial completion of directories | |
88 ;; on the path, e.g., "/u/b/f" will not complete to "/usr/bin/foo", | |
89 ;; but you can put *'s in the path to accomplish this: "/u*/b*/f". | |
90 ;; Stars are required for performance reasons. | |
91 | |
92 ;; In addition, this package includes a feature for accessing include | |
93 ;; files. For example, `C-x C-f <sys/time.h> RET' reads the file | |
94 ;; /usr/include/sys/time.h. The variable PC-include-file-path is a | |
95 ;; list of directories in which to search for include files. Completion | |
96 ;; is supported in include file names. | |
97 | |
98 | |
7942 | 99 ;;; Code: |
3725 | 100 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
101 (defgroup partial-completion nil |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
102 "Partial Completion of items." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
103 :prefix "pc-" |
22250
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
22142
diff
changeset
|
104 :group 'minibuffer |
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
22142
diff
changeset
|
105 :group 'convenience) |
3725 | 106 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
107 (defcustom partial-completion-mode nil |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
108 "Toggle Partial Completion mode. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
109 When Partial Completion mode is enabled, TAB (or M-TAB if `PC-meta-flag' is |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
110 nil) is enhanced so that if some string is divided into words and each word is |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
111 delimited by a character in `PC-word-delimiters', partial words are completed |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
112 as much as possible and `*' characters are treated likewise in file names. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
113 You must modify via \\[customize] for this variable to have an effect." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
114 :set (lambda (symbol value) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
115 (partial-completion-mode (or value 0))) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
116 :initialize 'custom-initialize-default |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
117 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
118 :group 'partial-completion |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
119 :require 'complete) |
3725 | 120 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
121 (defcustom PC-first-char 'find-file |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
122 "*Control how the first character of a string is to be interpreted. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
123 If nil, the first character of a string is not taken literally if it is a word |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
124 delimiter, so that \".e\" matches \"*.e*\". |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
125 If t, the first character of a string is always taken literally even if it is a |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
126 word delimiter, so that \".e\" matches \".e*\". |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
127 If non-nil and non-t, the first character is taken literally only for file name |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
128 completion." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
129 :type '(choice (const :tag "delimiter" nil) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
130 (const :tag "literal" t) |
22570
6cfe82c80677
(PC-first-char): Use `other' widget type.
Andreas Schwab <schwab@suse.de>
parents:
22250
diff
changeset
|
131 (other :tag "find-file" find-file)) |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
132 :group 'partial-completion) |
3725 | 133 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
134 (defcustom PC-meta-flag t |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
135 "*If non-nil, TAB means PC completion and M-TAB means normal completion. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
136 Otherwise, TAB means normal completion and M-TAB means Partial Completion." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
137 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
138 :group 'partial-completion) |
3725 | 139 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
140 (defcustom PC-word-delimiters "-_. " |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
141 "*A string of characters treated as word delimiters for completion. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
142 Some arcane rules: |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
143 If `]' is in this string, it must come first. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
144 If `^' is in this string, it must not come first. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
145 If `-' is in this string, it must come first or right after `]'. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
146 In other words, if S is this string, then `[S]' must be a legal Emacs regular |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
147 expression (not containing character ranges like `a-z')." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
148 :type 'string |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
149 :group 'partial-completion) |
3725 | 150 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
151 (defcustom PC-include-file-path '("/usr/include" "/usr/local/include") |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
152 "*A list of directories in which to look for include files. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
153 If nil, means use the colon-separated path in the variable $INCPATH instead." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
154 :type '(repeat directory) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
155 :group 'partial-completion) |
3725 | 156 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
157 (defcustom PC-disable-wildcards nil |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
158 "*If non-nil, wildcard support in \\[find-file] is disabled." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
159 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
160 :group 'partial-completion) |
3725 | 161 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
162 (defcustom PC-disable-includes nil |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
163 "*If non-nil, include-file support in \\[find-file] is disabled." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
164 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
165 :group 'partial-completion) |
3725 | 166 |
167 (defvar PC-default-bindings t | |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
168 "If non-nil, default partial completion key bindings are suppressed.") |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
169 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
170 (defvar PC-old-read-file-name-internal nil) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
171 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
172 ;;;###autoload |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
173 (defun partial-completion-mode (&optional arg) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
174 "Toggle Partial Completion mode. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
175 With prefix ARG, turn Partial Completion mode on if ARG is positive. |
3725 | 176 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
177 When Partial Completion mode is enabled, TAB (or M-TAB if `PC-meta-flag' is |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
178 nil) is enhanced so that if some string is divided into words and each word is |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
179 delimited by a character in `PC-word-delimiters', partial words are completed |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
180 as much as possible. |
3725 | 181 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
182 For example, M-x p-c-b expands to M-x partial-completion-mode since no other |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
183 command begins with that sequence of characters, and |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
184 \\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
185 other file in that directory begin with that sequence of characters. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
186 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
187 Unless `PC-disable-wildcards' is non-nil, the \"*\" wildcard is interpreted |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
188 specially when entering file or directory names. For example, |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
189 \\[find-file] *.c RET finds each C file in the currenty directory, and |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
190 \\[find-file] */foo_bar.c TAB completes the directory name as far as possible. |
3725 | 191 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
192 Unless `PC-disable-includes' is non-nil, the \"<...>\" sequence is interpreted |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
193 specially in \\[find-file]. For example, |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
194 \\[find-file] <sys/time.h> RET finds the file /usr/include/sys/time.h. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
195 See also the variable `PC-include-file-path'." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
196 (interactive "P") |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
197 (let ((on-p (if arg |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
198 (> (prefix-numeric-value arg) 0) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
199 (not partial-completion-mode)))) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
200 ;; Deal with key bindings... |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
201 (PC-bindings on-p) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
202 ;; Deal with wildcard file feature... |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
203 (cond ((not on-p) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
204 (remove-hook 'find-file-not-found-hooks 'PC-try-load-many-files)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
205 ((not PC-disable-wildcards) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
206 (add-hook 'find-file-not-found-hooks 'PC-try-load-many-files))) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
207 ;; Deal with include file feature... |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
208 (cond ((not on-p) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
209 (remove-hook 'find-file-not-found-hooks 'PC-look-for-include-file)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
210 ((not PC-disable-includes) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
211 (add-hook 'find-file-not-found-hooks 'PC-look-for-include-file))) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
212 ;; ... with some underhand redefining. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
213 (cond ((and (not on-p) (functionp PC-old-read-file-name-internal)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
214 (fset 'read-file-name-internal PC-old-read-file-name-internal)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
215 ((and (not PC-disable-includes) (not PC-old-read-file-name-internal)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
216 (setq PC-old-read-file-name-internal |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
217 (symbol-function 'read-file-name-internal)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
218 (fset 'read-file-name-internal |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
219 'PC-read-include-file-name-internal))) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
220 ;; Finally set the mode variable. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
221 (setq partial-completion-mode on-p))) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
222 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
223 (defun PC-bindings (bind) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
224 (let ((completion-map minibuffer-local-completion-map) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
225 (must-match-map minibuffer-local-must-match-map)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
226 (cond ((not bind) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
227 ;; These bindings are the default bindings. It would be better to |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
228 ;; restore the previous bindings. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
229 (define-key completion-map "\t" 'minibuffer-complete) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
230 (define-key completion-map " " 'minibuffer-complete-word) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
231 (define-key completion-map "?" 'minibuffer-completion-help) |
3725 | 232 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
233 (define-key must-match-map "\t" 'minibuffer-complete) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
234 (define-key must-match-map " " 'minibuffer-complete-word) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
235 (define-key must-match-map "\r" 'minibuffer-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
236 (define-key must-match-map "\n" 'minibuffer-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
237 (define-key must-match-map "?" 'minibuffer-completion-help) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
238 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
239 (define-key global-map "\e\t" 'complete-symbol)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
240 (PC-default-bindings |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
241 (define-key completion-map "\t" 'PC-complete) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
242 (define-key completion-map " " 'PC-complete-word) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
243 (define-key completion-map "?" 'PC-completion-help) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
244 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
245 (define-key completion-map "\e\t" 'PC-complete) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
246 (define-key completion-map "\e " 'PC-complete-word) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
247 (define-key completion-map "\e\r" 'PC-force-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
248 (define-key completion-map "\e\n" 'PC-force-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
249 (define-key completion-map "\e?" 'PC-completion-help) |
3725 | 250 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
251 (define-key must-match-map "\t" 'PC-complete) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
252 (define-key must-match-map " " 'PC-complete-word) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
253 (define-key must-match-map "\r" 'PC-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
254 (define-key must-match-map "\n" 'PC-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
255 (define-key must-match-map "?" 'PC-completion-help) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
256 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
257 (define-key must-match-map "\e\t" 'PC-complete) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
258 (define-key must-match-map "\e " 'PC-complete-word) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
259 (define-key must-match-map "\e\r" 'PC-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
260 (define-key must-match-map "\e\n" 'PC-complete-and-exit) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
261 (define-key must-match-map "\e?" 'PC-completion-help) |
3725 | 262 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
263 (define-key global-map "\e\t" 'PC-lisp-complete-symbol))))) |
3725 | 264 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
265 ;; Because the `partial-completion-mode' option is defined before the |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
266 ;; `partial-completion-mode' command and its callee, we give the former a |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
267 ;; default `:initialize' keyword value. Otherwise, the `:set' keyword value |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
268 ;; would be called to initialise the variable value, and that would call the |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
269 ;; as-yet undefined `partial-completion-mode' function. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
270 ;; Since the default `:initialize' keyword value (obviously) does not turn on |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
271 ;; Partial Completion Mode, we do that here, once the `partial-completion-mode' |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
272 ;; function and its callee are defined. |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
273 (when partial-completion-mode |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
274 (partial-completion-mode t)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
275 |
3725 | 276 (defun PC-complete () |
277 "Like minibuffer-complete, but allows \"b--di\"-style abbreviations. | |
278 For example, \"M-x b--di\" would match `byte-recompile-directory', or any | |
279 name which consists of three or more words, the first beginning with \"b\" | |
280 and the third beginning with \"di\". | |
281 | |
282 The pattern \"b--d\" is ambiguous for `byte-recompile-directory' and | |
283 `beginning-of-defun', so this would produce a list of completions | |
284 just like when normal Emacs completions are ambiguous. | |
285 | |
286 Word-delimiters for the purposes of Partial Completion are \"-\", \"_\", | |
287 \".\", and SPC." | |
288 (interactive) | |
289 (if (PC-was-meta-key) | |
290 (minibuffer-complete) | |
15802
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
291 ;; If the previous command was not this one, |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
292 ;; never scroll, always retry completion. |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
293 (or (eq last-command this-command) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
294 (setq minibuffer-scroll-window nil)) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
295 (let ((window minibuffer-scroll-window)) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
296 ;; If there's a fresh completion window with a live buffer, |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
297 ;; and this command is repeated, scroll that window. |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
298 (if (and window (window-buffer window) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
299 (buffer-name (window-buffer window))) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
300 (save-excursion |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
301 (set-buffer (window-buffer window)) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
302 (if (pos-visible-in-window-p (point-max) window) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
303 (set-window-start window (point-min) nil) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
304 (scroll-other-window))) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
305 (PC-do-completion nil))))) |
3725 | 306 |
307 | |
308 (defun PC-complete-word () | |
309 "Like `minibuffer-complete-word', but allows \"b--di\"-style abbreviations. | |
310 See `PC-complete' for details. | |
311 This can be bound to other keys, like `-' and `.', if you wish." | |
312 (interactive) | |
313 (if (eq (PC-was-meta-key) PC-meta-flag) | |
314 (if (eq last-command-char ? ) | |
315 (minibuffer-complete-word) | |
316 (self-insert-command 1)) | |
317 (self-insert-command 1) | |
318 (if (eobp) | |
319 (PC-do-completion 'word)))) | |
320 | |
321 | |
322 (defun PC-complete-space () | |
323 "Like `minibuffer-complete-word', but allows \"b--di\"-style abbreviations. | |
324 See `PC-complete' for details. | |
325 This is suitable for binding to other keys which should act just like SPC." | |
326 (interactive) | |
327 (if (eq (PC-was-meta-key) PC-meta-flag) | |
328 (minibuffer-complete-word) | |
329 (insert " ") | |
330 (if (eobp) | |
331 (PC-do-completion 'word)))) | |
332 | |
333 | |
334 (defun PC-complete-and-exit () | |
335 "Like `minibuffer-complete-and-exit', but allows \"b--di\"-style abbreviations. | |
336 See `PC-complete' for details." | |
337 (interactive) | |
338 (if (eq (PC-was-meta-key) PC-meta-flag) | |
339 (minibuffer-complete-and-exit) | |
340 (PC-do-complete-and-exit))) | |
341 | |
342 (defun PC-force-complete-and-exit () | |
343 "Like `minibuffer-complete-and-exit', but allows \"b--di\"-style abbreviations. | |
344 See `PC-complete' for details." | |
345 (interactive) | |
346 (let ((minibuffer-completion-confirm nil)) | |
347 (PC-do-complete-and-exit))) | |
348 | |
349 (defun PC-do-complete-and-exit () | |
350 (if (= (buffer-size) 0) ; Duplicate the "bug" that Info-menu relies on... | |
351 (exit-minibuffer) | |
352 (let ((flag (PC-do-completion 'exit))) | |
353 (and flag | |
354 (if (or (eq flag 'complete) | |
355 (not minibuffer-completion-confirm)) | |
356 (exit-minibuffer) | |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
357 (PC-temp-minibuffer-message " [Confirm]")))))) |
3725 | 358 |
359 | |
360 (defun PC-completion-help () | |
361 "Like `minibuffer-completion-help', but allows \"b--di\"-style abbreviations. | |
362 See `PC-complete' for details." | |
363 (interactive) | |
364 (if (eq (PC-was-meta-key) PC-meta-flag) | |
365 (minibuffer-completion-help) | |
366 (PC-do-completion 'help))) | |
367 | |
368 (defun PC-was-meta-key () | |
369 (or (/= (length (this-command-keys)) 1) | |
370 (let ((key (aref (this-command-keys) 0))) | |
371 (if (integerp key) | |
372 (>= key 128) | |
373 (not (null (memq 'meta (event-modifiers key)))))))) | |
374 | |
375 | |
376 (defvar PC-ignored-extensions 'empty-cache) | |
377 (defvar PC-delims 'empty-cache) | |
378 (defvar PC-ignored-regexp nil) | |
379 (defvar PC-word-failed-flag nil) | |
380 (defvar PC-delim-regex nil) | |
381 (defvar PC-ndelims-regex nil) | |
382 (defvar PC-delims-list nil) | |
383 | |
14765
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
384 (defvar PC-completion-as-file-name-predicate |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
385 (function |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
386 (lambda () |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
387 (memq minibuffer-completion-table |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
388 '(read-file-name-internal read-directory-name-internal)))) |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
389 "A function testing whether a minibuffer completion now will work filename-style. |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
390 The function takes no arguments, and typically looks at the value |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
391 of `minibuffer-completion-table' and the minibuffer contents.") |
14759
f93ed65c0584
(PC-do-completion-filename-completers): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
392 |
3725 | 393 (defun PC-do-completion (&optional mode beg end) |
394 (or beg (setq beg (point-min))) | |
395 (or end (setq end (point-max))) | |
396 (let* ((table minibuffer-completion-table) | |
397 (pred minibuffer-completion-predicate) | |
14765
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
398 (filename (funcall PC-completion-as-file-name-predicate)) |
3725 | 399 (dirname nil) |
8478
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
400 dirlength |
3725 | 401 (str (buffer-substring beg end)) |
402 (incname (and filename (string-match "<\\([^\"<>]*\\)>?$" str))) | |
403 (ambig nil) | |
404 basestr | |
405 regex | |
406 p offset | |
407 (poss nil) | |
408 helpposs | |
409 (case-fold-search completion-ignore-case)) | |
410 | |
411 ;; Check if buffer contents can already be considered complete | |
412 (if (and (eq mode 'exit) | |
413 (PC-is-complete-p str table pred)) | |
414 'complete | |
415 | |
8478
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
416 ;; Record how many characters at the beginning are not included |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
417 ;; in completion. |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
418 (setq dirlength |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
419 (if filename |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
420 (length (file-name-directory str)) |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
421 0)) |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
422 |
3725 | 423 ;; Do substitutions in directory names |
424 (and filename | |
425 (not (equal str (setq p (substitute-in-file-name str)))) | |
426 (progn | |
427 (delete-region beg end) | |
428 (insert p) | |
429 (setq str p end (+ beg (length str))))) | |
430 | |
431 ;; Prepare various delimiter strings | |
432 (or (equal PC-word-delimiters PC-delims) | |
433 (setq PC-delims PC-word-delimiters | |
434 PC-delim-regex (concat "[" PC-delims "]") | |
435 PC-ndelims-regex (concat "[^" PC-delims "]*") | |
436 PC-delims-list (append PC-delims nil))) | |
437 | |
438 ;; Look for wildcard expansions in directory name | |
439 (and filename | |
440 (string-match "\\*.*/" str) | |
441 (let ((pat str) | |
442 files) | |
443 (setq p (1+ (string-match "/[^/]*\\'" pat))) | |
444 (while (setq p (string-match PC-delim-regex pat p)) | |
445 (setq pat (concat (substring pat 0 p) | |
446 "*" | |
447 (substring pat p)) | |
448 p (+ p 2))) | |
449 (setq files (PC-expand-many-files (concat pat "*"))) | |
450 (if files | |
451 (let ((dir (file-name-directory (car files))) | |
452 (p files)) | |
453 (while (and (setq p (cdr p)) | |
454 (equal dir (file-name-directory (car p))))) | |
455 (if p | |
456 (setq filename nil table nil pred nil | |
457 ambig t) | |
458 (delete-region beg end) | |
459 (setq str (concat dir (file-name-nondirectory str))) | |
460 (insert str) | |
461 (setq end (+ beg (length str))))) | |
462 (setq filename nil table nil pred nil)))) | |
463 | |
464 ;; Strip directory name if appropriate | |
465 (if filename | |
466 (if incname | |
467 (setq basestr (substring str incname) | |
468 dirname (substring str 0 incname)) | |
469 (setq basestr (file-name-nondirectory str) | |
470 dirname (file-name-directory str))) | |
471 (setq basestr str)) | |
472 | |
473 ;; Convert search pattern to a standard regular expression | |
474 (setq regex (regexp-quote basestr) | |
475 offset (if (and (> (length regex) 0) | |
476 (not (eq (aref basestr 0) ?\*)) | |
477 (or (eq PC-first-char t) | |
478 (and PC-first-char filename))) 1 0) | |
479 p offset) | |
480 (while (setq p (string-match PC-delim-regex regex p)) | |
481 (if (eq (aref regex p) ? ) | |
482 (setq regex (concat (substring regex 0 p) | |
483 PC-ndelims-regex | |
484 PC-delim-regex | |
485 (substring regex (1+ p))) | |
486 p (+ p (length PC-ndelims-regex) (length PC-delim-regex))) | |
487 (let ((bump (if (memq (aref regex p) | |
488 '(?$ ?^ ?\. ?* ?+ ?? ?[ ?] ?\\)) | |
489 -1 0))) | |
490 (setq regex (concat (substring regex 0 (+ p bump)) | |
491 PC-ndelims-regex | |
492 (substring regex (+ p bump))) | |
493 p (+ p (length PC-ndelims-regex) 1))))) | |
494 (setq p 0) | |
495 (if filename | |
496 (while (setq p (string-match "\\\\\\*" regex p)) | |
497 (setq regex (concat (substring regex 0 p) | |
498 "[^/]*" | |
499 (substring regex (+ p 2)))))) | |
500 ;;(setq the-regex regex) | |
501 (setq regex (concat "\\`" regex)) | |
502 | |
503 ;; Find an initial list of possible completions | |
504 (if (not (setq p (string-match (concat PC-delim-regex | |
505 (if filename "\\|\\*" "")) | |
506 str | |
507 (+ (length dirname) offset)))) | |
508 | |
509 ;; Minibuffer contains no hyphens -- simple case! | |
510 (setq poss (all-completions str | |
511 table | |
512 pred)) | |
513 | |
514 ;; Use all-completions to do an initial cull. This is a big win, | |
515 ;; since all-completions is written in C! | |
516 (let ((compl (all-completions (substring str 0 p) | |
517 table | |
518 pred))) | |
519 (setq p compl) | |
520 (while p | |
521 (and (string-match regex (car p)) | |
16608
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
522 (progn |
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
523 (set-text-properties 0 (length (car p)) '() (car p)) |
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
524 (setq poss (cons (car p) poss)))) |
3725 | 525 (setq p (cdr p))))) |
526 | |
527 ;; Now we have a list of possible completions | |
528 (cond | |
529 | |
530 ;; No valid completions found | |
531 ((null poss) | |
532 (if (and (eq mode 'word) | |
533 (not PC-word-failed-flag)) | |
534 (let ((PC-word-failed-flag t)) | |
535 (delete-backward-char 1) | |
536 (PC-do-completion 'word)) | |
537 (beep) | |
538 (PC-temp-minibuffer-message (if ambig | |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
539 " [Ambiguous dir name]" |
3725 | 540 (if (eq mode 'help) |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
541 " [No completions]" |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
542 " [No match]"))) |
3725 | 543 nil)) |
544 | |
545 ;; More than one valid completion found | |
546 ((or (cdr (setq helpposs poss)) | |
547 (memq mode '(help word))) | |
548 | |
549 ;; Handle completion-ignored-extensions | |
550 (and filename | |
551 (not (eq mode 'help)) | |
552 (let ((p2 poss)) | |
553 | |
554 ;; Build a regular expression representing the extensions list | |
555 (or (equal completion-ignored-extensions PC-ignored-extensions) | |
556 (setq PC-ignored-regexp | |
557 (concat "\\(" | |
558 (mapconcat | |
559 'regexp-quote | |
560 (setq PC-ignored-extensions | |
561 completion-ignored-extensions) | |
562 "\\|") | |
563 "\\)\\'"))) | |
564 | |
23009
9ffaa505edc7
(PC-do-completion): Exclude ./ and ../ from completion.
Richard M. Stallman <rms@gnu.org>
parents:
22570
diff
changeset
|
565 ;; Check if there are any without an ignored extension. |
9ffaa505edc7
(PC-do-completion): Exclude ./ and ../ from completion.
Richard M. Stallman <rms@gnu.org>
parents:
22570
diff
changeset
|
566 ;; Also ignore `.' and `..'. |
3725 | 567 (setq p nil) |
568 (while p2 | |
569 (or (string-match PC-ignored-regexp (car p2)) | |
23009
9ffaa505edc7
(PC-do-completion): Exclude ./ and ../ from completion.
Richard M. Stallman <rms@gnu.org>
parents:
22570
diff
changeset
|
570 (string-match "\\(\\`\\|/\\)[.][.]?/?\\'" (car p2)) |
3725 | 571 (setq p (cons (car p2) p))) |
572 (setq p2 (cdr p2))) | |
573 | |
574 ;; If there are "good" names, use them | |
575 (and p (setq poss p)))) | |
576 | |
577 ;; Is the actual string one of the possible completions? | |
578 (setq p (and (not (eq mode 'help)) poss)) | |
579 (while (and p | |
16608
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
580 (not (string-equal (car p) basestr))) |
3725 | 581 (setq p (cdr p))) |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
582 (and p (null mode) |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
583 (PC-temp-minibuffer-message " [Complete, but not unique]")) |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
584 (if (and p |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
585 (not (and (null mode) |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
586 (eq this-command last-command)))) |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
587 t |
3725 | 588 |
589 ;; If ambiguous, try for a partial completion | |
590 (let ((improved nil) | |
591 prefix | |
592 (pt nil) | |
593 (skip "\\`")) | |
594 | |
595 ;; Check if next few letters are the same in all cases | |
596 (if (and (not (eq mode 'help)) | |
597 (setq prefix (try-completion "" (mapcar 'list poss)))) | |
598 (let ((first t) i) | |
599 (if (eq mode 'word) | |
600 (setq prefix (PC-chop-word prefix basestr))) | |
601 (goto-char (+ beg (length dirname))) | |
602 (while (and (progn | |
603 (setq i 0) | |
604 (while (< i (length prefix)) | |
605 (if (and (< (point) end) | |
606 (eq (aref prefix i) | |
607 (following-char))) | |
608 (forward-char 1) | |
609 (if (and (< (point) end) | |
610 (or (and (looking-at " ") | |
611 (memq (aref prefix i) | |
612 PC-delims-list)) | |
613 (eq (downcase (aref prefix i)) | |
614 (downcase | |
615 (following-char))))) | |
616 (progn | |
617 (delete-char 1) | |
618 (setq end (1- end))) | |
619 (and filename (looking-at "\\*") | |
620 (progn | |
621 (delete-char 1) | |
622 (setq end (1- end)))) | |
623 (setq improved t)) | |
16608
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
624 (insert (substring prefix i (1+ i))) |
3725 | 625 (setq end (1+ end))) |
626 (setq i (1+ i))) | |
627 (or pt (equal (point) beg) | |
628 (setq pt (point))) | |
629 (looking-at PC-delim-regex)) | |
630 (setq skip (concat skip | |
631 (regexp-quote prefix) | |
632 PC-ndelims-regex) | |
633 prefix (try-completion | |
634 "" | |
635 (mapcar | |
636 (function | |
637 (lambda (x) | |
638 (list | |
639 (and (string-match skip x) | |
640 (substring | |
641 x | |
642 (match-end 0)))))) | |
643 poss))) | |
644 (or (> i 0) (> (length prefix) 0)) | |
645 (or (not (eq mode 'word)) | |
646 (and first (> (length prefix) 0) | |
647 (setq first nil | |
648 prefix (substring prefix 0 1)))))) | |
649 (goto-char (if (eq mode 'word) end | |
650 (or pt beg))))) | |
651 | |
652 (if (and (eq mode 'word) | |
653 (not PC-word-failed-flag)) | |
654 | |
655 (if improved | |
656 | |
657 ;; We changed it... would it be complete without the space? | |
658 (if (PC-is-complete-p (buffer-substring 1 (1- end)) | |
659 table pred) | |
660 (delete-region (1- end) end))) | |
661 | |
662 (if improved | |
663 | |
664 ;; We changed it... enough to be complete? | |
665 (and (eq mode 'exit) | |
666 (PC-is-complete-p (buffer-string) table pred)) | |
667 | |
668 ;; If totally ambiguous, display a list of completions | |
669 (if (or completion-auto-help | |
670 (eq mode 'help)) | |
7844
86402e8c677b
(PC-do-completion): Likewise.
Richard M. Stallman <rms@gnu.org>
parents:
7792
diff
changeset
|
671 (with-output-to-temp-buffer "*Completions*" |
8478
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
672 (display-completion-list (sort helpposs 'string-lessp)) |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
673 (save-excursion |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
674 (set-buffer standard-output) |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
675 ;; Record which part of the buffer we are completing |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
676 ;; so that choosing a completion from the list |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
677 ;; knows how much old text to replace. |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
678 (setq completion-base-size dirlength))) |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
679 (PC-temp-minibuffer-message " [Next char not unique]")) |
3725 | 680 nil))))) |
681 | |
682 ;; Only one possible completion | |
683 (t | |
684 (if (equal basestr (car poss)) | |
685 (if (null mode) | |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
686 (PC-temp-minibuffer-message " [Sole completion]")) |
3725 | 687 (delete-region beg end) |
7792
1335cec8a016
(PC-do-completion): Clear text props from inserted text.
Richard M. Stallman <rms@gnu.org>
parents:
7639
diff
changeset
|
688 (insert (format "%s" |
1335cec8a016
(PC-do-completion): Clear text props from inserted text.
Richard M. Stallman <rms@gnu.org>
parents:
7639
diff
changeset
|
689 (if filename |
1335cec8a016
(PC-do-completion): Clear text props from inserted text.
Richard M. Stallman <rms@gnu.org>
parents:
7639
diff
changeset
|
690 (substitute-in-file-name (concat dirname (car poss))) |
1335cec8a016
(PC-do-completion): Clear text props from inserted text.
Richard M. Stallman <rms@gnu.org>
parents:
7639
diff
changeset
|
691 (car poss))))) |
3725 | 692 t))))) |
693 | |
694 | |
695 (defun PC-is-complete-p (str table pred) | |
696 (let ((res (if (listp table) | |
697 (assoc str table) | |
698 (if (vectorp table) | |
699 (or (equal str "nil") ; heh, heh, heh | |
700 (intern-soft str table)) | |
701 (funcall table str pred 'lambda))))) | |
702 (and res | |
703 (or (not pred) | |
704 (and (not (listp table)) (not (vectorp table))) | |
705 (funcall pred res)) | |
706 res))) | |
707 | |
708 (defun PC-chop-word (new old) | |
709 (let ((i -1) | |
710 (j -1)) | |
711 (while (and (setq i (string-match PC-delim-regex old (1+ i))) | |
712 (setq j (string-match PC-delim-regex new (1+ j))))) | |
713 (if (and j | |
714 (or (not PC-word-failed-flag) | |
715 (setq j (string-match PC-delim-regex new (1+ j))))) | |
716 (substring new 0 (1+ j)) | |
717 new))) | |
718 | |
719 (defvar PC-not-minibuffer nil) | |
720 | |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
721 (defun PC-temp-minibuffer-message (message) |
3725 | 722 "A Lisp version of `temp_minibuffer_message' from minibuf.c." |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
723 (cond (PC-not-minibuffer |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
724 (message message) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
725 (sit-for 2) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
726 (message "")) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
727 ((fboundp 'temp-minibuffer-message) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
728 (temp-minibuffer-message message)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
729 (t |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
730 (let ((point-max (point-max))) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
731 (save-excursion |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
732 (goto-char point-max) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
733 (insert message)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
734 (let ((inhibit-quit t)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
735 (sit-for 2) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
736 (delete-region point-max (point-max)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
737 (when quit-flag |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
738 (setq quit-flag nil |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
739 unread-command-events '(7)))))))) |
3725 | 740 |
741 | |
742 (defun PC-lisp-complete-symbol () | |
743 "Perform completion on Lisp symbol preceding point. | |
744 That symbol is compared against the symbols that exist | |
745 and any additional characters determined by what is there | |
746 are inserted. | |
747 If the symbol starts just after an open-parenthesis, | |
748 only symbols with function definitions are considered. | |
749 Otherwise, all symbols with function definitions, values | |
750 or properties are considered." | |
751 (interactive) | |
752 (let* ((end (point)) | |
753 (buffer-syntax (syntax-table)) | |
754 (beg (unwind-protect | |
755 (save-excursion | |
756 (if lisp-mode-syntax-table | |
757 (set-syntax-table lisp-mode-syntax-table)) | |
758 (backward-sexp 1) | |
759 (while (= (char-syntax (following-char)) ?\') | |
760 (forward-char 1)) | |
761 (point)) | |
762 (set-syntax-table buffer-syntax))) | |
763 (minibuffer-completion-table obarray) | |
764 (minibuffer-completion-predicate | |
765 (if (eq (char-after (1- beg)) ?\() | |
766 'fboundp | |
767 (function (lambda (sym) | |
768 (or (boundp sym) (fboundp sym) | |
769 (symbol-plist sym)))))) | |
770 (PC-not-minibuffer t)) | |
771 (PC-do-completion nil beg end))) | |
772 | |
773 | |
774 ;;; Wildcards in `C-x C-f' command. This is independent from the main | |
775 ;;; completion code, except for `PC-expand-many-files' which is called | |
776 ;;; when "*"'s are found in the path during filename completion. (The | |
777 ;;; above completion code always understands "*"'s, except in file paths, | |
778 ;;; without relying on the following code.) | |
779 | |
780 (defvar PC-many-files-list nil) | |
781 | |
782 (defun PC-try-load-many-files () | |
783 (if (string-match "\\*" buffer-file-name) | |
784 (let* ((pat buffer-file-name) | |
785 (files (PC-expand-many-files pat)) | |
786 (first (car files)) | |
20709
780929dca508
(PC-try-load-many-files): Load files in reverse
Richard M. Stallman <rms@gnu.org>
parents:
18981
diff
changeset
|
787 (next (reverse (cdr files)))) |
3725 | 788 (kill-buffer (current-buffer)) |
789 (or files | |
790 (error "No matching files")) | |
17352
058970c0f57f
(PC-try-load-many-files): Set truename.
Richard M. Stallman <rms@gnu.org>
parents:
16608
diff
changeset
|
791 ;; Bring the other files (not the first) into buffers. |
3725 | 792 (save-window-excursion |
20709
780929dca508
(PC-try-load-many-files): Load files in reverse
Richard M. Stallman <rms@gnu.org>
parents:
18981
diff
changeset
|
793 (while next |
3725 | 794 (let ((buf (find-file-noselect (car next)))) |
17352
058970c0f57f
(PC-try-load-many-files): Set truename.
Richard M. Stallman <rms@gnu.org>
parents:
16608
diff
changeset
|
795 ;; Put this buffer at the front of the buffer list. |
20709
780929dca508
(PC-try-load-many-files): Load files in reverse
Richard M. Stallman <rms@gnu.org>
parents:
18981
diff
changeset
|
796 (switch-to-buffer buf)) |
780929dca508
(PC-try-load-many-files): Load files in reverse
Richard M. Stallman <rms@gnu.org>
parents:
18981
diff
changeset
|
797 (setq next (cdr next)))) |
17352
058970c0f57f
(PC-try-load-many-files): Set truename.
Richard M. Stallman <rms@gnu.org>
parents:
16608
diff
changeset
|
798 ;; This modifies the `buf' variable inside find-file-noselect. |
3725 | 799 (setq buf (get-file-buffer first)) |
800 (if buf | |
801 nil ; should do verify-visited-file-modtime stuff. | |
802 (setq filename first) | |
803 (setq buf (create-file-buffer filename)) | |
17352
058970c0f57f
(PC-try-load-many-files): Set truename.
Richard M. Stallman <rms@gnu.org>
parents:
16608
diff
changeset
|
804 ;; This modified `truename' inside find-file-noselect. |
058970c0f57f
(PC-try-load-many-files): Set truename.
Richard M. Stallman <rms@gnu.org>
parents:
16608
diff
changeset
|
805 (setq truename (abbreviate-file-name (file-truename filename))) |
3725 | 806 (set-buffer buf) |
807 (erase-buffer) | |
808 (insert-file-contents filename t)) | |
809 (if (cdr files) | |
810 (setq PC-many-files-list (mapconcat | |
811 (if (string-match "\\*.*/" pat) | |
812 'identity | |
813 'file-name-nondirectory) | |
814 (cdr files) ", ") | |
815 find-file-hooks (cons 'PC-after-load-many-files | |
816 find-file-hooks))) | |
817 ;; This modifies the "error" variable inside find-file-noselect. | |
818 (setq error nil) | |
819 t) | |
820 nil)) | |
821 | |
822 (defun PC-after-load-many-files () | |
823 (setq find-file-hooks (delq 'PC-after-load-many-files find-file-hooks)) | |
824 (message "Also loaded %s." PC-many-files-list)) | |
825 | |
826 (defun PC-expand-many-files (name) | |
827 (save-excursion | |
828 (set-buffer (generate-new-buffer " *Glob Output*")) | |
829 (erase-buffer) | |
830 (shell-command (concat "echo " name) t) | |
831 (goto-char (point-min)) | |
832 (if (looking-at ".*No match") | |
833 nil | |
834 (insert "(\"") | |
835 (while (search-forward " " nil t) | |
836 (delete-backward-char 1) | |
837 (insert "\" \"")) | |
838 (goto-char (point-max)) | |
839 (delete-backward-char 1) | |
840 (insert "\")") | |
841 (goto-char (point-min)) | |
21266
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
842 (let ((files (read (current-buffer))) (p nil)) |
3725 | 843 (kill-buffer (current-buffer)) |
21266
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
844 (or (equal completion-ignored-extensions PC-ignored-extensions) |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
845 (setq PC-ignored-regexp |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
846 (concat "\\(" |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
847 (mapconcat |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
848 'regexp-quote |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
849 (setq PC-ignored-extensions |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
850 completion-ignored-extensions) |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
851 "\\|") |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
852 "\\)\\'"))) |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
853 (setq p nil) |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
854 (while files |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
855 (or (string-match PC-ignored-regexp (car files)) |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
856 (setq p (cons (car files) p))) |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
857 (setq files (cdr files))) |
af9641af8877
(PC-expand-many-files): Apply completion-ignored-extensions.
Karl Heuer <kwzh@gnu.org>
parents:
20709
diff
changeset
|
858 p)))) |
3725 | 859 |
860 ;;; Facilities for loading C header files. This is independent from the | |
861 ;;; main completion code. See also the variable `PC-include-file-path' | |
862 ;;; at top of this file. | |
863 | |
864 (defun PC-look-for-include-file () | |
865 (if (string-match "[\"<]\\([^\"<>]*\\)[\">]?$" (buffer-file-name)) | |
866 (let ((name (substring (buffer-file-name) | |
867 (match-beginning 1) (match-end 1))) | |
868 (punc (aref (buffer-file-name) (match-beginning 0))) | |
869 (path nil) | |
870 new-buf) | |
871 (kill-buffer (current-buffer)) | |
872 (if (equal name "") | |
873 (save-excursion | |
874 (set-buffer (car (buffer-list))) | |
875 (save-excursion | |
876 (beginning-of-line) | |
877 (if (looking-at | |
878 "[ \t]*#[ \t]*include[ \t]+[<\"]\\(.+\\)[>\"][ \t]*[\n/]") | |
879 (setq name (buffer-substring (match-beginning 1) | |
880 (match-end 1)) | |
881 punc (char-after (1- (match-beginning 1)))) | |
882 ;; Suggested by Frank Siebenlist: | |
883 (if (or (looking-at | |
884 "[ \t]*([ \t]*load[ \t]+\"\\([^\"]+\\)\"") | |
885 (looking-at | |
886 "[ \t]*([ \t]*load-library[ \t]+\"\\([^\"]+\\)\"") | |
887 (looking-at | |
888 "[ \t]*([ \t]*require[ \t]+'\\([^\t )]+\\)[\t )]")) | |
889 (progn | |
890 (setq name (buffer-substring (match-beginning 1) | |
891 (match-end 1)) | |
892 punc ?\< | |
893 path load-path) | |
894 (if (string-match "\\.elc$" name) | |
895 (setq name (substring name 0 -1)) | |
896 (or (string-match "\\.el$" name) | |
897 (setq name (concat name ".el"))))) | |
898 (error "Not on an #include line")))))) | |
899 (or (string-match "\\.[a-zA-Z0-9]+$" name) | |
900 (setq name (concat name ".h"))) | |
901 (if (eq punc ?\<) | |
902 (let ((path (or path (PC-include-file-path)))) | |
903 (while (and path | |
904 (not (file-exists-p | |
905 (concat (file-name-as-directory (car path)) | |
906 name)))) | |
907 (setq path (cdr path))) | |
908 (if path | |
909 (setq name (concat (file-name-as-directory (car path)) name)) | |
910 (error "No such include file: <%s>" name))) | |
911 (let ((dir (save-excursion | |
912 (set-buffer (car (buffer-list))) | |
913 default-directory))) | |
914 (if (file-exists-p (concat dir name)) | |
915 (setq name (concat dir name)) | |
916 (error "No such include file: \"%s\"" name)))) | |
917 (setq new-buf (get-file-buffer name)) | |
918 (if new-buf | |
919 ;; no need to verify last-modified time for this! | |
920 (set-buffer new-buf) | |
921 (setq new-buf (create-file-buffer name)) | |
922 (set-buffer new-buf) | |
923 (erase-buffer) | |
924 (insert-file-contents name t)) | |
925 (setq filename name | |
926 error nil | |
927 buf new-buf) | |
928 t) | |
929 nil)) | |
930 | |
931 (defun PC-include-file-path () | |
932 (or PC-include-file-path | |
933 (let ((env (getenv "INCPATH")) | |
934 (path nil) | |
935 pos) | |
936 (or env (error "No include file path specified")) | |
937 (while (setq pos (string-match ":[^:]+$" env)) | |
938 (setq path (cons (substring env (1+ pos)) path) | |
939 env (substring env 0 pos))) | |
940 path))) | |
941 | |
942 ;;; This is adapted from lib-complete.el, by Mike Williams. | |
943 (defun PC-include-file-all-completions (file search-path &optional full) | |
944 "Return all completions for FILE in any directory on SEARCH-PATH. | |
945 If optional third argument FULL is non-nil, returned pathnames should be | |
946 absolute rather than relative to some directory on the SEARCH-PATH." | |
947 (setq search-path | |
948 (mapcar '(lambda (dir) | |
949 (if dir (file-name-as-directory dir) default-directory)) | |
950 search-path)) | |
951 (if (file-name-absolute-p file) | |
952 ;; It's an absolute file name, so don't need search-path | |
953 (progn | |
954 (setq file (expand-file-name file)) | |
955 (file-name-all-completions | |
956 (file-name-nondirectory file) (file-name-directory file))) | |
957 (let ((subdir (file-name-directory file)) | |
958 (ndfile (file-name-nondirectory file)) | |
959 file-lists) | |
960 ;; Append subdirectory part to each element of search-path | |
961 (if subdir | |
962 (setq search-path | |
963 (mapcar '(lambda (dir) (concat dir subdir)) | |
964 search-path) | |
965 file )) | |
966 ;; Make list of completions in each directory on search-path | |
967 (while search-path | |
968 (let* ((dir (car search-path)) | |
969 (subdir (if full dir subdir))) | |
970 (if (file-directory-p dir) | |
971 (progn | |
972 (setq file-lists | |
973 (cons | |
974 (mapcar '(lambda (file) (concat subdir file)) | |
975 (file-name-all-completions ndfile | |
976 (car search-path))) | |
977 file-lists)))) | |
978 (setq search-path (cdr search-path)))) | |
979 ;; Compress out duplicates while building complete list (slloooow!) | |
980 (let ((sorted (sort (apply 'nconc file-lists) | |
981 '(lambda (x y) (not (string-lessp x y))))) | |
982 compressed) | |
983 (while sorted | |
984 (if (equal (car sorted) (car compressed)) nil | |
985 (setq compressed (cons (car sorted) compressed))) | |
986 (setq sorted (cdr sorted))) | |
987 compressed)))) | |
988 | |
989 (defun PC-read-include-file-name-internal (string dir action) | |
990 (if (string-match "<\\([^\"<>]*\\)>?$" string) | |
991 (let* ((name (substring string (match-beginning 1) (match-end 1))) | |
992 (str2 (substring string (match-beginning 0))) | |
993 (completion-table | |
994 (mapcar (function (lambda (x) (list (format "<%s>" x)))) | |
995 (PC-include-file-all-completions | |
996 name (PC-include-file-path))))) | |
997 (cond | |
998 ((not completion-table) nil) | |
999 ((eq action nil) (try-completion str2 completion-table nil)) | |
1000 ((eq action t) (all-completions str2 completion-table nil)) | |
1001 ((eq action 'lambda) | |
1002 (eq (try-completion str2 completion-table nil) t)))) | |
1003 (funcall PC-old-read-file-name-internal string dir action))) | |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
1004 |
3725 | 1005 |
1006 (provide 'complete) | |
1007 | |
1008 ;;; End. |