annotate lisp/hippie-exp.el @ 5086:6e9634463e93

(Ftext_property_not_all): Swap t and nil values in the case where there are no intervals. (Fprevious_single_property_change, Fprevious_property_change) Extra arg LIMIT. Return value was off by 1. (Fnext_single_property_change, Fnext_property_change): Extra arg LIMIT. (Fnext_single_property_change): Require at least 2 args.
author Richard M. Stallman <rms@gnu.org>
date Sat, 20 Nov 1993 09:44:27 +0000
parents e5aee6a3bb75
children 81b21ef5290d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
1 ;;; hippie-exp.el --- expand text trying various ways to find its expansion.
2230
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1737
diff changeset
2
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1737
diff changeset
3 ;; Author: Anders Holst <aho@sans.kth.se>
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
4 ;; Last change: 22 June 1993
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
5 ;; Version: 1.2
2230
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1737
diff changeset
6 ;; Keywords: extensions
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1737
diff changeset
7
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Copyright (C) 1992 Free Software Foundation, Inc.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;;
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2230
diff changeset
26 ;;; Commentary:
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; `hippie-expand' is a single function for a lot of different kinds
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; of completions and expansions. Called repeatedly it tries all
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; possible completions in succession.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; Which kinds of completions to try, and in which order, is
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; determined by the contents of `hippie-expand-try-functions-list'.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; Much customization of `hippie-expand' can be made by changing the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; order of, removing, or inserting new functions in this list.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; Given a positive numeric argument, `hippie-expand' jumps directly
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; ARG functions forward in this list. Given some other argument
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; (a negative argument or just Ctrl-U) it undoes the tried
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; completion.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; If the variable `hippie-expand-verbose' is non-nil, `hippie-expand'
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; outputs in a message which try-function in the list that is used
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; currently (ie. was used currently and will be tried first the next
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; time).
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
43 ;; The variable `hippie-expand-max-buffers' determines in how many
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
44 ;; buffers, apart from the current, to search for expansions in. It
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
45 ;; is used by the try-functions named "-all-buffers".
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; See also the macro `make-hippie-expand-function' below.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; A short description of the current try-functions in this file:
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; `try-complete-file-name' : very convenient to have in any buffer,
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; and not just in the minibuffer or (some) shell-mode. It goes
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; through all possible completions instead of just completing as
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; much as is unique.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; `try-complete-file-name-partially' : To insert in the list just
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; before `try-complete-file-name' for those who want first to get
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; a file name completed only as many characters as is unique.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; `try-expand-all-abbrevs' : can be removed if you don't use abbrevs.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; Otherwise it looks through all abbrev-tables, starting with
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; the local followed by the global.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; `try-expand-line' : Searches the buffer for an entire line that
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; begins exactly as the current line. Convenient sometimes, for
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; example as a substitute for (or complement to) the history
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
62 ;; list in shell-like buffers. At other times, only confusing.
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; `try-expand-line-all-buffers' : Like `try-expand-line' but searches
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; in all buffers (except the current). (This may be a little
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
65 ;; slow, don't use it unless you are really fond of `hippie-expand'.)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
66 ;; `try-expand-list' : Tries to expand the text back to the nearest
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
67 ;; open delimiter, to a whole list from the buffer. Convenient for
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
68 ;; example when writing lisp or TeX.
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
69 ;; `try-expand-list-all-buffers' : Like `try-expand-list' but searches
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
70 ;; in all buffers (except the current).
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; `try-expand-dabbrev' : works exactly as dabbrev-expand (but of
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; course in a way compatible with the other try-functions).
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; `try-expand-dabbrev-all-buffers' : perhaps the most useful of them,
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; like `dabbrev-expand' but searches all Emacs buffers (except the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; current) for matching words. (No, I don't find this one
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; particularly slow.)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; `try-complete-lisp-symbol' : like `lisp-complete-symbol', but goes
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; through all possibilities instead of completing what is unique.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; Might be tedious (usually a lot of possible completions) and
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; since its function is much like `lisp-complete-symbol', which
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; already has a key of its own, you might want to remove this.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; `try-complete-lisp-symbol-partially' : To insert in the list just
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; before `try-complete-lisp-symbol' for those who first want to get
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
84 ;; completion of what is unique in the name.
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
85 ;;
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
86 ;; Not all of the above functions are by default in
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
87 ;; `hippie-expand-try-functions-list'. This variable is better set
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
88 ;; in ".emacs" to make `hippie-expand' behave maximally convenient
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
89 ;; according to personal taste. Also, instead of loading the
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
90 ;; variable with all kinds of try-functions above, it might be an
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
91 ;; idea to use `make-hippie-expand-function' to construct different
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
92 ;; `hippie-expand'-like functions, with different try-lists and bound
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
93 ;; to different keys. It is also possible to make
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
94 ;; `hippie-expand-try-functions-list' a buffer local variable, and
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
95 ;; let it depend on the mode (by setting it in the mode-hooks).
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; To write new try-functions, consider the following:
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; Each try-function takes one argument OLD which is nil the first
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; time the function is called and true in succeeding calls for the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; same string to complete. The first time the function has to
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; extract the string before point to complete, and substitute the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; first completion alternative for it. On following calls it has to
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; substitute the next possible completion for the last tried string.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; The try-function is to return t as long as it finds new
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; possible completions. When there are no more alternatives it has
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; to restore the text before point to its original contents, and
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;; return nil (don't beep or message or anything).
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; The try-function can (should) use the following functions:
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;; `he-init-string' : Initializes the text to substitute to the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; contents of the region BEGIN to END. Also sets the variable
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;; `he-search-string' to the text to expand.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; `he-substitute-string' : substitutes STR into the region
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;; initialized with `he-init-string'. (An optional second argument
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; TRANS-CASE non-nil, means transfer of case from the abbreviation
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;; to the expansion is ok if that is enabled in the buffer.)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;; `he-reset-string' : Resets the initialized region to its original
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;; contents.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; There is also a variable: `he-tried-table' which is meant to contain
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; all tried expansions so far. The try-function can check this
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; variable to see whether an expansion has already been tried
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;; (hint: `he-string-member'), and add its own tried expansions to it.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;;
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
123 ;; Known bugs
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;;
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; It may happen that some completion suggestion occurs twice, in
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; spite of the use of `he-tried-table' to prevent that. This is
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; because different try-functions may try to complete different
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; lengths of text, and thus put different amounts of the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; text in `he-try-table'. Anyway this seems to occur seldom enough not
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; to be too disturbing. Also it should NOT bee possible for the
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; opposite situation to occur, that `hippie-expand' misses some
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; suggestion because it thinks it has already tried it.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;;
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
134 ;; Acknowledgement
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;;
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; I want to thank Mikael Djurfeldt in discussions with whom the idea
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; of this function took form.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;; I am also grateful to all those who have given me suggestions on
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;; how to improve it.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;;
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2230
diff changeset
142 ;;; Code:
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (defvar he-num -1)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
146 (defvar he-string-beg (make-marker))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
148 (defvar he-string-end (make-marker))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (defvar he-search-string ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (defvar he-expand-list ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defvar he-tried-table ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
156 (defvar he-search-loc (make-marker))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (defvar he-search-bw ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (defvar he-search-bufs ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
162 (defvar he-searched-n-bufs ())
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
163
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
164 ;;;###autoload
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (defvar hippie-expand-try-functions-list '(try-complete-file-name
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 try-expand-all-abbrevs
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 try-expand-line
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 try-expand-dabbrev
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 try-expand-dabbrev-all-buffers
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 try-complete-lisp-symbol)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 "The list of expansion functions tried in order by `hippie-expand'.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 To change the behavior of `hippie-expand', remove, change the order of,
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 or insert functions in this list.")
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
175 ;;;###autoload
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (defvar hippie-expand-verbose t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 "*Non-nil makes `hippie-expand' output which function it is trying.")
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
179 ;;;###autoload
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
180 (defvar hippie-expand-max-buffers ()
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
181 "*The maximum number of buffers (apart from the current) searched.
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
182 If nil, all buffers are searched.")
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
183
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
184 ;;;###autoload
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (defun hippie-expand (arg)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 "Try to expand text before point, using multiple methods.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 The expansion functions in `hippie-expand-try-functions-list' are
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 tried in order, until a possible expansion is found. Repeated
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 application of `hippie-expand' inserts successively possible
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 expansions.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 With a positive numeric argument, jumps directly to the ARG next
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 function in this list. With a negative argument or just \\[universal-argument],
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 undoes the expansion."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (interactive "P")
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (if (or (not arg)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (and (integerp arg) (> arg 0)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (let ((first (or (= he-num -1)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (not (equal this-command last-command)))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (if first
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (setq he-num -1)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (setq he-tried-table nil)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (if arg
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (if (not first) (he-reset-string))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (setq arg 0))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (let ((i (max (+ he-num arg) 0)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (while (not (or (>= i (length hippie-expand-try-functions-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (apply (nth i hippie-expand-try-functions-list)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (list (= he-num i)))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (setq i (1+ i)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (setq he-num i))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (if (>= he-num (length hippie-expand-try-functions-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (setq he-num -1)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (if first
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (message "No expansion found")
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (message "No further expansions found"))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (ding))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
219 (if (and hippie-expand-verbose
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
220 (not (window-minibuffer-p (selected-window))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (message (concat "Using "
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (prin1-to-string (nth he-num
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 hippie-expand-try-functions-list)))))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (if (>= he-num 0)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (setq he-num -1)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (he-reset-string)
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
228 (if (and hippie-expand-verbose
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
229 (not (window-minibuffer-p (selected-window))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (message "Undoing expansions"))))))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
231
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 ;; Initializes the region to expand (to between BEG and END).
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (defun he-init-string (beg end)
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
234 (set-marker he-string-beg beg)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
235 (set-marker he-string-end end)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (setq he-search-string (buffer-substring beg end)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ;; Resets the expanded region to its original contents.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (defun he-reset-string ()
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
240 (let ((newpos (point-marker)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
241 (delete-region he-string-beg he-string-end)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
242 (goto-char he-string-beg)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
243 (insert he-search-string)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
244 (set-marker he-string-end (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
245 (if (= newpos he-string-beg)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
246 (goto-char he-string-end)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
247 (goto-char newpos))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 ;; Substitutes an expansion STR into the correct region (the region
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ;; initialized with `he-init-string').
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 ;; An optional argument TRANS-CASE means that it is ok to transfer case
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 ;; from the abbreviation to the expansion if that is possible, and is
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 ;; enabled in the buffer.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (defun he-substitute-string (str &optional trans-case)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (let ((trans-case (and trans-case
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 case-replace
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 case-fold-search
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
258 (he-transfer-case-ok str he-search-string)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
259 (newpos (point-marker)))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (he-reset-string)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (goto-char he-string-beg)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (search-forward he-search-string)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (replace-match (if trans-case (downcase str) str)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (not trans-case)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 'literal)
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
266 (set-marker he-string-end (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
267 (if (= newpos he-string-beg)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
268 (goto-char he-string-end)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
269 (goto-char newpos))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (defun he-ordinary-case-p (str)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (or (string= str (downcase str))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (string= str (upcase str))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (string= str (capitalize str))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (defun he-transfer-case-ok (to-str from-str)
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
277 (and (not (string= from-str (substring to-str 0 (min (length from-str)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
278 (length to-str)))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 ;; otherwise transfer is not needed (and this also solves
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 ;; some obscure situations)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (he-ordinary-case-p to-str)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 ;; otherwise case may be significant
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (he-ordinary-case-p from-str)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 ;; otherwise replace-match wont know what to do
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 ))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 ;; Check if STR is a member of LST.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 ;; Ignore case if `case-replace' and `case-fold-search' are both t.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (defun he-string-member (str lst)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (while (and lst
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (not
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (if (and case-fold-search case-replace)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (string= (downcase (car lst)) (downcase str))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (string= (car lst) str))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (setq lst (cdr lst)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 lst)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 ;; For the real hippie-expand enthusiast: A macro that makes it
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 ;; possible to use many functions like hippie-expand, but with
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 ;; different try-functions-lists.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 ;; Usage is for example:
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ;; (fset 'my-complete-file (make-hippie-expand-function
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 ;; '(try-complete-file-name-partially
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 ;; try-complete-file-name)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 ;; (fset 'my-complete-line (make-hippie-expand-function
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 ;; '(try-expand-line
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;; try-expand-line-all-buffers)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ;;
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
309 ;;;###autoload
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (defmacro make-hippie-expand-function (try-list &optional verbose)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 "Construct a function similar to `hippie-expand'.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 Make it use the expansion functions in TRY-LIST. An optional second
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 argument VERBOSE non-nil makes the function verbose."
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
314 (` (function (lambda (arg)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (, (concat
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 "Try to expand text before point, using the following functions: \n"
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (mapconcat 'prin1-to-string (eval try-list) ", ")))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (interactive "P")
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (let ((hippie-expand-try-functions-list (, try-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (hippie-expand-verbose (, verbose)))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
321 (hippie-expand arg))))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 ;;; Here follows the try-functions and their requisites:
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (defun try-complete-file-name (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 "Try to complete text as a file name.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 The argument OLD has to be nil the first call of this function, and t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 for subsequent calls (for further possible completions of the same
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 string). It returns t if a new completion is found, nil otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (he-init-string (he-file-name-beg) (point))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (let ((name-part (file-name-nondirectory he-search-string))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (dir-part (expand-file-name (or (file-name-directory
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 he-search-string) ""))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (if (not (he-string-member name-part he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (setq he-tried-table (cons name-part he-tried-table)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (if (and (not (equal he-search-string ""))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (file-directory-p dir-part))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (setq he-expand-list (sort (file-name-all-completions
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 name-part
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 dir-part)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 'string-lessp))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (setq he-expand-list ())))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (while (and he-expand-list
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (he-string-member (car he-expand-list) he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (setq he-expand-list (cdr he-expand-list)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (if (null he-expand-list)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
352 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (let ((filename (concat (file-name-directory he-search-string)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (car he-expand-list))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (he-substitute-string filename)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (setq he-tried-table (cons (car he-expand-list) he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (setq he-expand-list (cdr he-expand-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 t)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (defun try-complete-file-name-partially (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 "Try to complete text as a file name, as many characters as unique.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 The argument OLD has to be nil the first call of this function. It
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 returns t if a unique, possibly partial, completion is found, nil
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (let ((expansion ()))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (he-init-string (he-file-name-beg) (point))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (let ((name-part (file-name-nondirectory he-search-string))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (dir-part (expand-file-name (or (file-name-directory
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 he-search-string) ""))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (if (and (not (equal he-search-string ""))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (file-directory-p dir-part))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq expansion (file-name-completion name-part
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 dir-part)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (if (or (eq expansion t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (string= expansion name-part))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (setq expansion ())))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
383 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (let ((filename (concat (file-name-directory he-search-string)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 expansion)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (he-substitute-string filename)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (setq he-tried-table (cons expansion he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 t))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (defun he-file-name-beg ()
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (let ((skips "-a-zA-Z0-9_./~^#$"))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (save-excursion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (skip-chars-backward skips)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (point))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (defun try-complete-lisp-symbol (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 "Try to complete word as an Emacs Lisp symbol.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 The argument OLD has to be nil the first call of this function, and t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 for subsequent calls (for further possible completions of the same
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 string). It returns t if a new completion is found, nil otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (he-init-string (he-lisp-symbol-beg) (point))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (if (not (he-string-member he-search-string he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (setq he-tried-table (cons he-search-string he-tried-table)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (setq he-expand-list
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (and (not (equal he-search-string ""))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (sort (all-completions he-search-string obarray
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (function (lambda (sym)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (or (boundp sym)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (fboundp sym)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (symbol-plist sym)))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 'string-lessp)))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (while (and he-expand-list
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (he-string-member (car he-expand-list) he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (setq he-expand-list (cdr he-expand-list)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (if (null he-expand-list)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
420 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (he-substitute-string (car he-expand-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (setq he-tried-table (cons (car he-expand-list) he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (setq he-expand-list (cdr he-expand-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 t)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (defun try-complete-lisp-symbol-partially (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 "Try to complete as an Emacs Lisp symbol, as many characters as unique.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 The argument OLD has to be nil the first call of this function. It
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 returns t if a unique, possibly partial, completion is found, nil
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (let ((expansion ()))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (he-init-string (he-lisp-symbol-beg) (point))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (if (not (string= he-search-string ""))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (setq expansion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (try-completion he-search-string obarray
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (function (lambda (sym)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (or (boundp sym)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (fboundp sym)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (symbol-plist sym)))))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (if (or (eq expansion t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (string= expansion he-search-string))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (setq expansion ()))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
450 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (he-substitute-string expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (setq he-tried-table (cons expansion he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 t))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (defun he-lisp-symbol-beg ()
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (let ((skips "-a-zA-Z0-9_."))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (save-excursion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (skip-chars-backward skips)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (point))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (defun try-expand-line (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 "Try to complete the current line to an entire line in the buffer.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 The argument OLD has to be nil the first call of this function, and t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 for subsequent calls (for further possible completions of the same
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 string). It returns t if a new completion is found, nil otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (let ((expansion ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (strip-prompt (and (get-buffer-process (current-buffer))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
470 comint-prompt-regexp)))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (he-init-string (he-line-beg strip-prompt) (point))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
474 (set-marker he-search-loc he-string-beg)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (setq he-search-bw t)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (if (not (equal he-search-string ""))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (save-excursion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 ;; Try looking backward unless inhibited.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (if he-search-bw
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (goto-char he-search-loc)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (setq expansion (he-line-search he-search-string
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 strip-prompt t))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
485 (set-marker he-search-loc (point))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
488 (set-marker he-search-loc he-string-end)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (setq he-search-bw ())))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (if (not expansion) ; Then look forward.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (goto-char he-search-loc)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (setq expansion (he-line-search he-search-string
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 strip-prompt nil))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
496 (set-marker he-search-loc (point))))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
500 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (he-substitute-string expansion t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (setq he-tried-table (cons expansion he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 t))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (defun try-expand-line-all-buffers (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 "Try to complete the current line, searching all other buffers.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 The argument OLD has to be nil the first call of this function, and t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 for subsequent calls (for further possible completions of the same
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 string). It returns t if a new completion is found, nil otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (let ((expansion ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (strip-prompt (and (get-buffer-process (current-buffer))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
514 comint-prompt-regexp))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (buf (current-buffer)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (he-init-string (he-line-beg strip-prompt) (point))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
519 (setq he-search-bufs (buffer-list))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
520 (setq he-searched-n-bufs 0)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
521 (set-marker he-search-loc 1 (car he-search-bufs))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (if (not (equal he-search-string ""))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
524 (while (and he-search-bufs
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
525 (not expansion)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
526 (or (not hippie-expand-max-buffers)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
527 (< he-searched-n-bufs hippie-expand-max-buffers)))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (set-buffer (car he-search-bufs))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (if (and (not (eq (current-buffer) buf))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
530 (not (string-match " \\*Minibuf-[0-9]+\\*"
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
531 (buffer-name (current-buffer))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (not (eq major-mode 'dired-mode)))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
533 ;; Dont search minibuffers nor dired buffers
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (save-excursion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (goto-char he-search-loc)
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
536 (setq strip-prompt (and (get-buffer-process (current-buffer))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
537 comint-prompt-regexp))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (setq expansion (he-line-search he-search-string
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 strip-prompt nil))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
540 (set-marker he-search-loc (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
541 (if expansion
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
542 (setq he-tried-table (cons expansion he-tried-table))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
543 (setq he-search-bufs (cdr he-search-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
544 (setq he-searched-n-bufs (1+ he-searched-n-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
545 (set-marker he-search-loc 1 (car he-search-bufs))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
546 (setq he-search-bufs (cdr he-search-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
547 (set-marker he-search-loc 1 (car he-search-bufs)))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (set-buffer buf)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
552 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (he-substitute-string expansion t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 t))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (defun he-line-search (str strip-prompt reverse)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (let ((result ()))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (while (and (not result)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (if reverse
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (re-search-backward
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (he-line-search-regexp str strip-prompt)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 nil t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (re-search-forward
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (he-line-search-regexp str strip-prompt)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 nil t)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (setq result (buffer-substring (match-beginning 2) (match-end 2)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 (if (he-string-member result he-tried-table)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (setq result nil))) ; if already in table, ignore
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 result))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (defun he-line-beg (strip-prompt)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (save-excursion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (end-of-line)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (if (re-search-backward (he-line-search-regexp "" strip-prompt)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 (save-excursion (beginning-of-line)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (point)) t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (match-beginning 2)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (beginning-of-line)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (point))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (defun he-line-search-regexp (pat strip-prompt)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (if strip-prompt
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
585 (concat "\\(" comint-prompt-regexp "\\|^\\s-*\\)\\("
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (regexp-quote pat)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 "[^\n]*[^ \t\n]\\)")
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (concat "^\\(\\s-*\\)\\("
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (regexp-quote pat)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 "[^\n]*[^ \t\n]\\)")))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
592 (defun try-expand-list (old)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
593 "Try to complete the current beginning of a list.
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
594 The argument OLD has to be nil the first call of this function, and t
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
595 for subsequent calls (for further possible completions of the same
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
596 string). It returns t if a new completion is found, nil otherwise."
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
597 (let ((expansion ()))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
598 (if (not old)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
599 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
600 (he-init-string (he-list-beg) (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
601 (set-marker he-search-loc he-string-beg)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
602 (setq he-search-bw t)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
603
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
604 (if (not (equal he-search-string ""))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
605 (save-excursion
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
606 ;; Try looking backward unless inhibited.
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
607 (if he-search-bw
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
608 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
609 (goto-char he-search-loc)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
610 (setq expansion (he-list-search he-search-string t))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
611 (set-marker he-search-loc (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
612 (if (not expansion)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
613 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
614 (set-marker he-search-loc he-string-end)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
615 (setq he-search-bw ())))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
616
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
617 (if (not expansion) ; Then look forward.
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
618 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
619 (goto-char he-search-loc)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
620 (setq expansion (he-list-search he-search-string nil))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
621 (set-marker he-search-loc (point))))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
622
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
623 (if (not expansion)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
624 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
625 (if old (he-reset-string))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
626 ())
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
627 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
628 (he-substitute-string expansion t)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
629 (setq he-tried-table (cons expansion he-tried-table))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
630 t))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
631
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
632 (defun try-expand-list-all-buffers (old)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
633 "Try to complete the current list, searching all other buffers.
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
634 The argument OLD has to be nil the first call of this function, and t
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
635 for subsequent calls (for further possible completions of the same
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
636 string). It returns t if a new completion is found, nil otherwise."
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
637 (let ((expansion ())
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
638 (buf (current-buffer)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
639 (if (not old)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
640 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
641 (he-init-string (he-list-beg) (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
642 (setq he-search-bufs (buffer-list))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
643 (setq he-searched-n-bufs 0)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
644 (set-marker he-search-loc 1 (car he-search-bufs))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
645
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
646 (if (not (equal he-search-string ""))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
647 (while (and he-search-bufs
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
648 (not expansion)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
649 (or (not hippie-expand-max-buffers)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
650 (< he-searched-n-bufs hippie-expand-max-buffers)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
651 (set-buffer (car he-search-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
652 (if (and (not (eq (current-buffer) buf))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
653 (not (string-match " \\*Minibuf-[0-9]+\\*"
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
654 (buffer-name (current-buffer))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
655 (not (eq major-mode 'dired-mode)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
656 ;; Dont search minibuffers nor dired buffers
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
657 (save-excursion
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
658 (goto-char he-search-loc)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
659 (setq expansion (he-list-search he-search-string nil))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
660 (set-marker he-search-loc (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
661 (if expansion
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
662 (setq he-tried-table (cons expansion he-tried-table))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
663 (setq he-search-bufs (cdr he-search-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
664 (setq he-searched-n-bufs (1+ he-searched-n-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
665 (set-marker he-search-loc 1 (car he-search-bufs))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
666 (setq he-search-bufs (cdr he-search-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
667 (set-marker he-search-loc 1 (car he-search-bufs)))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
668
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
669 (set-buffer buf)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
670 (if (not expansion)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
671 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
672 (if old (he-reset-string))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
673 ())
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
674 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
675 (he-substitute-string expansion t)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
676 t))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
677
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
678 (defun he-list-search (str reverse)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
679 (let ((result ())
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
680 beg pos err)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
681 (while (and (not result)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
682 (if reverse
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
683 (search-backward str nil t)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
684 (search-forward str nil t)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
685 (setq pos (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
686 (setq beg (match-beginning 0))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
687 (goto-char beg)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
688 (setq err ())
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
689 (condition-case ()
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
690 (forward-list 1)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
691 (error (setq err t)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
692 (if (not err)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
693 (progn
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
694 (setq result (buffer-substring beg (point)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
695 (if (he-string-member result he-tried-table)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
696 (setq result nil)))) ; if already in table, ignore
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
697 (goto-char pos))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
698 result))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
699
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
700 (defun he-list-beg ()
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
701 (save-excursion
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
702 (condition-case ()
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
703 (backward-up-list 1)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
704 (error ()))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
705 (point)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
706
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (defun try-expand-all-abbrevs (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 "Try to expand word before point according to all abbrev tables.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 The argument OLD has to be nil the first call of this function, and t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 for subsequent calls (for further possible expansions of the same
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 string). It returns t if a new expansion is found, nil otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (he-init-string (he-dabbrev-beg) (point))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (setq he-expand-list
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (and (not (equal he-search-string ""))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (mapcar (function (lambda (sym)
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
718 (abbrev-expansion (downcase he-search-string)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (eval sym))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 (append '(local-abbrev-table
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 global-abbrev-table)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 abbrev-table-name-list))))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (while (and he-expand-list
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (or (not (car he-expand-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (he-string-member (car he-expand-list) he-tried-table)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 (setq he-expand-list (cdr he-expand-list)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (if (null he-expand-list)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
729 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
732 (he-substitute-string (car he-expand-list) t)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (setq he-tried-table (cons (car he-expand-list) he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (setq he-expand-list (cdr he-expand-list))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 t)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (defun try-expand-dabbrev (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 "Try to expand word \"dynamically\", searching the current buffer.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 The argument OLD has to be nil the first call of this function, and t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 for subsequent calls (for further possible expansions of the same
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 string). It returns t if a new expansion is found, nil otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 (let ((expansion ()))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (he-init-string (he-dabbrev-beg) (point))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
746 (set-marker he-search-loc he-string-beg)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 (setq he-search-bw t)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 (if (not (equal he-search-string ""))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (save-excursion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 ;; Try looking backward unless inhibited.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 (if he-search-bw
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (goto-char he-search-loc)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (setq expansion (he-dab-search he-search-string t))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
756 (set-marker he-search-loc (point))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
759 (set-marker he-search-loc he-string-end)
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (setq he-search-bw ())))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (if (not expansion) ; Then look forward.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 (goto-char he-search-loc)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (setq expansion (he-dab-search he-search-string nil))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
766 (set-marker he-search-loc (point))))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
770 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 (he-substitute-string expansion t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (setq he-tried-table (cons expansion he-tried-table))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 t))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (defun try-expand-dabbrev-all-buffers (old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 "Tries to expand word \"dynamically\", searching all other buffers.
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 The argument OLD has to be nil the first call of this function, and t
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 for subsequent calls (for further possible expansions of the same
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 string). It returns t if a new expansion is found, nil otherwise."
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (let ((expansion ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 (buf (current-buffer)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (if (not old)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (he-init-string (he-dabbrev-beg) (point))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
787 (setq he-search-bufs (buffer-list))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
788 (setq he-searched-n-bufs 0)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
789 (set-marker he-search-loc 1 (car he-search-bufs))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 (if (not (equal he-search-string ""))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
792 (while (and he-search-bufs
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
793 (not expansion)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
794 (or (not hippie-expand-max-buffers)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
795 (< he-searched-n-bufs hippie-expand-max-buffers)))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 (set-buffer (car he-search-bufs))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (if (and (not (eq (current-buffer) buf))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
798 (not (string-match " \\*Minibuf-[0-9]+\\*"
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
799 (buffer-name (current-buffer))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
800 (not (eq major-mode 'dired-mode)))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
801 ;; Dont search minibuffers nor dired buffers
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 (save-excursion
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 (goto-char he-search-loc)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 (setq expansion (he-dab-search he-search-string nil))
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
805 (set-marker he-search-loc (point))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
806 (if expansion
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
807 (setq he-tried-table (cons expansion he-tried-table))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
808 (setq he-search-bufs (cdr he-search-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
809 (setq he-searched-n-bufs (1+ he-searched-n-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
810 (set-marker he-search-loc 1 (car he-search-bufs))))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
811 (setq he-search-bufs (cdr he-search-bufs))
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
812 (set-marker he-search-loc 1 (car he-search-bufs)))))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 (set-buffer buf)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 (if (not expansion)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (progn
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
817 (if old (he-reset-string))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 ())
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 (progn
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 (he-substitute-string expansion t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 t))))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 (defun he-dab-search-regexp (pat)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 (concat "\\b" (regexp-quote pat)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 "\\(\\sw\\|\\s_\\)+"))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 (defun he-dab-search (pattern reverse)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 (let ((result ()))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 (while (and (not result)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 (if reverse
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 (re-search-backward (he-dab-search-regexp pattern)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 nil t)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 (re-search-forward (he-dab-search-regexp pattern)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 nil t)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 (setq result (buffer-substring (match-beginning 0) (match-end 0)))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 (if (he-string-member result he-tried-table)
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 (setq result nil))) ; if already in table, ignore
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 result))
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 (defun he-dabbrev-beg ()
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
841 (save-excursion
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
842 (skip-syntax-backward "w_")
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
843 (skip-syntax-forward "_")
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
844 (point)))
1737
d7e9186edefa entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845
4130
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
846 (provide 'hippie-exp)
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
847
e5aee6a3bb75 * hippie-exp.el: Renamed from hippie.el.
Jim Blandy <jimb@redhat.com>
parents: 2233
diff changeset
848 ;;; hippie-exp.el ends here