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