38436
|
1 ;;; hippie-exp.el --- expand text trying various ways to find its expansion
|
2230
|
2
|
14169
|
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
|
|
4
|
2230
|
5 ;; Author: Anders Holst <aho@sans.kth.se>
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
6 ;; Last change: 3 March 1998
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
7 ;; Version: 1.6
|
22250
|
8 ;; Keywords: abbrev convenience
|
2230
|
9
|
1737
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;; it under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
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.
|
1737
|
26
|
2233
|
27 ;;; Commentary:
|
14169
|
28
|
1737
|
29 ;; `hippie-expand' is a single function for a lot of different kinds
|
|
30 ;; of completions and expansions. Called repeatedly it tries all
|
|
31 ;; possible completions in succession.
|
|
32 ;; Which kinds of completions to try, and in which order, is
|
|
33 ;; determined by the contents of `hippie-expand-try-functions-list'.
|
|
34 ;; Much customization of `hippie-expand' can be made by changing the
|
|
35 ;; order of, removing, or inserting new functions in this list.
|
|
36 ;; Given a positive numeric argument, `hippie-expand' jumps directly
|
|
37 ;; ARG functions forward in this list. Given some other argument
|
|
38 ;; (a negative argument or just Ctrl-U) it undoes the tried
|
|
39 ;; completion.
|
5296
|
40 ;;
|
1737
|
41 ;; If the variable `hippie-expand-verbose' is non-nil, `hippie-expand'
|
|
42 ;; outputs in a message which try-function in the list that is used
|
|
43 ;; currently (ie. was used currently and will be tried first the next
|
|
44 ;; time).
|
4130
|
45 ;; The variable `hippie-expand-max-buffers' determines in how many
|
|
46 ;; buffers, apart from the current, to search for expansions in. It
|
|
47 ;; is used by the try-functions named "-all-buffers".
|
5296
|
48 ;; The variable `hippie-expand-ignore-buffers' is a list of regexps
|
|
49 ;; matching buffer names (as strings) or major modes (as atoms) of
|
|
50 ;; buffers that should not be searched by the try-functions named
|
|
51 ;; "-all-buffers".
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
52 ;; If set, the variable `hippie-expand-only-buffers' does the opposite
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
53 ;; of `hippie-expand-ignore-buffers', in that the search is restricted
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
54 ;; to only the kind of buffers listed.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
55 ;; If the variable `hippie-expand-no-restriction' is non-nil, narrowed
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
56 ;; buffers are widened before they are searched.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
57 ;; The variable `hippie-expand-dabbrev-skip-space' controls whether
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
58 ;; trailing spaces will be included in the abbreviation to search for,
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
59 ;; which then gives the same behavior as the original `dabbrev-expand'.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
60 ;; The variable `hippie-expand-dabbrev-as-symbol' controls whether
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
61 ;; characters of syntax '_' is considered part of the words to expand
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
62 ;; dynamically.
|
1737
|
63 ;; See also the macro `make-hippie-expand-function' below.
|
|
64 ;;
|
|
65 ;; A short description of the current try-functions in this file:
|
|
66 ;; `try-complete-file-name' : very convenient to have in any buffer,
|
|
67 ;; and not just in the minibuffer or (some) shell-mode. It goes
|
|
68 ;; through all possible completions instead of just completing as
|
|
69 ;; much as is unique.
|
|
70 ;; `try-complete-file-name-partially' : To insert in the list just
|
|
71 ;; before `try-complete-file-name' for those who want first to get
|
|
72 ;; a file name completed only as many characters as is unique.
|
|
73 ;; `try-expand-all-abbrevs' : can be removed if you don't use abbrevs.
|
|
74 ;; Otherwise it looks through all abbrev-tables, starting with
|
|
75 ;; the local followed by the global.
|
|
76 ;; `try-expand-line' : Searches the buffer for an entire line that
|
|
77 ;; begins exactly as the current line. Convenient sometimes, for
|
|
78 ;; example as a substitute for (or complement to) the history
|
4130
|
79 ;; list in shell-like buffers. At other times, only confusing.
|
1737
|
80 ;; `try-expand-line-all-buffers' : Like `try-expand-line' but searches
|
|
81 ;; in all buffers (except the current). (This may be a little
|
4130
|
82 ;; slow, don't use it unless you are really fond of `hippie-expand'.)
|
|
83 ;; `try-expand-list' : Tries to expand the text back to the nearest
|
|
84 ;; open delimiter, to a whole list from the buffer. Convenient for
|
|
85 ;; example when writing lisp or TeX.
|
|
86 ;; `try-expand-list-all-buffers' : Like `try-expand-list' but searches
|
|
87 ;; in all buffers (except the current).
|
1737
|
88 ;; `try-expand-dabbrev' : works exactly as dabbrev-expand (but of
|
|
89 ;; course in a way compatible with the other try-functions).
|
|
90 ;; `try-expand-dabbrev-all-buffers' : perhaps the most useful of them,
|
|
91 ;; like `dabbrev-expand' but searches all Emacs buffers (except the
|
|
92 ;; current) for matching words. (No, I don't find this one
|
|
93 ;; particularly slow.)
|
13207
|
94 ;; `try-expand-dabbrev-visible': Searches the currently visible parts of
|
|
95 ;; all windows. Can be put before `try-expand-dabbrev-all-buffers' to
|
|
96 ;; first try the expansions you can see.
|
|
97 ;; `try-expand-dabbrev-from-kill': Searches the kill ring for a suitable
|
|
98 ;; completion of the word. Good to have, just in case the word was not
|
|
99 ;; found elsewhere.
|
|
100 ;; `try-expand-whole-kill' : Tries to complete text with a whole entry
|
|
101 ;; from the kill ring. May be good if you don't know how far up in
|
|
102 ;; the kill-ring the required entry is, and don't want to mess with
|
|
103 ;; "Choose Next Paste".
|
1737
|
104 ;; `try-complete-lisp-symbol' : like `lisp-complete-symbol', but goes
|
|
105 ;; through all possibilities instead of completing what is unique.
|
|
106 ;; Might be tedious (usually a lot of possible completions) and
|
|
107 ;; since its function is much like `lisp-complete-symbol', which
|
|
108 ;; already has a key of its own, you might want to remove this.
|
|
109 ;; `try-complete-lisp-symbol-partially' : To insert in the list just
|
|
110 ;; before `try-complete-lisp-symbol' for those who first want to get
|
4130
|
111 ;; completion of what is unique in the name.
|
|
112 ;;
|
|
113 ;; Not all of the above functions are by default in
|
|
114 ;; `hippie-expand-try-functions-list'. This variable is better set
|
|
115 ;; in ".emacs" to make `hippie-expand' behave maximally convenient
|
|
116 ;; according to personal taste. Also, instead of loading the
|
|
117 ;; variable with all kinds of try-functions above, it might be an
|
|
118 ;; idea to use `make-hippie-expand-function' to construct different
|
|
119 ;; `hippie-expand'-like functions, with different try-lists and bound
|
|
120 ;; to different keys. It is also possible to make
|
|
121 ;; `hippie-expand-try-functions-list' a buffer local variable, and
|
|
122 ;; let it depend on the mode (by setting it in the mode-hooks).
|
1737
|
123 ;;
|
|
124 ;; To write new try-functions, consider the following:
|
|
125 ;; Each try-function takes one argument OLD which is nil the first
|
|
126 ;; time the function is called and true in succeeding calls for the
|
|
127 ;; same string to complete. The first time the function has to
|
|
128 ;; extract the string before point to complete, and substitute the
|
|
129 ;; first completion alternative for it. On following calls it has to
|
|
130 ;; substitute the next possible completion for the last tried string.
|
|
131 ;; The try-function is to return t as long as it finds new
|
|
132 ;; possible completions. When there are no more alternatives it has
|
|
133 ;; to restore the text before point to its original contents, and
|
|
134 ;; return nil (don't beep or message or anything).
|
|
135 ;; The try-function can (should) use the following functions:
|
|
136 ;; `he-init-string' : Initializes the text to substitute to the
|
|
137 ;; contents of the region BEGIN to END. Also sets the variable
|
|
138 ;; `he-search-string' to the text to expand.
|
|
139 ;; `he-substitute-string' : substitutes STR into the region
|
|
140 ;; initialized with `he-init-string'. (An optional second argument
|
|
141 ;; TRANS-CASE non-nil, means transfer of case from the abbreviation
|
|
142 ;; to the expansion is ok if that is enabled in the buffer.)
|
|
143 ;; `he-reset-string' : Resets the initialized region to its original
|
|
144 ;; contents.
|
|
145 ;; There is also a variable: `he-tried-table' which is meant to contain
|
|
146 ;; all tried expansions so far. The try-function can check this
|
|
147 ;; variable to see whether an expansion has already been tried
|
13207
|
148 ;; (hint: `he-string-member').
|
1737
|
149 ;;
|
4130
|
150 ;; Known bugs
|
1737
|
151 ;;
|
|
152 ;; It may happen that some completion suggestion occurs twice, in
|
|
153 ;; spite of the use of `he-tried-table' to prevent that. This is
|
|
154 ;; because different try-functions may try to complete different
|
|
155 ;; lengths of text, and thus put different amounts of the
|
13207
|
156 ;; text in `he-tried-table'. Anyway this seems to occur seldom enough
|
|
157 ;; not to be too disturbing. Also it should NOT be possible for the
|
1737
|
158 ;; opposite situation to occur, that `hippie-expand' misses some
|
|
159 ;; suggestion because it thinks it has already tried it.
|
|
160 ;;
|
4130
|
161 ;; Acknowledgement
|
1737
|
162 ;;
|
|
163 ;; I want to thank Mikael Djurfeldt in discussions with whom the idea
|
|
164 ;; of this function took form.
|
|
165 ;; I am also grateful to all those who have given me suggestions on
|
13207
|
166 ;; how to improve it, and all those who helped to find and remove bugs.
|
1737
|
167 ;;
|
|
168
|
2233
|
169 ;;; Code:
|
1737
|
170
|
26599
|
171 (eval-when-compile (require 'comint))
|
|
172
|
17634
|
173 (defgroup hippie-expand nil
|
|
174 "Expand text trying various ways to find its expansion."
|
26599
|
175 :link '(custom-manual "(autotype)Hippie Expand")
|
|
176 :link '(emacs-commentary-link "hippie-exp")
|
22250
|
177 :group 'abbrev
|
|
178 :group 'convenience)
|
17634
|
179
|
1737
|
180 (defvar he-num -1)
|
|
181
|
4130
|
182 (defvar he-string-beg (make-marker))
|
1737
|
183
|
4130
|
184 (defvar he-string-end (make-marker))
|
1737
|
185
|
|
186 (defvar he-search-string ())
|
|
187
|
|
188 (defvar he-expand-list ())
|
|
189
|
|
190 (defvar he-tried-table ())
|
|
191
|
4130
|
192 (defvar he-search-loc (make-marker))
|
1737
|
193
|
13207
|
194 (defvar he-search-loc2 ())
|
|
195
|
1737
|
196 (defvar he-search-bw ())
|
|
197
|
|
198 (defvar he-search-bufs ())
|
|
199
|
4130
|
200 (defvar he-searched-n-bufs ())
|
|
201
|
13207
|
202 (defvar he-search-window ())
|
|
203
|
4130
|
204 ;;;###autoload
|
26599
|
205 (defcustom hippie-expand-try-functions-list
|
|
206 '(try-complete-file-name-partially
|
|
207 try-complete-file-name
|
|
208 try-expand-all-abbrevs
|
|
209 try-expand-list
|
|
210 try-expand-line
|
|
211 try-expand-dabbrev
|
|
212 try-expand-dabbrev-all-buffers
|
|
213 try-expand-dabbrev-from-kill
|
|
214 try-complete-lisp-symbol-partially
|
|
215 try-complete-lisp-symbol)
|
1737
|
216 "The list of expansion functions tried in order by `hippie-expand'.
|
|
217 To change the behavior of `hippie-expand', remove, change the order of,
|
26599
|
218 or insert functions in this list."
|
|
219 :type '(repeat function)
|
|
220 :group 'hippie-expand)
|
1737
|
221
|
4130
|
222 ;;;###autoload
|
17634
|
223 (defcustom hippie-expand-verbose t
|
|
224 "*Non-nil makes `hippie-expand' output which function it is trying."
|
|
225 :type 'boolean
|
|
226 :group 'hippie-expand)
|
1737
|
227
|
4130
|
228 ;;;###autoload
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
229 (defcustom hippie-expand-dabbrev-skip-space nil
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
230 "*Non-nil means tolerate trailing spaces in the abbreviation to expand."
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
231 :group 'hippie-expand
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
232 :type 'boolean)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
233
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
234 ;;;###autoload
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
235 (defcustom hippie-expand-dabbrev-as-symbol t
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
236 "*Non-nil means expand as symbols, i.e. syntax `_' is considered a letter."
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
237 :group 'hippie-expand
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
238 :type 'boolean)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
239
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
240 ;;;###autoload
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
241 (defcustom hippie-expand-no-restriction t
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
242 "*Non-nil means that narrowed buffers are widened during search."
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
243 :group 'hippie-expand
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
244 :type 'boolean)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
245
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
246 ;;;###autoload
|
17634
|
247 (defcustom hippie-expand-max-buffers ()
|
4130
|
248 "*The maximum number of buffers (apart from the current) searched.
|
17634
|
249 If nil, all buffers are searched."
|
|
250 :type '(choice (const :tag "All" nil)
|
|
251 integer)
|
|
252 :group 'hippie-expand)
|
4130
|
253
|
|
254 ;;;###autoload
|
17634
|
255 (defcustom hippie-expand-ignore-buffers '("^ \\*.*\\*$" dired-mode)
|
5296
|
256 "*A list specifying which buffers not to search (if not current).
|
|
257 Can contain both regexps matching buffer names (as strings) and major modes
|
17634
|
258 \(as atoms)"
|
|
259 :type '(repeat (choice regexp (symbol :tag "Major Mode")))
|
|
260 :group 'hippie-expand)
|
5296
|
261
|
|
262 ;;;###autoload
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
263 (defcustom hippie-expand-only-buffers ()
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
264 "*A list specifying the only buffers to search (in addition to current).
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
265 Can contain both regexps matching buffer names (as strings) and major modes
|
42205
|
266 \(as atoms). If non-nil, this variable overrides the variable
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
267 `hippie-expand-ignore-buffers'."
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
268 :type '(repeat (choice regexp (symbol :tag "Major Mode")))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
269 :group 'hippie-expand)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
270
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
271 ;;;###autoload
|
1737
|
272 (defun hippie-expand (arg)
|
|
273 "Try to expand text before point, using multiple methods.
|
|
274 The expansion functions in `hippie-expand-try-functions-list' are
|
|
275 tried in order, until a possible expansion is found. Repeated
|
|
276 application of `hippie-expand' inserts successively possible
|
|
277 expansions.
|
|
278 With a positive numeric argument, jumps directly to the ARG next
|
|
279 function in this list. With a negative argument or just \\[universal-argument],
|
|
280 undoes the expansion."
|
|
281 (interactive "P")
|
|
282 (if (or (not arg)
|
|
283 (and (integerp arg) (> arg 0)))
|
|
284 (let ((first (or (= he-num -1)
|
|
285 (not (equal this-command last-command)))))
|
|
286 (if first
|
|
287 (progn
|
|
288 (setq he-num -1)
|
|
289 (setq he-tried-table nil)))
|
|
290 (if arg
|
|
291 (if (not first) (he-reset-string))
|
|
292 (setq arg 0))
|
|
293 (let ((i (max (+ he-num arg) 0)))
|
|
294 (while (not (or (>= i (length hippie-expand-try-functions-list))
|
|
295 (apply (nth i hippie-expand-try-functions-list)
|
|
296 (list (= he-num i)))))
|
|
297 (setq i (1+ i)))
|
|
298 (setq he-num i))
|
|
299 (if (>= he-num (length hippie-expand-try-functions-list))
|
|
300 (progn
|
|
301 (setq he-num -1)
|
|
302 (if first
|
|
303 (message "No expansion found")
|
|
304 (message "No further expansions found"))
|
|
305 (ding))
|
4130
|
306 (if (and hippie-expand-verbose
|
13207
|
307 (not (window-minibuffer-p (selected-window))))
|
14317
|
308 (message "Using %s"
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
309 (nth he-num hippie-expand-try-functions-list)))))
|
13207
|
310 (if (and (>= he-num 0)
|
|
311 (eq (marker-buffer he-string-beg) (current-buffer)))
|
1737
|
312 (progn
|
|
313 (setq he-num -1)
|
|
314 (he-reset-string)
|
4130
|
315 (if (and hippie-expand-verbose
|
13207
|
316 (not (window-minibuffer-p (selected-window))))
|
1737
|
317 (message "Undoing expansions"))))))
|
4130
|
318
|
1737
|
319 ;; Initializes the region to expand (to between BEG and END).
|
|
320 (defun he-init-string (beg end)
|
4130
|
321 (set-marker he-string-beg beg)
|
|
322 (set-marker he-string-end end)
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
323 (setq he-search-string (buffer-substring-no-properties beg end)))
|
1737
|
324
|
|
325 ;; Resets the expanded region to its original contents.
|
|
326 (defun he-reset-string ()
|
4130
|
327 (let ((newpos (point-marker)))
|
|
328 (goto-char he-string-beg)
|
|
329 (insert he-search-string)
|
13207
|
330 (delete-region (point) he-string-end)
|
|
331 (goto-char newpos)))
|
1737
|
332
|
|
333 ;; Substitutes an expansion STR into the correct region (the region
|
|
334 ;; initialized with `he-init-string').
|
|
335 ;; An optional argument TRANS-CASE means that it is ok to transfer case
|
|
336 ;; from the abbreviation to the expansion if that is possible, and is
|
|
337 ;; enabled in the buffer.
|
|
338 (defun he-substitute-string (str &optional trans-case)
|
|
339 (let ((trans-case (and trans-case
|
|
340 case-replace
|
13207
|
341 case-fold-search))
|
|
342 (newpos (point-marker))
|
|
343 (subst ()))
|
1737
|
344 (goto-char he-string-beg)
|
13207
|
345 (setq subst (if trans-case (he-transfer-case he-search-string str) str))
|
|
346 (setq he-tried-table (cons subst he-tried-table))
|
|
347 (insert subst)
|
|
348 (delete-region (point) he-string-end)
|
|
349 (goto-char newpos)))
|
|
350
|
|
351 (defun he-capitalize-first (str)
|
|
352 (save-match-data
|
|
353 (if (string-match "\\Sw*\\(\\sw\\).*" str)
|
|
354 (let ((res (downcase str))
|
|
355 (no (match-beginning 1)))
|
|
356 (aset res no (upcase (aref str no)))
|
|
357 res)
|
|
358 str)))
|
1737
|
359
|
|
360 (defun he-ordinary-case-p (str)
|
|
361 (or (string= str (downcase str))
|
|
362 (string= str (upcase str))
|
13207
|
363 (string= str (capitalize str))
|
|
364 (string= str (he-capitalize-first str))))
|
1737
|
365
|
13207
|
366 (defun he-transfer-case (from-str to-str)
|
|
367 (cond ((string= from-str (substring to-str 0 (min (length from-str)
|
|
368 (length to-str))))
|
|
369 to-str)
|
|
370 ((not (he-ordinary-case-p to-str))
|
13225
|
371 to-str)
|
13207
|
372 ((string= from-str (downcase from-str))
|
|
373 (downcase to-str))
|
|
374 ((string= from-str (upcase from-str))
|
|
375 (upcase to-str))
|
|
376 ((string= from-str (he-capitalize-first from-str))
|
|
377 (he-capitalize-first to-str))
|
|
378 ((string= from-str (capitalize from-str))
|
|
379 (capitalize to-str))
|
|
380 (t
|
|
381 to-str)))
|
|
382
|
1737
|
383
|
|
384 ;; Check if STR is a member of LST.
|
42205
|
385 ;; Transform to the final case if optional TRANS-CASE is non-nil.
|
13207
|
386 (defun he-string-member (str lst &optional trans-case)
|
|
387 (if str
|
|
388 (member (if (and trans-case
|
|
389 case-replace
|
|
390 case-fold-search)
|
|
391 (he-transfer-case he-search-string str)
|
|
392 str)
|
|
393 lst)))
|
1737
|
394
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
395 ;; Check if current buffer matches any atom or regexp in LST.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
396 ;; Atoms are interpreted as major modes, strings as regexps mathing the name.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
397 (defun he-buffer-member (lst)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
398 (or (memq major-mode lst)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
399 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
400 (while (and lst
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
401 (or (not (stringp (car lst)))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
402 (not (string-match (car lst) (buffer-name)))))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
403 (setq lst (cdr lst)))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
404 lst)))
|
5296
|
405
|
1737
|
406 ;; For the real hippie-expand enthusiast: A macro that makes it
|
|
407 ;; possible to use many functions like hippie-expand, but with
|
|
408 ;; different try-functions-lists.
|
|
409 ;; Usage is for example:
|
|
410 ;; (fset 'my-complete-file (make-hippie-expand-function
|
|
411 ;; '(try-complete-file-name-partially
|
|
412 ;; try-complete-file-name)))
|
|
413 ;; (fset 'my-complete-line (make-hippie-expand-function
|
|
414 ;; '(try-expand-line
|
|
415 ;; try-expand-line-all-buffers)))
|
|
416 ;;
|
4130
|
417 ;;;###autoload
|
1737
|
418 (defmacro make-hippie-expand-function (try-list &optional verbose)
|
|
419 "Construct a function similar to `hippie-expand'.
|
|
420 Make it use the expansion functions in TRY-LIST. An optional second
|
|
421 argument VERBOSE non-nil makes the function verbose."
|
26449
|
422 `(function (lambda (arg)
|
|
423 ,(concat
|
|
424 "Try to expand text before point, using the following functions: \n"
|
|
425 (mapconcat 'prin1-to-string (eval try-list) ", "))
|
|
426 (interactive "P")
|
|
427 (let ((hippie-expand-try-functions-list ,try-list)
|
|
428 (hippie-expand-verbose ,verbose))
|
|
429 (hippie-expand arg)))))
|
1737
|
430
|
|
431
|
|
432 ;;; Here follows the try-functions and their requisites:
|
|
433
|
13207
|
434
|
1737
|
435 (defun try-complete-file-name (old)
|
|
436 "Try to complete text as a file name.
|
|
437 The argument OLD has to be nil the first call of this function, and t
|
|
438 for subsequent calls (for further possible completions of the same
|
|
439 string). It returns t if a new completion is found, nil otherwise."
|
|
440 (if (not old)
|
|
441 (progn
|
|
442 (he-init-string (he-file-name-beg) (point))
|
13207
|
443 (let ((name-part (he-file-name-nondirectory he-search-string))
|
|
444 (dir-part (expand-file-name (or (he-file-name-directory
|
1737
|
445 he-search-string) ""))))
|
|
446 (if (not (he-string-member name-part he-tried-table))
|
|
447 (setq he-tried-table (cons name-part he-tried-table)))
|
|
448 (if (and (not (equal he-search-string ""))
|
13207
|
449 (he-file-directory-p dir-part))
|
1737
|
450 (setq he-expand-list (sort (file-name-all-completions
|
|
451 name-part
|
|
452 dir-part)
|
|
453 'string-lessp))
|
|
454 (setq he-expand-list ())))))
|
|
455
|
|
456 (while (and he-expand-list
|
|
457 (he-string-member (car he-expand-list) he-tried-table))
|
|
458 (setq he-expand-list (cdr he-expand-list)))
|
|
459 (if (null he-expand-list)
|
|
460 (progn
|
13207
|
461 (if old (he-reset-string))
|
1737
|
462 ())
|
13207
|
463 (let ((filename (he-concat-directory-file-name
|
|
464 (he-file-name-directory he-search-string)
|
|
465 (car he-expand-list))))
|
1737
|
466 (he-substitute-string filename)
|
13207
|
467 (setq he-tried-table (cons (car he-expand-list) (cdr he-tried-table)))
|
1737
|
468 (setq he-expand-list (cdr he-expand-list))
|
|
469 t)))
|
|
470
|
|
471 (defun try-complete-file-name-partially (old)
|
|
472 "Try to complete text as a file name, as many characters as unique.
|
|
473 The argument OLD has to be nil the first call of this function. It
|
|
474 returns t if a unique, possibly partial, completion is found, nil
|
|
475 otherwise."
|
|
476 (let ((expansion ()))
|
|
477 (if (not old)
|
|
478 (progn
|
|
479 (he-init-string (he-file-name-beg) (point))
|
13207
|
480 (let ((name-part (he-file-name-nondirectory he-search-string))
|
|
481 (dir-part (expand-file-name (or (he-file-name-directory
|
1737
|
482 he-search-string) ""))))
|
|
483 (if (and (not (equal he-search-string ""))
|
13207
|
484 (he-file-directory-p dir-part))
|
1737
|
485 (setq expansion (file-name-completion name-part
|
|
486 dir-part)))
|
|
487 (if (or (eq expansion t)
|
13207
|
488 (string= expansion name-part)
|
|
489 (he-string-member expansion he-tried-table))
|
1737
|
490 (setq expansion ())))))
|
|
491
|
|
492 (if (not expansion)
|
|
493 (progn
|
13207
|
494 (if old (he-reset-string))
|
1737
|
495 ())
|
13207
|
496 (let ((filename (he-concat-directory-file-name
|
|
497 (he-file-name-directory he-search-string)
|
|
498 expansion)))
|
1737
|
499 (he-substitute-string filename)
|
13207
|
500 (setq he-tried-table (cons expansion (cdr he-tried-table)))
|
1737
|
501 t))))
|
|
502
|
13207
|
503 (defvar he-file-name-chars
|
|
504 (cond ((memq system-type '(vax-vms axp-vms))
|
|
505 "-a-zA-Z0-9_/.,~^#$+=:\\[\\]")
|
15330
|
506 ((memq system-type '(ms-dos windows-nt))
|
13207
|
507 "-a-zA-Z0-9_/.,~^#$+=:\\\\")
|
|
508 (t ;; More strange file formats ?
|
|
509 "-a-zA-Z0-9_/.,~^#$+="))
|
|
510 "Characters that are considered part of the file name to expand.")
|
|
511
|
1737
|
512 (defun he-file-name-beg ()
|
18030
|
513 (let ((op (point)))
|
|
514 (save-excursion
|
|
515 (skip-chars-backward he-file-name-chars)
|
|
516 (if (> (skip-syntax-backward "w") 0) ;; No words with non-file chars
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
517 op
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
518 (point)))))
|
13207
|
519
|
|
520 ;; Thanks go to Richard Levitte <levitte@e.kth.se> who helped to make these
|
|
521 ;; work under VMS, and to David Hughes <ukchugd@ukpmr.cs.philips.nl> who
|
|
522 ;; helped to make it work on PC.
|
|
523 (defun he-file-name-nondirectory (file)
|
|
524 "Fix to make `file-name-nondirectory' work for hippie-expand under VMS."
|
|
525 (if (memq system-type '(axp-vms vax-vms))
|
|
526 (let ((n (file-name-nondirectory file)))
|
|
527 (if (string-match "^\\(\\[.*\\)\\.\\([^\\.]*\\)$" n)
|
|
528 (concat "[." (substring n (match-beginning 2) (match-end 2)))
|
|
529 n))
|
|
530 (file-name-nondirectory file)))
|
1737
|
531
|
13207
|
532 (defun he-file-name-directory (file)
|
|
533 "Fix to make `file-name-directory' work for hippie-expand under VMS."
|
|
534 (if (memq system-type '(axp-vms vax-vms))
|
|
535 (let ((n (file-name-nondirectory file))
|
|
536 (d (file-name-directory file)))
|
|
537 (if (string-match "^\\(\\[.*\\)\\.\\([^\\.]*\\)$" n)
|
|
538 (concat d (substring n (match-beginning 1) (match-end 1)) "]")
|
|
539 d))
|
|
540 (file-name-directory file)))
|
|
541
|
|
542 (defun he-file-directory-p (file)
|
|
543 "Fix to make `file-directory-p' work for hippie-expand under VMS."
|
|
544 (if (memq system-type '(vax-vms axp-vms))
|
|
545 (or (file-directory-p file)
|
|
546 (file-directory-p (concat file "[000000]")))
|
15447
|
547 (file-directory-p file)))
|
13207
|
548
|
|
549 (defun he-concat-directory-file-name (dir-part name-part)
|
|
550 "Try to slam together two parts of a file specification, system dependently."
|
15447
|
551 (cond ((null dir-part) name-part)
|
|
552 ((memq system-type '(axp-vms vax-vms))
|
13207
|
553 (if (and (string= (substring dir-part -1) "]")
|
|
554 (string= (substring name-part 0 2) "[."))
|
|
555 (concat (substring dir-part 0 -1) (substring name-part 1))
|
|
556 (concat dir-part name-part)))
|
16590
|
557 ((memq system-type '(ms-dos w32))
|
13207
|
558 (if (and (string-match "\\\\" dir-part)
|
|
559 (not (string-match "/" dir-part))
|
|
560 (= (aref name-part (1- (length name-part))) ?/))
|
|
561 (aset name-part (1- (length name-part)) ?\\))
|
|
562 (concat dir-part name-part))
|
|
563 (t
|
|
564 (concat dir-part name-part))))
|
|
565
|
1737
|
566 (defun try-complete-lisp-symbol (old)
|
|
567 "Try to complete word as an Emacs Lisp symbol.
|
|
568 The argument OLD has to be nil the first call of this function, and t
|
|
569 for subsequent calls (for further possible completions of the same
|
|
570 string). It returns t if a new completion is found, nil otherwise."
|
|
571 (if (not old)
|
|
572 (progn
|
|
573 (he-init-string (he-lisp-symbol-beg) (point))
|
|
574 (if (not (he-string-member he-search-string he-tried-table))
|
|
575 (setq he-tried-table (cons he-search-string he-tried-table)))
|
|
576 (setq he-expand-list
|
|
577 (and (not (equal he-search-string ""))
|
|
578 (sort (all-completions he-search-string obarray
|
|
579 (function (lambda (sym)
|
|
580 (or (boundp sym)
|
|
581 (fboundp sym)
|
|
582 (symbol-plist sym)))))
|
|
583 'string-lessp)))))
|
|
584 (while (and he-expand-list
|
|
585 (he-string-member (car he-expand-list) he-tried-table))
|
|
586 (setq he-expand-list (cdr he-expand-list)))
|
|
587 (if (null he-expand-list)
|
|
588 (progn
|
13207
|
589 (if old (he-reset-string))
|
1737
|
590 ())
|
|
591 (progn
|
|
592 (he-substitute-string (car he-expand-list))
|
|
593 (setq he-expand-list (cdr he-expand-list))
|
|
594 t)))
|
|
595
|
|
596 (defun try-complete-lisp-symbol-partially (old)
|
|
597 "Try to complete as an Emacs Lisp symbol, as many characters as unique.
|
|
598 The argument OLD has to be nil the first call of this function. It
|
|
599 returns t if a unique, possibly partial, completion is found, nil
|
|
600 otherwise."
|
|
601 (let ((expansion ()))
|
|
602 (if (not old)
|
|
603 (progn
|
|
604 (he-init-string (he-lisp-symbol-beg) (point))
|
|
605 (if (not (string= he-search-string ""))
|
|
606 (setq expansion
|
|
607 (try-completion he-search-string obarray
|
|
608 (function (lambda (sym)
|
|
609 (or (boundp sym)
|
|
610 (fboundp sym)
|
|
611 (symbol-plist sym)))))))
|
|
612 (if (or (eq expansion t)
|
13207
|
613 (string= expansion he-search-string)
|
|
614 (he-string-member expansion he-tried-table))
|
1737
|
615 (setq expansion ()))))
|
|
616
|
|
617 (if (not expansion)
|
|
618 (progn
|
13207
|
619 (if old (he-reset-string))
|
1737
|
620 ())
|
|
621 (progn
|
|
622 (he-substitute-string expansion)
|
|
623 t))))
|
|
624
|
|
625 (defun he-lisp-symbol-beg ()
|
18030
|
626 (save-excursion
|
|
627 (skip-syntax-backward "w_")
|
|
628 (point)))
|
1737
|
629
|
|
630 (defun try-expand-line (old)
|
|
631 "Try to complete the current line to an entire line in the buffer.
|
|
632 The argument OLD has to be nil the first call of this function, and t
|
|
633 for subsequent calls (for further possible completions of the same
|
|
634 string). It returns t if a new completion is found, nil otherwise."
|
|
635 (let ((expansion ())
|
|
636 (strip-prompt (and (get-buffer-process (current-buffer))
|
30645
4706d5e24141
(try-expand-line, try-expand-line-all-buffers): Only use comint-prompt-regexp
Miles Bader <miles@gnu.org>
diff
changeset
|
637 comint-use-prompt-regexp-instead-of-fields
|
4130
|
638 comint-prompt-regexp)))
|
1737
|
639 (if (not old)
|
|
640 (progn
|
|
641 (he-init-string (he-line-beg strip-prompt) (point))
|
4130
|
642 (set-marker he-search-loc he-string-beg)
|
1737
|
643 (setq he-search-bw t)))
|
|
644
|
|
645 (if (not (equal he-search-string ""))
|
|
646 (save-excursion
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
647 (save-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
648 (if hippie-expand-no-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
649 (widen))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
650 ;; Try looking backward unless inhibited.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
651 (if he-search-bw
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
652 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
653 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
654 (setq expansion (he-line-search he-search-string
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
655 strip-prompt t))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
656 (set-marker he-search-loc (point))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
657 (if (not expansion)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
658 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
659 (set-marker he-search-loc he-string-end)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
660 (setq he-search-bw ())))))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
661
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
662 (if (not expansion) ; Then look forward.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
663 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
664 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
665 (setq expansion (he-line-search he-search-string
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
666 strip-prompt nil))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
667 (set-marker he-search-loc (point)))))))
|
1737
|
668
|
|
669 (if (not expansion)
|
|
670 (progn
|
13207
|
671 (if old (he-reset-string))
|
1737
|
672 ())
|
|
673 (progn
|
|
674 (he-substitute-string expansion t)
|
|
675 t))))
|
|
676
|
|
677 (defun try-expand-line-all-buffers (old)
|
|
678 "Try to complete the current line, searching all other buffers.
|
|
679 The argument OLD has to be nil the first call of this function, and t
|
|
680 for subsequent calls (for further possible completions of the same
|
|
681 string). It returns t if a new completion is found, nil otherwise."
|
|
682 (let ((expansion ())
|
|
683 (strip-prompt (and (get-buffer-process (current-buffer))
|
30645
4706d5e24141
(try-expand-line, try-expand-line-all-buffers): Only use comint-prompt-regexp
Miles Bader <miles@gnu.org>
diff
changeset
|
684 comint-use-prompt-regexp-instead-of-fields
|
4130
|
685 comint-prompt-regexp))
|
13207
|
686 (buf (current-buffer))
|
|
687 (orig-case-fold-search case-fold-search))
|
1737
|
688 (if (not old)
|
|
689 (progn
|
|
690 (he-init-string (he-line-beg strip-prompt) (point))
|
4130
|
691 (setq he-search-bufs (buffer-list))
|
13207
|
692 (setq he-searched-n-bufs 0)
|
4130
|
693 (set-marker he-search-loc 1 (car he-search-bufs))))
|
1737
|
694
|
|
695 (if (not (equal he-search-string ""))
|
4130
|
696 (while (and he-search-bufs
|
13207
|
697 (not expansion)
|
|
698 (or (not hippie-expand-max-buffers)
|
|
699 (< he-searched-n-bufs hippie-expand-max-buffers)))
|
1737
|
700 (set-buffer (car he-search-bufs))
|
|
701 (if (and (not (eq (current-buffer) buf))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
702 (if hippie-expand-only-buffers
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
703 (he-buffer-member hippie-expand-only-buffers)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
704 (not (he-buffer-member hippie-expand-ignore-buffers))))
|
1737
|
705 (save-excursion
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
706 (save-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
707 (if hippie-expand-no-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
708 (widen))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
709 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
710 (setq strip-prompt (and (get-buffer-process (current-buffer))
|
30645
4706d5e24141
(try-expand-line, try-expand-line-all-buffers): Only use comint-prompt-regexp
Miles Bader <miles@gnu.org>
diff
changeset
|
711 comint-use-prompt-regexp-instead-of-fields
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
712 comint-prompt-regexp))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
713 (setq expansion
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
714 (let ((case-fold-search orig-case-fold-search))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
715 (he-line-search he-search-string
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
716 strip-prompt nil)))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
717 (set-marker he-search-loc (point))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
718 (if (not expansion)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
719 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
720 (setq he-search-bufs (cdr he-search-bufs))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
721 (setq he-searched-n-bufs (1+ he-searched-n-bufs))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
722 (set-marker he-search-loc 1 (car he-search-bufs))))))
|
13207
|
723 (setq he-search-bufs (cdr he-search-bufs))
|
|
724 (set-marker he-search-loc 1 (car he-search-bufs)))))
|
1737
|
725
|
|
726 (set-buffer buf)
|
|
727 (if (not expansion)
|
|
728 (progn
|
13207
|
729 (if old (he-reset-string))
|
1737
|
730 ())
|
|
731 (progn
|
|
732 (he-substitute-string expansion t)
|
|
733 t))))
|
|
734
|
|
735 (defun he-line-search (str strip-prompt reverse)
|
|
736 (let ((result ()))
|
|
737 (while (and (not result)
|
|
738 (if reverse
|
|
739 (re-search-backward
|
|
740 (he-line-search-regexp str strip-prompt)
|
|
741 nil t)
|
|
742 (re-search-forward
|
|
743 (he-line-search-regexp str strip-prompt)
|
|
744 nil t)))
|
26449
|
745 (setq result (buffer-substring-no-properties (match-end 1)
|
|
746 (match-end 0)))
|
13207
|
747 (if (he-string-member result he-tried-table t)
|
|
748 (setq result nil))) ; if already in table, ignore
|
1737
|
749 result))
|
|
750
|
|
751 (defun he-line-beg (strip-prompt)
|
|
752 (save-excursion
|
|
753 (if (re-search-backward (he-line-search-regexp "" strip-prompt)
|
|
754 (save-excursion (beginning-of-line)
|
|
755 (point)) t)
|
|
756 (match-beginning 2)
|
|
757 (point))))
|
|
758
|
|
759 (defun he-line-search-regexp (pat strip-prompt)
|
|
760 (if strip-prompt
|
4130
|
761 (concat "\\(" comint-prompt-regexp "\\|^\\s-*\\)\\("
|
1737
|
762 (regexp-quote pat)
|
|
763 "[^\n]*[^ \t\n]\\)")
|
|
764 (concat "^\\(\\s-*\\)\\("
|
|
765 (regexp-quote pat)
|
|
766 "[^\n]*[^ \t\n]\\)")))
|
|
767
|
4130
|
768 (defun try-expand-list (old)
|
|
769 "Try to complete the current beginning of a list.
|
|
770 The argument OLD has to be nil the first call of this function, and t
|
|
771 for subsequent calls (for further possible completions of the same
|
|
772 string). It returns t if a new completion is found, nil otherwise."
|
|
773 (let ((expansion ()))
|
|
774 (if (not old)
|
|
775 (progn
|
|
776 (he-init-string (he-list-beg) (point))
|
|
777 (set-marker he-search-loc he-string-beg)
|
|
778 (setq he-search-bw t)))
|
|
779
|
|
780 (if (not (equal he-search-string ""))
|
|
781 (save-excursion
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
782 (save-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
783 (if hippie-expand-no-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
784 (widen))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
785 ;; Try looking backward unless inhibited.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
786 (if he-search-bw
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
787 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
788 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
789 (setq expansion (he-list-search he-search-string t))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
790 (set-marker he-search-loc (point))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
791 (if (not expansion)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
792 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
793 (set-marker he-search-loc he-string-end)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
794 (setq he-search-bw ())))))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
795
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
796 (if (not expansion) ; Then look forward.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
797 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
798 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
799 (setq expansion (he-list-search he-search-string nil))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
800 (set-marker he-search-loc (point)))))))
|
4130
|
801
|
|
802 (if (not expansion)
|
|
803 (progn
|
|
804 (if old (he-reset-string))
|
|
805 ())
|
|
806 (progn
|
|
807 (he-substitute-string expansion t)
|
|
808 t))))
|
|
809
|
|
810 (defun try-expand-list-all-buffers (old)
|
|
811 "Try to complete the current list, searching all other buffers.
|
|
812 The argument OLD has to be nil the first call of this function, and t
|
|
813 for subsequent calls (for further possible completions of the same
|
|
814 string). It returns t if a new completion is found, nil otherwise."
|
|
815 (let ((expansion ())
|
13207
|
816 (buf (current-buffer))
|
|
817 (orig-case-fold-search case-fold-search))
|
4130
|
818 (if (not old)
|
|
819 (progn
|
|
820 (he-init-string (he-list-beg) (point))
|
|
821 (setq he-search-bufs (buffer-list))
|
13207
|
822 (setq he-searched-n-bufs 0)
|
4130
|
823 (set-marker he-search-loc 1 (car he-search-bufs))))
|
|
824
|
|
825 (if (not (equal he-search-string ""))
|
|
826 (while (and he-search-bufs
|
13207
|
827 (not expansion)
|
|
828 (or (not hippie-expand-max-buffers)
|
|
829 (< he-searched-n-bufs hippie-expand-max-buffers)))
|
4130
|
830 (set-buffer (car he-search-bufs))
|
|
831 (if (and (not (eq (current-buffer) buf))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
832 (if hippie-expand-only-buffers
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
833 (he-buffer-member hippie-expand-only-buffers)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
834 (not (he-buffer-member hippie-expand-ignore-buffers))))
|
4130
|
835 (save-excursion
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
836 (save-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
837 (if hippie-expand-no-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
838 (widen))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
839 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
840 (setq expansion
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
841 (let ((case-fold-search orig-case-fold-search))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
842 (he-list-search he-search-string nil)))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
843 (set-marker he-search-loc (point))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
844 (if (not expansion)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
845 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
846 (setq he-search-bufs (cdr he-search-bufs))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
847 (setq he-searched-n-bufs (1+ he-searched-n-bufs))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
848 (set-marker he-search-loc 1 (car he-search-bufs))))))
|
13207
|
849 (setq he-search-bufs (cdr he-search-bufs))
|
|
850 (set-marker he-search-loc 1 (car he-search-bufs)))))
|
4130
|
851
|
|
852 (set-buffer buf)
|
|
853 (if (not expansion)
|
|
854 (progn
|
13207
|
855 (if old (he-reset-string))
|
4130
|
856 ())
|
|
857 (progn
|
|
858 (he-substitute-string expansion t)
|
|
859 t))))
|
|
860
|
|
861 (defun he-list-search (str reverse)
|
|
862 (let ((result ())
|
13207
|
863 beg pos err)
|
4130
|
864 (while (and (not result)
|
|
865 (if reverse
|
|
866 (search-backward str nil t)
|
|
867 (search-forward str nil t)))
|
|
868 (setq pos (point))
|
|
869 (setq beg (match-beginning 0))
|
|
870 (goto-char beg)
|
|
871 (setq err ())
|
|
872 (condition-case ()
|
13207
|
873 (forward-list 1)
|
|
874 (error (setq err t)))
|
5296
|
875 (if (and reverse
|
13207
|
876 (> (point) he-string-beg))
|
|
877 (setq err t))
|
4130
|
878 (if (not err)
|
13207
|
879 (progn
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
880 (setq result (buffer-substring-no-properties beg (point)))
|
13207
|
881 (if (he-string-member result he-tried-table t)
|
|
882 (setq result nil)))) ; if already in table, ignore
|
4130
|
883 (goto-char pos))
|
|
884 result))
|
|
885
|
|
886 (defun he-list-beg ()
|
|
887 (save-excursion
|
|
888 (condition-case ()
|
13207
|
889 (backward-up-list 1)
|
4130
|
890 (error ()))
|
|
891 (point)))
|
|
892
|
1737
|
893 (defun try-expand-all-abbrevs (old)
|
|
894 "Try to expand word before point according to all abbrev tables.
|
|
895 The argument OLD has to be nil the first call of this function, and t
|
|
896 for subsequent calls (for further possible expansions of the same
|
|
897 string). It returns t if a new expansion is found, nil otherwise."
|
|
898 (if (not old)
|
|
899 (progn
|
|
900 (he-init-string (he-dabbrev-beg) (point))
|
|
901 (setq he-expand-list
|
|
902 (and (not (equal he-search-string ""))
|
|
903 (mapcar (function (lambda (sym)
|
13207
|
904 (if (and (boundp sym) (vectorp (eval sym)))
|
|
905 (abbrev-expansion (downcase he-search-string)
|
|
906 (eval sym)))))
|
1737
|
907 (append '(local-abbrev-table
|
|
908 global-abbrev-table)
|
|
909 abbrev-table-name-list))))))
|
|
910 (while (and he-expand-list
|
|
911 (or (not (car he-expand-list))
|
13207
|
912 (he-string-member (car he-expand-list) he-tried-table t)))
|
1737
|
913 (setq he-expand-list (cdr he-expand-list)))
|
|
914 (if (null he-expand-list)
|
|
915 (progn
|
13207
|
916 (if old (he-reset-string))
|
1737
|
917 ())
|
|
918 (progn
|
4130
|
919 (he-substitute-string (car he-expand-list) t)
|
1737
|
920 (setq he-expand-list (cdr he-expand-list))
|
|
921 t)))
|
|
922
|
|
923 (defun try-expand-dabbrev (old)
|
|
924 "Try to expand word \"dynamically\", searching the current buffer.
|
|
925 The argument OLD has to be nil the first call of this function, and t
|
|
926 for subsequent calls (for further possible expansions of the same
|
|
927 string). It returns t if a new expansion is found, nil otherwise."
|
|
928 (let ((expansion ()))
|
|
929 (if (not old)
|
|
930 (progn
|
|
931 (he-init-string (he-dabbrev-beg) (point))
|
4130
|
932 (set-marker he-search-loc he-string-beg)
|
1737
|
933 (setq he-search-bw t)))
|
|
934
|
|
935 (if (not (equal he-search-string ""))
|
|
936 (save-excursion
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
937 (save-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
938 (if hippie-expand-no-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
939 (widen))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
940 ;; Try looking backward unless inhibited.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
941 (if he-search-bw
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
942 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
943 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
944 (setq expansion (he-dabbrev-search he-search-string t))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
945 (set-marker he-search-loc (point))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
946 (if (not expansion)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
947 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
948 (set-marker he-search-loc he-string-end)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
949 (setq he-search-bw ())))))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
950
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
951 (if (not expansion) ; Then look forward.
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
952 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
953 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
954 (setq expansion (he-dabbrev-search he-search-string nil))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
955 (set-marker he-search-loc (point)))))))
|
1737
|
956
|
|
957 (if (not expansion)
|
|
958 (progn
|
13207
|
959 (if old (he-reset-string))
|
1737
|
960 ())
|
|
961 (progn
|
|
962 (he-substitute-string expansion t)
|
|
963 t))))
|
|
964
|
|
965 (defun try-expand-dabbrev-all-buffers (old)
|
|
966 "Tries to expand word \"dynamically\", searching all other buffers.
|
|
967 The argument OLD has to be nil the first call of this function, and t
|
|
968 for subsequent calls (for further possible expansions of the same
|
|
969 string). It returns t if a new expansion is found, nil otherwise."
|
|
970 (let ((expansion ())
|
13207
|
971 (buf (current-buffer))
|
|
972 (orig-case-fold-search case-fold-search))
|
1737
|
973 (if (not old)
|
|
974 (progn
|
|
975 (he-init-string (he-dabbrev-beg) (point))
|
4130
|
976 (setq he-search-bufs (buffer-list))
|
13207
|
977 (setq he-searched-n-bufs 0)
|
4130
|
978 (set-marker he-search-loc 1 (car he-search-bufs))))
|
1737
|
979
|
|
980 (if (not (equal he-search-string ""))
|
4130
|
981 (while (and he-search-bufs
|
13207
|
982 (not expansion)
|
|
983 (or (not hippie-expand-max-buffers)
|
|
984 (< he-searched-n-bufs hippie-expand-max-buffers)))
|
1737
|
985 (set-buffer (car he-search-bufs))
|
|
986 (if (and (not (eq (current-buffer) buf))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
987 (if hippie-expand-only-buffers
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
988 (he-buffer-member hippie-expand-only-buffers)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
989 (not (he-buffer-member hippie-expand-ignore-buffers))))
|
1737
|
990 (save-excursion
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
991 (save-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
992 (if hippie-expand-no-restriction
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
993 (widen))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
994 (goto-char he-search-loc)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
995 (setq expansion
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
996 (let ((case-fold-search orig-case-fold-search))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
997 (he-dabbrev-search he-search-string nil)))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
998 (set-marker he-search-loc (point))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
999 (if (not expansion)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1000 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1001 (setq he-search-bufs (cdr he-search-bufs))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1002 (setq he-searched-n-bufs (1+ he-searched-n-bufs))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1003 (set-marker he-search-loc 1 (car he-search-bufs))))))
|
13207
|
1004 (setq he-search-bufs (cdr he-search-bufs))
|
|
1005 (set-marker he-search-loc 1 (car he-search-bufs)))))
|
1737
|
1006
|
|
1007 (set-buffer buf)
|
|
1008 (if (not expansion)
|
|
1009 (progn
|
13207
|
1010 (if old (he-reset-string))
|
|
1011 ())
|
|
1012 (progn
|
|
1013 (he-substitute-string expansion t)
|
|
1014 t))))
|
|
1015
|
|
1016 ;; Thanks go to Jeff Dairiki <dairiki@faraday.apl.washington.edu> who
|
|
1017 ;; suggested this one.
|
|
1018 (defun try-expand-dabbrev-visible (old)
|
|
1019 "Try to expand word \"dynamically\", searching visible window parts.
|
|
1020 The argument OLD has to be nil the first call of this function, and t
|
|
1021 for subsequent calls (for further possible expansions of the same
|
|
1022 string). It returns t if a new expansion is found, nil otherwise."
|
|
1023 (let ((expansion ())
|
|
1024 (buf (current-buffer))
|
|
1025 (flag (if (frame-visible-p (window-frame (selected-window)))
|
|
1026 'visible t)))
|
|
1027 (if (not old)
|
|
1028 (progn
|
|
1029 (he-init-string (he-dabbrev-beg) (point))
|
|
1030 (setq he-search-window (selected-window))
|
|
1031 (set-marker he-search-loc
|
|
1032 (window-start he-search-window)
|
|
1033 (window-buffer he-search-window))))
|
|
1034
|
|
1035 (while (and (not (equal he-search-string ""))
|
|
1036 (marker-position he-search-loc)
|
|
1037 (not expansion))
|
|
1038 (save-excursion
|
|
1039 (set-buffer (marker-buffer he-search-loc))
|
|
1040 (goto-char he-search-loc)
|
|
1041 (setq expansion (he-dabbrev-search he-search-string ()
|
|
1042 (window-end he-search-window)))
|
|
1043 (if (and expansion
|
|
1044 (eq (marker-buffer he-string-beg) (current-buffer))
|
|
1045 (eq (marker-position he-string-beg) (match-beginning 0)))
|
|
1046 (setq expansion (he-dabbrev-search he-search-string ()
|
|
1047 (window-end he-search-window))))
|
|
1048 (set-marker he-search-loc (point) (current-buffer)))
|
|
1049 (if (not expansion)
|
|
1050 (progn
|
|
1051 (setq he-search-window (next-window he-search-window nil flag))
|
|
1052 (if (eq he-search-window (selected-window))
|
|
1053 (set-marker he-search-loc nil)
|
|
1054 (set-marker he-search-loc (window-start he-search-window)
|
|
1055 (window-buffer he-search-window))))))
|
|
1056
|
|
1057 (set-buffer buf)
|
|
1058 (if (not expansion)
|
|
1059 (progn
|
|
1060 (if old (he-reset-string))
|
1737
|
1061 ())
|
|
1062 (progn
|
|
1063 (he-substitute-string expansion t)
|
|
1064 t))))
|
|
1065
|
13207
|
1066 (defun he-dabbrev-search (pattern &optional reverse limit)
|
|
1067 (let ((result ())
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1068 (regpat (cond ((not hippie-expand-dabbrev-as-symbol)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1069 (concat "\\<" (regexp-quote pattern) "\\sw+"))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1070 ((eq (char-syntax (aref pattern 0)) ?_)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1071 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+"))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1072 (t
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1073 (concat "\\<" (regexp-quote pattern)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1074 "\\(\\sw\\|\\s_\\)+")))))
|
1737
|
1075 (while (and (not result)
|
|
1076 (if reverse
|
13207
|
1077 (re-search-backward regpat limit t)
|
|
1078 (re-search-forward regpat limit t)))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1079 (setq result (buffer-substring-no-properties (match-beginning 0)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1080 (match-end 0)))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1081 (if (or (and hippie-expand-dabbrev-as-symbol
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1082 (> (match-beginning 0) (point-min))
|
13207
|
1083 (memq (char-syntax (char-after (1- (match-beginning 0))))
|
|
1084 '(?_ ?w)))
|
|
1085 (he-string-member result he-tried-table t))
|
|
1086 (setq result nil))) ; ignore if bad prefix or already in table
|
1737
|
1087 result))
|
|
1088
|
|
1089 (defun he-dabbrev-beg ()
|
13207
|
1090 (let ((op (point)))
|
|
1091 (save-excursion
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1092 (if hippie-expand-dabbrev-skip-space
|
13207
|
1093 (skip-syntax-backward ". "))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1094 (if (= (skip-syntax-backward (if hippie-expand-dabbrev-as-symbol
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1095 "w_" "w"))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1096 0)
|
13207
|
1097 op
|
|
1098 (point)))))
|
|
1099
|
|
1100 (defun try-expand-dabbrev-from-kill (old)
|
|
1101 "Try to expand word \"dynamically\", searching the kill ring.
|
|
1102 The argument OLD has to be nil the first call of this function, and t
|
|
1103 for subsequent calls (for further possible completions of the same
|
|
1104 string). It returns t if a new completion is found, nil otherwise."
|
|
1105 (let ((expansion ()))
|
|
1106 (if (not old)
|
|
1107 (progn
|
|
1108 (he-init-string (he-dabbrev-beg) (point))
|
|
1109 (setq he-expand-list
|
|
1110 (if (not (equal he-search-string ""))
|
|
1111 kill-ring))
|
|
1112 (setq he-search-loc2 0)))
|
|
1113 (if (not (equal he-search-string ""))
|
|
1114 (setq expansion (he-dabbrev-kill-search he-search-string)))
|
|
1115 (if (not expansion)
|
|
1116 (progn
|
|
1117 (if old (he-reset-string))
|
|
1118 ())
|
|
1119 (progn
|
|
1120 (he-substitute-string expansion t)
|
|
1121 t))))
|
|
1122
|
|
1123 (defun he-dabbrev-kill-search (pattern)
|
|
1124 (let ((result ())
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1125 (regpat (cond ((not hippie-expand-dabbrev-as-symbol)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1126 (concat "\\<" (regexp-quote pattern) "\\sw+"))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1127 ((eq (char-syntax (aref pattern 0)) ?_)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1128 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+"))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1129 (t
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1130 (concat "\\<" (regexp-quote pattern)
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1131 "\\(\\sw\\|\\s_\\)+"))))
|
13207
|
1132 (killstr (car he-expand-list)))
|
|
1133 (while (and (not result)
|
|
1134 he-expand-list)
|
|
1135 (while (and (not result)
|
|
1136 (string-match regpat killstr he-search-loc2))
|
|
1137 (setq result (substring killstr (match-beginning 0) (match-end 0)))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1138 (set-text-properties 0 (length result) () result)
|
13207
|
1139 (setq he-search-loc2 (1+ (match-beginning 0)))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1140 (if (or (and hippie-expand-dabbrev-as-symbol
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1141 (> (match-beginning 0) 0)
|
13207
|
1142 (memq (char-syntax (aref killstr (1- (match-beginning 0))))
|
|
1143 '(?_ ?w)))
|
|
1144 (he-string-member result he-tried-table t))
|
|
1145 (setq result nil))) ; ignore if bad prefix or already in table
|
|
1146 (if (and (not result)
|
|
1147 he-expand-list)
|
|
1148 (progn
|
|
1149 (setq he-expand-list (cdr he-expand-list))
|
|
1150 (setq killstr (car he-expand-list))
|
|
1151 (setq he-search-loc2 0))))
|
|
1152 result))
|
|
1153
|
|
1154 (defun try-expand-whole-kill (old)
|
|
1155 "Try to complete text with something from the kill ring.
|
|
1156 The argument OLD has to be nil the first call of this function, and t
|
|
1157 for subsequent calls (for further possible completions of the same
|
|
1158 string). It returns t if a new completion is found, nil otherwise."
|
|
1159 (let ((expansion ()))
|
|
1160 (if (not old)
|
|
1161 (progn
|
|
1162 (he-init-string (he-kill-beg) (point))
|
|
1163 (if (not (he-string-member he-search-string he-tried-table))
|
|
1164 (setq he-tried-table (cons he-search-string he-tried-table)))
|
|
1165 (setq he-expand-list
|
|
1166 (if (not (equal he-search-string ""))
|
|
1167 kill-ring))
|
|
1168 (setq he-search-loc2 ())))
|
|
1169 (if (not (equal he-search-string ""))
|
|
1170 (setq expansion (he-whole-kill-search he-search-string)))
|
|
1171 (if (not expansion)
|
|
1172 (progn
|
|
1173 (if old (he-reset-string))
|
|
1174 ())
|
|
1175 (progn
|
|
1176 (he-substitute-string expansion)
|
|
1177 t))))
|
|
1178
|
|
1179 (defun he-whole-kill-search (str)
|
|
1180 (let ((case-fold-search ())
|
|
1181 (result ())
|
|
1182 (str (regexp-quote str))
|
|
1183 (killstr (car he-expand-list))
|
|
1184 (pos -1))
|
|
1185 (while (and (not result)
|
|
1186 he-expand-list)
|
|
1187 (if (not he-search-loc2)
|
|
1188 (while (setq pos (string-match str killstr (1+ pos)))
|
|
1189 (setq he-search-loc2 (cons pos he-search-loc2))))
|
|
1190 (while (and (not result)
|
|
1191 he-search-loc2)
|
|
1192 (setq pos (car he-search-loc2))
|
|
1193 (setq he-search-loc2 (cdr he-search-loc2))
|
|
1194 (save-excursion
|
|
1195 (goto-char he-string-beg)
|
|
1196 (if (and (>= (- (point) pos) (point-min)) ; avoid some string GC
|
|
1197 (eq (char-after (- (point) pos)) (aref killstr 0))
|
|
1198 (search-backward (substring killstr 0 pos)
|
|
1199 (- (point) pos) t))
|
21131
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1200 (progn
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1201 (setq result (substring killstr pos))
|
e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1202 (set-text-properties 0 (length result) () result))))
|
13207
|
1203 (if (and result
|
|
1204 (he-string-member result he-tried-table))
|
|
1205 (setq result nil))) ; ignore if already in table
|
|
1206 (if (and (not result)
|
|
1207 he-expand-list)
|
|
1208 (progn
|
|
1209 (setq he-expand-list (cdr he-expand-list))
|
|
1210 (setq killstr (car he-expand-list))
|
|
1211 (setq pos -1))))
|
|
1212 result))
|
|
1213
|
|
1214 (defun he-kill-beg ()
|
|
1215 (let ((op (point)))
|
|
1216 (save-excursion
|
|
1217 (skip-syntax-backward "^w_")
|
|
1218 (if (= (skip-syntax-backward "w_") 0)
|
|
1219 op
|
|
1220 (point)))))
|
|
1221
|
1737
|
1222
|
4130
|
1223 (provide 'hippie-exp)
|
|
1224
|
|
1225 ;;; hippie-exp.el ends here
|