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