Mercurial > emacs
annotate lisp/complete.el @ 19625:d2fa1806fd28
(HAVE_ALLOCA): Do define this, if SOLARIS2.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 30 Aug 1997 07:18:39 +0000 |
parents | 6681f7141d2b |
children | 780929dca508 |
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> | |
11487
577cd5d36667
Add Keywords: comment header for finder.el.
Roland McGrath <roland@gnu.org>
parents:
10164
diff
changeset
|
6 ;; Keywords: abbrev |
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 | |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
50 ;; Usage: M-x PC-mode. Now, 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 ;; | |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
65 ;; (PC-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-" |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
104 :group 'minibuffer) |
3725 | 105 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
106 (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
|
107 "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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 :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
|
114 (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
|
115 :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
|
116 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
117 :group 'partial-completion |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
118 :require 'complete) |
3725 | 119 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
120 (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
|
121 "*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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 completion." |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
128 :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
|
129 (const :tag "literal" t) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
130 (sexp :tag "find-file" :format "%t\n" find-file)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
131 :group 'partial-completion) |
3725 | 132 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
133 (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
|
134 "*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
|
135 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
|
136 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
137 :group 'partial-completion) |
3725 | 138 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
139 (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
|
140 "*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
|
141 Some arcane rules: |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 :type 'string |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
148 :group 'partial-completion) |
3725 | 149 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
150 (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
|
151 "*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
|
152 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
|
153 :type '(repeat directory) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
154 :group 'partial-completion) |
3725 | 155 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
156 (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
|
157 "*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
|
158 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
159 :group 'partial-completion) |
3725 | 160 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
161 (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
|
162 "*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
|
163 :type 'boolean |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
164 :group 'partial-completion) |
3725 | 165 |
166 (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
|
167 "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
|
168 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
169 (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
|
170 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
171 ;;;###autoload |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
172 (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
|
173 "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
|
174 With prefix ARG, turn Partial Completion mode on if ARG is positive. |
3725 | 175 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 as much as possible. |
3725 | 180 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
181 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
|
182 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
|
183 \\[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
|
184 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
|
185 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
186 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
|
187 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
|
188 \\[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
|
189 \\[find-file] */foo_bar.c TAB completes the directory name as far as possible. |
3725 | 190 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
191 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
|
192 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
|
193 \\[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
|
194 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
|
195 (interactive "P") |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
196 (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
|
197 (> (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
|
198 (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
|
199 ;; 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
|
200 (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
|
201 ;; 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
|
202 (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
|
203 (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
|
204 ((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
|
205 (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
|
206 ;; 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
|
207 (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
|
208 (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
|
209 ((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
|
210 (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
|
211 ;; ... 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
|
212 (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
|
213 (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
|
214 ((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
|
215 (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
|
216 (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
|
217 (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
|
218 '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
|
219 ;; 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
|
220 (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
|
221 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
222 (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
|
223 (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
|
224 (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
|
225 (cond ((not bind) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
226 ;; 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
|
227 ;; 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
|
228 (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
|
229 (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
|
230 (define-key completion-map "?" 'minibuffer-completion-help) |
3725 | 231 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
232 (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
|
233 (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
|
234 (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
|
235 (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
|
236 (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
|
237 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
238 (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
|
239 (PC-default-bindings |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
240 (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
|
241 (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
|
242 (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
|
243 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
244 (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
|
245 (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
|
246 (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
|
247 (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
|
248 (define-key completion-map "\e?" 'PC-completion-help) |
3725 | 249 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
250 (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
|
251 (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
|
252 (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
|
253 (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
|
254 (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
|
255 |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
256 (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
|
257 (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
|
258 (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
|
259 (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
|
260 (define-key must-match-map "\e?" 'PC-completion-help) |
3725 | 261 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
262 (define-key global-map "\e\t" 'PC-lisp-complete-symbol))))) |
3725 | 263 |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
264 ;; 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
|
265 ;; `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
|
266 ;; 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
|
267 ;; 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
|
268 ;; 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
|
269 ;; 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
|
270 ;; 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
|
271 ;; 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
|
272 (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
|
273 (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
|
274 |
3725 | 275 (defun PC-complete () |
276 "Like minibuffer-complete, but allows \"b--di\"-style abbreviations. | |
277 For example, \"M-x b--di\" would match `byte-recompile-directory', or any | |
278 name which consists of three or more words, the first beginning with \"b\" | |
279 and the third beginning with \"di\". | |
280 | |
281 The pattern \"b--d\" is ambiguous for `byte-recompile-directory' and | |
282 `beginning-of-defun', so this would produce a list of completions | |
283 just like when normal Emacs completions are ambiguous. | |
284 | |
285 Word-delimiters for the purposes of Partial Completion are \"-\", \"_\", | |
286 \".\", and SPC." | |
287 (interactive) | |
288 (if (PC-was-meta-key) | |
289 (minibuffer-complete) | |
15802
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
290 ;; 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
|
291 ;; never scroll, always retry completion. |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
292 (or (eq last-command this-command) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
293 (setq minibuffer-scroll-window nil)) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
294 (let ((window minibuffer-scroll-window)) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
295 ;; 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
|
296 ;; 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
|
297 (if (and window (window-buffer window) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
298 (buffer-name (window-buffer window))) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
299 (save-excursion |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
300 (set-buffer (window-buffer window)) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
301 (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
|
302 (set-window-start window (point-min) nil) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
303 (scroll-other-window))) |
1595df9ed1e8
(PC-complete): When command is repeated,
Richard M. Stallman <rms@gnu.org>
parents:
15261
diff
changeset
|
304 (PC-do-completion nil))))) |
3725 | 305 |
306 | |
307 (defun PC-complete-word () | |
308 "Like `minibuffer-complete-word', but allows \"b--di\"-style abbreviations. | |
309 See `PC-complete' for details. | |
310 This can be bound to other keys, like `-' and `.', if you wish." | |
311 (interactive) | |
312 (if (eq (PC-was-meta-key) PC-meta-flag) | |
313 (if (eq last-command-char ? ) | |
314 (minibuffer-complete-word) | |
315 (self-insert-command 1)) | |
316 (self-insert-command 1) | |
317 (if (eobp) | |
318 (PC-do-completion 'word)))) | |
319 | |
320 | |
321 (defun PC-complete-space () | |
322 "Like `minibuffer-complete-word', but allows \"b--di\"-style abbreviations. | |
323 See `PC-complete' for details. | |
324 This is suitable for binding to other keys which should act just like SPC." | |
325 (interactive) | |
326 (if (eq (PC-was-meta-key) PC-meta-flag) | |
327 (minibuffer-complete-word) | |
328 (insert " ") | |
329 (if (eobp) | |
330 (PC-do-completion 'word)))) | |
331 | |
332 | |
333 (defun PC-complete-and-exit () | |
334 "Like `minibuffer-complete-and-exit', but allows \"b--di\"-style abbreviations. | |
335 See `PC-complete' for details." | |
336 (interactive) | |
337 (if (eq (PC-was-meta-key) PC-meta-flag) | |
338 (minibuffer-complete-and-exit) | |
339 (PC-do-complete-and-exit))) | |
340 | |
341 (defun PC-force-complete-and-exit () | |
342 "Like `minibuffer-complete-and-exit', but allows \"b--di\"-style abbreviations. | |
343 See `PC-complete' for details." | |
344 (interactive) | |
345 (let ((minibuffer-completion-confirm nil)) | |
346 (PC-do-complete-and-exit))) | |
347 | |
348 (defun PC-do-complete-and-exit () | |
349 (if (= (buffer-size) 0) ; Duplicate the "bug" that Info-menu relies on... | |
350 (exit-minibuffer) | |
351 (let ((flag (PC-do-completion 'exit))) | |
352 (and flag | |
353 (if (or (eq flag 'complete) | |
354 (not minibuffer-completion-confirm)) | |
355 (exit-minibuffer) | |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
356 (PC-temp-minibuffer-message " [Confirm]")))))) |
3725 | 357 |
358 | |
359 (defun PC-completion-help () | |
360 "Like `minibuffer-completion-help', but allows \"b--di\"-style abbreviations. | |
361 See `PC-complete' for details." | |
362 (interactive) | |
363 (if (eq (PC-was-meta-key) PC-meta-flag) | |
364 (minibuffer-completion-help) | |
365 (PC-do-completion 'help))) | |
366 | |
367 (defun PC-was-meta-key () | |
368 (or (/= (length (this-command-keys)) 1) | |
369 (let ((key (aref (this-command-keys) 0))) | |
370 (if (integerp key) | |
371 (>= key 128) | |
372 (not (null (memq 'meta (event-modifiers key)))))))) | |
373 | |
374 | |
375 (defvar PC-ignored-extensions 'empty-cache) | |
376 (defvar PC-delims 'empty-cache) | |
377 (defvar PC-ignored-regexp nil) | |
378 (defvar PC-word-failed-flag nil) | |
379 (defvar PC-delim-regex nil) | |
380 (defvar PC-ndelims-regex nil) | |
381 (defvar PC-delims-list nil) | |
382 | |
14765
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
383 (defvar PC-completion-as-file-name-predicate |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
384 (function |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
385 (lambda () |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
386 (memq minibuffer-completion-table |
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
387 '(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
|
388 "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
|
389 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
|
390 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
|
391 |
3725 | 392 (defun PC-do-completion (&optional mode beg end) |
393 (or beg (setq beg (point-min))) | |
394 (or end (setq end (point-max))) | |
395 (let* ((table minibuffer-completion-table) | |
396 (pred minibuffer-completion-predicate) | |
14765
844686eabff0
(PC-completion-as-file-name-predicate):
Richard M. Stallman <rms@gnu.org>
parents:
14759
diff
changeset
|
397 (filename (funcall PC-completion-as-file-name-predicate)) |
3725 | 398 (dirname nil) |
8478
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
399 dirlength |
3725 | 400 (str (buffer-substring beg end)) |
401 (incname (and filename (string-match "<\\([^\"<>]*\\)>?$" str))) | |
402 (ambig nil) | |
403 basestr | |
404 regex | |
405 p offset | |
406 (poss nil) | |
407 helpposs | |
408 (case-fold-search completion-ignore-case)) | |
409 | |
410 ;; Check if buffer contents can already be considered complete | |
411 (if (and (eq mode 'exit) | |
412 (PC-is-complete-p str table pred)) | |
413 'complete | |
414 | |
8478
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
415 ;; 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
|
416 ;; in completion. |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
417 (setq dirlength |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
418 (if filename |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
419 (length (file-name-directory str)) |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
420 0)) |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
421 |
3725 | 422 ;; Do substitutions in directory names |
423 (and filename | |
424 (not (equal str (setq p (substitute-in-file-name str)))) | |
425 (progn | |
426 (delete-region beg end) | |
427 (insert p) | |
428 (setq str p end (+ beg (length str))))) | |
429 | |
430 ;; Prepare various delimiter strings | |
431 (or (equal PC-word-delimiters PC-delims) | |
432 (setq PC-delims PC-word-delimiters | |
433 PC-delim-regex (concat "[" PC-delims "]") | |
434 PC-ndelims-regex (concat "[^" PC-delims "]*") | |
435 PC-delims-list (append PC-delims nil))) | |
436 | |
437 ;; Look for wildcard expansions in directory name | |
438 (and filename | |
439 (string-match "\\*.*/" str) | |
440 (let ((pat str) | |
441 files) | |
442 (setq p (1+ (string-match "/[^/]*\\'" pat))) | |
443 (while (setq p (string-match PC-delim-regex pat p)) | |
444 (setq pat (concat (substring pat 0 p) | |
445 "*" | |
446 (substring pat p)) | |
447 p (+ p 2))) | |
448 (setq files (PC-expand-many-files (concat pat "*"))) | |
449 (if files | |
450 (let ((dir (file-name-directory (car files))) | |
451 (p files)) | |
452 (while (and (setq p (cdr p)) | |
453 (equal dir (file-name-directory (car p))))) | |
454 (if p | |
455 (setq filename nil table nil pred nil | |
456 ambig t) | |
457 (delete-region beg end) | |
458 (setq str (concat dir (file-name-nondirectory str))) | |
459 (insert str) | |
460 (setq end (+ beg (length str))))) | |
461 (setq filename nil table nil pred nil)))) | |
462 | |
463 ;; Strip directory name if appropriate | |
464 (if filename | |
465 (if incname | |
466 (setq basestr (substring str incname) | |
467 dirname (substring str 0 incname)) | |
468 (setq basestr (file-name-nondirectory str) | |
469 dirname (file-name-directory str))) | |
470 (setq basestr str)) | |
471 | |
472 ;; Convert search pattern to a standard regular expression | |
473 (setq regex (regexp-quote basestr) | |
474 offset (if (and (> (length regex) 0) | |
475 (not (eq (aref basestr 0) ?\*)) | |
476 (or (eq PC-first-char t) | |
477 (and PC-first-char filename))) 1 0) | |
478 p offset) | |
479 (while (setq p (string-match PC-delim-regex regex p)) | |
480 (if (eq (aref regex p) ? ) | |
481 (setq regex (concat (substring regex 0 p) | |
482 PC-ndelims-regex | |
483 PC-delim-regex | |
484 (substring regex (1+ p))) | |
485 p (+ p (length PC-ndelims-regex) (length PC-delim-regex))) | |
486 (let ((bump (if (memq (aref regex p) | |
487 '(?$ ?^ ?\. ?* ?+ ?? ?[ ?] ?\\)) | |
488 -1 0))) | |
489 (setq regex (concat (substring regex 0 (+ p bump)) | |
490 PC-ndelims-regex | |
491 (substring regex (+ p bump))) | |
492 p (+ p (length PC-ndelims-regex) 1))))) | |
493 (setq p 0) | |
494 (if filename | |
495 (while (setq p (string-match "\\\\\\*" regex p)) | |
496 (setq regex (concat (substring regex 0 p) | |
497 "[^/]*" | |
498 (substring regex (+ p 2)))))) | |
499 ;;(setq the-regex regex) | |
500 (setq regex (concat "\\`" regex)) | |
501 | |
502 ;; Find an initial list of possible completions | |
503 (if (not (setq p (string-match (concat PC-delim-regex | |
504 (if filename "\\|\\*" "")) | |
505 str | |
506 (+ (length dirname) offset)))) | |
507 | |
508 ;; Minibuffer contains no hyphens -- simple case! | |
509 (setq poss (all-completions str | |
510 table | |
511 pred)) | |
512 | |
513 ;; Use all-completions to do an initial cull. This is a big win, | |
514 ;; since all-completions is written in C! | |
515 (let ((compl (all-completions (substring str 0 p) | |
516 table | |
517 pred))) | |
518 (setq p compl) | |
519 (while p | |
520 (and (string-match regex (car p)) | |
16608
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
521 (progn |
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
522 (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
|
523 (setq poss (cons (car p) poss)))) |
3725 | 524 (setq p (cdr p))))) |
525 | |
526 ;; Now we have a list of possible completions | |
527 (cond | |
528 | |
529 ;; No valid completions found | |
530 ((null poss) | |
531 (if (and (eq mode 'word) | |
532 (not PC-word-failed-flag)) | |
533 (let ((PC-word-failed-flag t)) | |
534 (delete-backward-char 1) | |
535 (PC-do-completion 'word)) | |
536 (beep) | |
537 (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
|
538 " [Ambiguous dir name]" |
3725 | 539 (if (eq mode 'help) |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
540 " [No completions]" |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
541 " [No match]"))) |
3725 | 542 nil)) |
543 | |
544 ;; More than one valid completion found | |
545 ((or (cdr (setq helpposs poss)) | |
546 (memq mode '(help word))) | |
547 | |
548 ;; Handle completion-ignored-extensions | |
549 (and filename | |
550 (not (eq mode 'help)) | |
551 (let ((p2 poss)) | |
552 | |
553 ;; Build a regular expression representing the extensions list | |
554 (or (equal completion-ignored-extensions PC-ignored-extensions) | |
555 (setq PC-ignored-regexp | |
556 (concat "\\(" | |
557 (mapconcat | |
558 'regexp-quote | |
559 (setq PC-ignored-extensions | |
560 completion-ignored-extensions) | |
561 "\\|") | |
562 "\\)\\'"))) | |
563 | |
564 ;; Check if there are any without an ignored extension | |
565 (setq p nil) | |
566 (while p2 | |
567 (or (string-match PC-ignored-regexp (car p2)) | |
568 (setq p (cons (car p2) p))) | |
569 (setq p2 (cdr p2))) | |
570 | |
571 ;; If there are "good" names, use them | |
572 (and p (setq poss p)))) | |
573 | |
574 ;; Is the actual string one of the possible completions? | |
575 (setq p (and (not (eq mode 'help)) poss)) | |
576 (while (and p | |
16608
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
577 (not (string-equal (car p) basestr))) |
3725 | 578 (setq p (cdr p))) |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
579 (and p (null mode) |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
580 (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
|
581 (if (and p |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
582 (not (and (null mode) |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
583 (eq this-command last-command)))) |
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
584 t |
3725 | 585 |
586 ;; If ambiguous, try for a partial completion | |
587 (let ((improved nil) | |
588 prefix | |
589 (pt nil) | |
590 (skip "\\`")) | |
591 | |
592 ;; Check if next few letters are the same in all cases | |
593 (if (and (not (eq mode 'help)) | |
594 (setq prefix (try-completion "" (mapcar 'list poss)))) | |
595 (let ((first t) i) | |
596 (if (eq mode 'word) | |
597 (setq prefix (PC-chop-word prefix basestr))) | |
598 (goto-char (+ beg (length dirname))) | |
599 (while (and (progn | |
600 (setq i 0) | |
601 (while (< i (length prefix)) | |
602 (if (and (< (point) end) | |
603 (eq (aref prefix i) | |
604 (following-char))) | |
605 (forward-char 1) | |
606 (if (and (< (point) end) | |
607 (or (and (looking-at " ") | |
608 (memq (aref prefix i) | |
609 PC-delims-list)) | |
610 (eq (downcase (aref prefix i)) | |
611 (downcase | |
612 (following-char))))) | |
613 (progn | |
614 (delete-char 1) | |
615 (setq end (1- end))) | |
616 (and filename (looking-at "\\*") | |
617 (progn | |
618 (delete-char 1) | |
619 (setq end (1- end)))) | |
620 (setq improved t)) | |
16608
e2858bcbed43
(PC-do-completion): Remove text properties from
Karl Heuer <kwzh@gnu.org>
parents:
15802
diff
changeset
|
621 (insert (substring prefix i (1+ i))) |
3725 | 622 (setq end (1+ end))) |
623 (setq i (1+ i))) | |
624 (or pt (equal (point) beg) | |
625 (setq pt (point))) | |
626 (looking-at PC-delim-regex)) | |
627 (setq skip (concat skip | |
628 (regexp-quote prefix) | |
629 PC-ndelims-regex) | |
630 prefix (try-completion | |
631 "" | |
632 (mapcar | |
633 (function | |
634 (lambda (x) | |
635 (list | |
636 (and (string-match skip x) | |
637 (substring | |
638 x | |
639 (match-end 0)))))) | |
640 poss))) | |
641 (or (> i 0) (> (length prefix) 0)) | |
642 (or (not (eq mode 'word)) | |
643 (and first (> (length prefix) 0) | |
644 (setq first nil | |
645 prefix (substring prefix 0 1)))))) | |
646 (goto-char (if (eq mode 'word) end | |
647 (or pt beg))))) | |
648 | |
649 (if (and (eq mode 'word) | |
650 (not PC-word-failed-flag)) | |
651 | |
652 (if improved | |
653 | |
654 ;; We changed it... would it be complete without the space? | |
655 (if (PC-is-complete-p (buffer-substring 1 (1- end)) | |
656 table pred) | |
657 (delete-region (1- end) end))) | |
658 | |
659 (if improved | |
660 | |
661 ;; We changed it... enough to be complete? | |
662 (and (eq mode 'exit) | |
663 (PC-is-complete-p (buffer-string) table pred)) | |
664 | |
665 ;; If totally ambiguous, display a list of completions | |
666 (if (or completion-auto-help | |
667 (eq mode 'help)) | |
7844
86402e8c677b
(PC-do-completion): Likewise.
Richard M. Stallman <rms@gnu.org>
parents:
7792
diff
changeset
|
668 (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
|
669 (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
|
670 (save-excursion |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
671 (set-buffer standard-output) |
9d3d84a3c3fa
(PC-do-completion): Set completion-base-size.
Richard M. Stallman <rms@gnu.org>
parents:
7942
diff
changeset
|
672 ;; 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
|
673 ;; 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
|
674 ;; 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
|
675 (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
|
676 (PC-temp-minibuffer-message " [Next char not unique]")) |
3725 | 677 nil))))) |
678 | |
679 ;; Only one possible completion | |
680 (t | |
681 (if (equal basestr (car poss)) | |
682 (if (null mode) | |
10164
d16e46a4e34c
(PC-do-completion): If complete but not unique,
Richard M. Stallman <rms@gnu.org>
parents:
8478
diff
changeset
|
683 (PC-temp-minibuffer-message " [Sole completion]")) |
3725 | 684 (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
|
685 (insert (format "%s" |
1335cec8a016
(PC-do-completion): Clear text props from inserted text.
Richard M. Stallman <rms@gnu.org>
parents:
7639
diff
changeset
|
686 (if filename |
1335cec8a016
(PC-do-completion): Clear text props from inserted text.
Richard M. Stallman <rms@gnu.org>
parents:
7639
diff
changeset
|
687 (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
|
688 (car poss))))) |
3725 | 689 t))))) |
690 | |
691 | |
692 (defun PC-is-complete-p (str table pred) | |
693 (let ((res (if (listp table) | |
694 (assoc str table) | |
695 (if (vectorp table) | |
696 (or (equal str "nil") ; heh, heh, heh | |
697 (intern-soft str table)) | |
698 (funcall table str pred 'lambda))))) | |
699 (and res | |
700 (or (not pred) | |
701 (and (not (listp table)) (not (vectorp table))) | |
702 (funcall pred res)) | |
703 res))) | |
704 | |
705 (defun PC-chop-word (new old) | |
706 (let ((i -1) | |
707 (j -1)) | |
708 (while (and (setq i (string-match PC-delim-regex old (1+ i))) | |
709 (setq j (string-match PC-delim-regex new (1+ j))))) | |
710 (if (and j | |
711 (or (not PC-word-failed-flag) | |
712 (setq j (string-match PC-delim-regex new (1+ j))))) | |
713 (substring new 0 (1+ j)) | |
714 new))) | |
715 | |
716 (defvar PC-not-minibuffer nil) | |
717 | |
18981
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
718 (defun PC-temp-minibuffer-message (message) |
3725 | 719 "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
|
720 (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
|
721 (message message) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
722 (sit-for 2) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
723 (message "")) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
724 ((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
|
725 (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
|
726 (t |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
727 (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
|
728 (save-excursion |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
729 (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
|
730 (insert message)) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
731 (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
|
732 (sit-for 2) |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
733 (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
|
734 (when quit-flag |
6681f7141d2b
customise & make installation/deinstallation happen on mode command not file load.
Simon Marshall <simon@gnu.org>
parents:
17352
diff
changeset
|
735 (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
|
736 unread-command-events '(7)))))))) |
3725 | 737 |
738 | |
739 (defun PC-lisp-complete-symbol () | |
740 "Perform completion on Lisp symbol preceding point. | |
741 That symbol is compared against the symbols that exist | |
742 and any additional characters determined by what is there | |
743 are inserted. | |
744 If the symbol starts just after an open-parenthesis, | |
745 only symbols with function definitions are considered. | |
746 Otherwise, all symbols with function definitions, values | |
747 or properties are considered." | |
748 (interactive) | |
749 (let* ((end (point)) | |
750 (buffer-syntax (syntax-table)) | |
751 (beg (unwind-protect | |
752 (save-excursion | |
753 (if lisp-mode-syntax-table | |
754 (set-syntax-table lisp-mode-syntax-table)) | |
755 (backward-sexp 1) | |
756 (while (= (char-syntax (following-char)) ?\') | |
757 (forward-char 1)) | |
758 (point)) | |
759 (set-syntax-table buffer-syntax))) | |
760 (minibuffer-completion-table obarray) | |
761 (minibuffer-completion-predicate | |
762 (if (eq (char-after (1- beg)) ?\() | |
763 'fboundp | |
764 (function (lambda (sym) | |
765 (or (boundp sym) (fboundp sym) | |
766 (symbol-plist sym)))))) | |
767 (PC-not-minibuffer t)) | |
768 (PC-do-completion nil beg end))) | |
769 | |
770 | |
771 ;;; Wildcards in `C-x C-f' command. This is independent from the main | |
772 ;;; completion code, except for `PC-expand-many-files' which is called | |
773 ;;; when "*"'s are found in the path during filename completion. (The | |
774 ;;; above completion code always understands "*"'s, except in file paths, | |
775 ;;; without relying on the following code.) | |
776 | |
777 (defvar PC-many-files-list nil) | |
778 | |
779 (defun PC-try-load-many-files () | |
780 (if (string-match "\\*" buffer-file-name) | |
781 (let* ((pat buffer-file-name) | |
782 (files (PC-expand-many-files pat)) | |
783 (first (car files)) | |
784 (next files)) | |
785 (kill-buffer (current-buffer)) | |
786 (or files | |
787 (error "No matching files")) | |
17352
058970c0f57f
(PC-try-load-many-files): Set truename.
Richard M. Stallman <rms@gnu.org>
parents:
16608
diff
changeset
|
788 ;; Bring the other files (not the first) into buffers. |
3725 | 789 (save-window-excursion |
790 (while (setq next (cdr next)) | |
791 (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
|
792 ;; Put this buffer at the front of the buffer list. |
3725 | 793 (switch-to-buffer buf)))) |
17352
058970c0f57f
(PC-try-load-many-files): Set truename.
Richard M. Stallman <rms@gnu.org>
parents:
16608
diff
changeset
|
794 ;; This modifies the `buf' variable inside find-file-noselect. |
3725 | 795 (setq buf (get-file-buffer first)) |
796 (if buf | |
797 nil ; should do verify-visited-file-modtime stuff. | |
798 (setq filename first) | |
799 (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
|
800 ;; 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
|
801 (setq truename (abbreviate-file-name (file-truename filename))) |
3725 | 802 (set-buffer buf) |
803 (erase-buffer) | |
804 (insert-file-contents filename t)) | |
805 (if (cdr files) | |
806 (setq PC-many-files-list (mapconcat | |
807 (if (string-match "\\*.*/" pat) | |
808 'identity | |
809 'file-name-nondirectory) | |
810 (cdr files) ", ") | |
811 find-file-hooks (cons 'PC-after-load-many-files | |
812 find-file-hooks))) | |
813 ;; This modifies the "error" variable inside find-file-noselect. | |
814 (setq error nil) | |
815 t) | |
816 nil)) | |
817 | |
818 (defun PC-after-load-many-files () | |
819 (setq find-file-hooks (delq 'PC-after-load-many-files find-file-hooks)) | |
820 (message "Also loaded %s." PC-many-files-list)) | |
821 | |
822 (defun PC-expand-many-files (name) | |
823 (save-excursion | |
824 (set-buffer (generate-new-buffer " *Glob Output*")) | |
825 (erase-buffer) | |
826 (shell-command (concat "echo " name) t) | |
827 (goto-char (point-min)) | |
828 (if (looking-at ".*No match") | |
829 nil | |
830 (insert "(\"") | |
831 (while (search-forward " " nil t) | |
832 (delete-backward-char 1) | |
833 (insert "\" \"")) | |
834 (goto-char (point-max)) | |
835 (delete-backward-char 1) | |
836 (insert "\")") | |
837 (goto-char (point-min)) | |
838 (let ((files (read (current-buffer)))) | |
839 (kill-buffer (current-buffer)) | |
840 files)))) | |
841 | |
842 ;;; Facilities for loading C header files. This is independent from the | |
843 ;;; main completion code. See also the variable `PC-include-file-path' | |
844 ;;; at top of this file. | |
845 | |
846 (defun PC-look-for-include-file () | |
847 (if (string-match "[\"<]\\([^\"<>]*\\)[\">]?$" (buffer-file-name)) | |
848 (let ((name (substring (buffer-file-name) | |
849 (match-beginning 1) (match-end 1))) | |
850 (punc (aref (buffer-file-name) (match-beginning 0))) | |
851 (path nil) | |
852 new-buf) | |
853 (kill-buffer (current-buffer)) | |
854 (if (equal name "") | |
855 (save-excursion | |
856 (set-buffer (car (buffer-list))) | |
857 (save-excursion | |
858 (beginning-of-line) | |
859 (if (looking-at | |
860 "[ \t]*#[ \t]*include[ \t]+[<\"]\\(.+\\)[>\"][ \t]*[\n/]") | |
861 (setq name (buffer-substring (match-beginning 1) | |
862 (match-end 1)) | |
863 punc (char-after (1- (match-beginning 1)))) | |
864 ;; Suggested by Frank Siebenlist: | |
865 (if (or (looking-at | |
866 "[ \t]*([ \t]*load[ \t]+\"\\([^\"]+\\)\"") | |
867 (looking-at | |
868 "[ \t]*([ \t]*load-library[ \t]+\"\\([^\"]+\\)\"") | |
869 (looking-at | |
870 "[ \t]*([ \t]*require[ \t]+'\\([^\t )]+\\)[\t )]")) | |
871 (progn | |
872 (setq name (buffer-substring (match-beginning 1) | |
873 (match-end 1)) | |
874 punc ?\< | |
875 path load-path) | |
876 (if (string-match "\\.elc$" name) | |
877 (setq name (substring name 0 -1)) | |
878 (or (string-match "\\.el$" name) | |
879 (setq name (concat name ".el"))))) | |
880 (error "Not on an #include line")))))) | |
881 (or (string-match "\\.[a-zA-Z0-9]+$" name) | |
882 (setq name (concat name ".h"))) | |
883 (if (eq punc ?\<) | |
884 (let ((path (or path (PC-include-file-path)))) | |
885 (while (and path | |
886 (not (file-exists-p | |
887 (concat (file-name-as-directory (car path)) | |
888 name)))) | |
889 (setq path (cdr path))) | |
890 (if path | |
891 (setq name (concat (file-name-as-directory (car path)) name)) | |
892 (error "No such include file: <%s>" name))) | |
893 (let ((dir (save-excursion | |
894 (set-buffer (car (buffer-list))) | |
895 default-directory))) | |
896 (if (file-exists-p (concat dir name)) | |
897 (setq name (concat dir name)) | |
898 (error "No such include file: \"%s\"" name)))) | |
899 (setq new-buf (get-file-buffer name)) | |
900 (if new-buf | |
901 ;; no need to verify last-modified time for this! | |
902 (set-buffer new-buf) | |
903 (setq new-buf (create-file-buffer name)) | |
904 (set-buffer new-buf) | |
905 (erase-buffer) | |
906 (insert-file-contents name t)) | |
907 (setq filename name | |
908 error nil | |
909 buf new-buf) | |
910 t) | |
911 nil)) | |
912 | |
913 (defun PC-include-file-path () | |
914 (or PC-include-file-path | |
915 (let ((env (getenv "INCPATH")) | |
916 (path nil) | |
917 pos) | |
918 (or env (error "No include file path specified")) | |
919 (while (setq pos (string-match ":[^:]+$" env)) | |
920 (setq path (cons (substring env (1+ pos)) path) | |
921 env (substring env 0 pos))) | |
922 path))) | |
923 | |
924 ;;; This is adapted from lib-complete.el, by Mike Williams. | |
925 (defun PC-include-file-all-completions (file search-path &optional full) | |
926 "Return all completions for FILE in any directory on SEARCH-PATH. | |
927 If optional third argument FULL is non-nil, returned pathnames should be | |
928 absolute rather than relative to some directory on the SEARCH-PATH." | |
929 (setq search-path | |
930 (mapcar '(lambda (dir) | |
931 (if dir (file-name-as-directory dir) default-directory)) | |
932 search-path)) | |
933 (if (file-name-absolute-p file) | |
934 ;; It's an absolute file name, so don't need search-path | |
935 (progn | |
936 (setq file (expand-file-name file)) | |
937 (file-name-all-completions | |
938 (file-name-nondirectory file) (file-name-directory file))) | |
939 (let ((subdir (file-name-directory file)) | |
940 (ndfile (file-name-nondirectory file)) | |
941 file-lists) | |
942 ;; Append subdirectory part to each element of search-path | |
943 (if subdir | |
944 (setq search-path | |
945 (mapcar '(lambda (dir) (concat dir subdir)) | |
946 search-path) | |
947 file )) | |
948 ;; Make list of completions in each directory on search-path | |
949 (while search-path | |
950 (let* ((dir (car search-path)) | |
951 (subdir (if full dir subdir))) | |
952 (if (file-directory-p dir) | |
953 (progn | |
954 (setq file-lists | |
955 (cons | |
956 (mapcar '(lambda (file) (concat subdir file)) | |
957 (file-name-all-completions ndfile | |
958 (car search-path))) | |
959 file-lists)))) | |
960 (setq search-path (cdr search-path)))) | |
961 ;; Compress out duplicates while building complete list (slloooow!) | |
962 (let ((sorted (sort (apply 'nconc file-lists) | |
963 '(lambda (x y) (not (string-lessp x y))))) | |
964 compressed) | |
965 (while sorted | |
966 (if (equal (car sorted) (car compressed)) nil | |
967 (setq compressed (cons (car sorted) compressed))) | |
968 (setq sorted (cdr sorted))) | |
969 compressed)))) | |
970 | |
971 (defun PC-read-include-file-name-internal (string dir action) | |
972 (if (string-match "<\\([^\"<>]*\\)>?$" string) | |
973 (let* ((name (substring string (match-beginning 1) (match-end 1))) | |
974 (str2 (substring string (match-beginning 0))) | |
975 (completion-table | |
976 (mapcar (function (lambda (x) (list (format "<%s>" x)))) | |
977 (PC-include-file-all-completions | |
978 name (PC-include-file-path))))) | |
979 (cond | |
980 ((not completion-table) nil) | |
981 ((eq action nil) (try-completion str2 completion-table nil)) | |
982 ((eq action t) (all-completions str2 completion-table nil)) | |
983 ((eq action 'lambda) | |
984 (eq (try-completion str2 completion-table nil) t)))) | |
985 (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
|
986 |
3725 | 987 |
988 (provide 'complete) | |
989 | |
990 ;;; End. |