annotate lisp/packages/dabbrev.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; dabbrev.el --- dynamic abbreviation package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1985, 1986, 1992, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Don Morrison
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: Lars Lindberg <Lars.Lindberg@sypro.cap.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Created: 16 Mars 1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Lindberg's last update version: 5.7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Keywords: abbrev expand completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2 of the License, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; (at your option) any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; The purpose with this package is to let you write just a few
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; characters of words you've written earlier to be able to expand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; To expand a word, just put the point right after the word and press
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; M-/ (dabbrev-expand) or M-C-/ (dabbrev-completion).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; Check out the customizable variables below to learn about all the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; features of this package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; Hints and tips for major modes writers:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; Recommended values C/Lisp etc text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; dabbrev-case-fold-search nil t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; dabbrev-case-replace nil t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; Set the variables you want special for your mode like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; (set (make-local-variable 'dabbrev-case-replace) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; Then you don't interfer with other modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; If your mode handles buffers that refers to other buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; (i.e. compilation-mode, gud-mode), then try to set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; `dabbrev-select-buffers-function' or `dabbrev-friend-buffer-function'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; to a function that point out those buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Same goes for major-modes that are connected to other modes. There
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; are for instance a number of mail-modes. One for reading, one for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; creating a new mail etc. Maybe those should be connected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; Example for GNUS (when we write a reply, we want dabbrev to look in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; the article for expansion):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; (set (make-local-variable 'dabbrev-friend-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; (lambda (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; (memq major-mode '(news-reply-mode gnus-article-mode)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; Known bugs and limitations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; - Possible to do several levels of `dabbrev-completion' in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; - dabbrev-completion doesn't handle resetting the globals variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; right. It resets them after finding the abbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; Future enhancements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; - Check the tags-files? Like tags-complete?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; - Add the possibility of searching both forward and backward to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; the nearest expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; - Check the kill-ring when everything else fails. (Maybe something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; for hippie-expand?). [Bng] <boris@cs.rochester.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; These people gave suggestions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; [hymie] Hyman Rosen <marks!hymie@jyacc.jyacc.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; [burgett] Steve Burgett <burgett@bizet.eecs.berkeley.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; [jules] Julian Gosnell <jules@x.co.uk>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; [kifer] Michael Kifer <kifer@sbcs.sunysb.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; [ake] Ake Stenhoff <extaksf@aom.ericsson.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; [alon] Alon Albert <al%imercury@uunet.uu.net>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; [tromey] Tom Tromey <tromey@busco.lanl.gov>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; [Rolf] Rolf Schreiber <rolf@mathematik.uni-stuttgart.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; [Petri] Petri Raitio <per@tekla.fi>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; [ejb] Jay Berkenbilt <ejb@ERA.COM>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; [hawley] Bob Hawley <rth1@quartet.mt.att.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; ... and to all the people who have participated in the beta tests.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;; Customization variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar dabbrev-backward-only nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "*If non-nil, `dabbrev-expand' only looks backwards.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defvar dabbrev-limit nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "*Limits region searched by `dabbrev-expand' to this many chars away.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defvar dabbrev-abbrev-skip-leading-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "*Regexp for skipping leading characters of an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 Example: Set this to \"\\\\$\" for programming languages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 in which variable names may appear with or without a leading `$'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (For example, in Makefiles.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 Set this to nil if no characters should be skipped.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; XEmacs change: The old defaults are just too obnoxious. Rarely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; do you actually want the case-folding behavior here, even though
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; it's useful to have case-fold-search set to t most of the time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defvar dabbrev-case-fold-search nil ;;'case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "*Non-nil if dabbrev searches should ignore case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 A value of nil means case is significant.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 The value of this variable is an expression; it is evaluated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 and the resulting value determines the decision.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 For example: setting this to `case-fold-search' means evaluate that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 variable to see whether its value is nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar dabbrev-upcase-means-case-search nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "*The significance of an uppercase character in an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 nil means case fold search, non-nil means case sensitive search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 This variable has an effect only when the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 `dabbrev-case-fold-search' evaluates to t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; XEmacs change: likewise here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; I recommend that you set this to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defvar dabbrev-case-replace nil ;;'case-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "*Non-nil means dabbrev should preserve case when expanding the abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 More precisely, it preserves the case pattern of the abbreviation as you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 typed it--as opposed to the case pattern of the expansion that is copied.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 The value of this variable is an expression; it is evaluated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 and the resulting value determines the decision.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 For example, setting this to `case-replace' means evaluate that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 variable to see if its value is t or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 This variable has an effect only when the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 `dabbrev-case-fold-search' evaluates to t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defvar dabbrev-abbrev-char-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "*Regexp to recognize a character in an abbreviation or expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 This regexp will be surrounded with \\\\( ... \\\\) when actually used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 Set this variable to \"\\\\sw\" if you want ordinary words or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 \"\\\\sw\\\\|\\\\s_\" if you want symbols (including characters whose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 syntax is \"symbol\" as well as those whose syntax is \"word\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 The value nil has a special meaning: the abbreviation is from point to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 previous word-start, but the search is for symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 For instance, if you are programming in Lisp, `yes-or-no-p' is a symbol,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 while `yes', `or', `no' and `p' are considered words. If this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 variable is nil, then expanding `yes-or-no-' looks for a symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 starting with or containing `no-'. If you set this variable to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 \"\\\\sw\\\\|\\\\s_\", that expansion looks for a symbol starting with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 `yes-or-no-'. Finally, if you set this variable to \"\\\\sw\", then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 expanding `yes-or-no-' signals an error because `-' is not part of a word;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 but expanding `yes-or-no' looks for a word starting with `no'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 The recommended value is \"\\\\sw\\\\|\\\\s_\".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defvar dabbrev-check-all-buffers t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "*Non-nil means dabbrev package should search *all* buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 Dabbrev always searches the current buffer first. Then, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 `dabbrev-check-other-buffers' says so, it searches the buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 designated by `dabbrev-select-buffers-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Then, if `dabbrev-check-all-buffers' is non-nil, dabbrev searches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 all the other buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defvar dabbrev-check-other-buffers t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "*Should \\[dabbrev-expand] look in other buffers?\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 nil: Don't look in other buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 t: Also look for expansions in the buffers pointed out by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 `dabbrev-select-buffers-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 Anything else: When we can't find any more expansions in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 the current buffer, then ask the user whether to look in other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 buffers too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 The default value is t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; I guess setting this to a function that selects all C- or C++-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; mode buffers would be a good choice for a debugging buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; when debugging C- or C++-code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (defvar dabbrev-select-buffers-function 'dabbrev--select-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 "A function that selects buffers that should be searched by dabbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 The function should take no arguments and return a list of buffers to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 search for expansions. Have a look at `dabbrev--select-buffers' for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 an example.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 A mode setting this variable should make it buffer local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (defvar dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 "*A function to decide whether dabbrev should search OTHER-BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 The function should take one argument, OTHER-BUFFER, and return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 non-nil if that buffer should be searched. Have a look at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 `dabbrev--same-major-mode-p' for an example.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 The value of `dabbrev-friend-buffer-function' has an effect only if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 the value of `dabbrev-select-buffers-function' uses it. The function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 `dabbrev--select-buffers' is one function you can use here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 A mode setting this variable should make it buffer local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defvar dabbrev-search-these-buffers-only nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "If non-nil, a list of buffers which dabbrev should search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 If this variable is non-nil, dabbrev will only look in these buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 It will not even look in the current buffer if it is not a member of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 this list.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;;; Internal variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;; Last obarray of completions in `dabbrev-completion'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (defvar dabbrev--last-obarray nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; Table of expansions seen so far
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defvar dabbrev--last-table nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;; Last string we tried to expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defvar dabbrev--last-abbreviation nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; Location last abbreviation began
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (defvar dabbrev--last-abbrev-location nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; Direction of last dabbrevs search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defvar dabbrev--last-direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; Last expansion of an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defvar dabbrev--last-expansion nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; Location the last expansion was found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defvar dabbrev--last-expansion-location nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;; The list of remaining buffers with the same mode as current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defvar dabbrev--friend-buffer-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; The buffer we looked in last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defvar dabbrev--last-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; The buffer we found the expansion last time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (defvar dabbrev--last-buffer-found nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; The buffer we last did a completion in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (defvar dabbrev--last-completion-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; Same as dabbrev-check-other-buffers, but is set for every expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defvar dabbrev--check-other-buffers dabbrev-check-other-buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; The regexp for recognizing a character in an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defvar dabbrev--abbrev-char-regexp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;;; Macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;;; Get the buffer that mini-buffer was activated from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defsubst dabbrev--minibuffer-origin ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (car (cdr (buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ;; Make a list of some of the elements of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;; Check each element of LIST, storing it temporarily in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; variable ELEMENT, and include it in the result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; if CONDITION evaluates non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (defmacro dabbrev-filter-elements (element list condition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (` (let (dabbrev-result dabbrev-tail (, element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (setq dabbrev-tail (, list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (while dabbrev-tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (setq (, element) (car dabbrev-tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (if (, condition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (setq dabbrev-result (cons (, element) dabbrev-result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq dabbrev-tail (cdr dabbrev-tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (nreverse dabbrev-result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defun dabbrev--extent-clicked-on (event extent user-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (let ((buffer (first user-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (point (second user-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (init (third user-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (wconfig (fourth user-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (set-window-configuration wconfig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (dabbrev--substitute-expansion nil init (extent-string extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;;; Exported functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; XEmacs changes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (define-key global-map [(meta /)] 'dabbrev-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;;;??? Do we want this?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (define-key global-map [(meta control /)] 'dabbrev-completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (defun dabbrev-completion (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 "Completion on current word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 Like \\[dabbrev-expand] but finds all expansions in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 and presents suggestions for completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 With a prefix argument, it searches all buffers accepted by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 function pointed out by `dabbrev-friend-buffer-function' to find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 If the prefix argument is 16 (which comes from C-u C-u),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 then it searches *all* buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 With no prefix argument, it reuses an old completion list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 if there is a suitable one already."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (dabbrev--reset-global-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let* ((dabbrev-check-other-buffers (and arg t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (dabbrev-check-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (and arg (= (prefix-numeric-value arg) 16)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (abbrev (dabbrev--abbrev-at-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (ignore-case-p (and (eval dabbrev-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (or (not dabbrev-upcase-means-case-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (string= abbrev (downcase abbrev)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (my-obarray dabbrev--last-obarray)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (if (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 my-obarray
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (or (eq dabbrev--last-completion-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (eq dabbrev--last-completion-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (dabbrev--minibuffer-origin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 dabbrev--last-abbreviation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (>= (length abbrev) (length dabbrev--last-abbreviation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (string= dabbrev--last-abbreviation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (substring abbrev 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (length dabbrev--last-abbreviation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (setq init (try-completion abbrev my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; We can reuse the existing completion list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ;; New abbreviation to expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq dabbrev--last-abbreviation abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;; Find all expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (let ((completion-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (dabbrev--find-all-expansions abbrev ignore-case-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;; Make an obarray with all expansions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (setq my-obarray (make-vector (length completion-list) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (or (> (length my-obarray) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (error "No dynamic expansion for \"%s\" found%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (if dabbrev--check-other-buffers "" " in this-buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ((or (not ignore-case-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (not dabbrev-case-replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (intern string my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 completion-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 ((string= abbrev (upcase abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (intern (upcase string) my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 completion-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ((string= (substring abbrev 0 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (upcase (substring abbrev 0 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (intern (capitalize string) my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 completion-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (intern (downcase string) my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 completion-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (setq dabbrev--last-obarray my-obarray)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (setq dabbrev--last-completion-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;; Find the longest common string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (setq init (try-completion abbrev my-obarray)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ;; Let the user choose between the expansions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (or (stringp init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (setq init abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; * Replace string fragment with matched common substring completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ((and (not (string-equal init ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (not (string-equal (downcase init) (downcase abbrev))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (if (> (length (all-completions init my-obarray)) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (message "Repeat `%s' to see all completions"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (key-description (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (message "The only possible completion"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (dabbrev--substitute-expansion nil abbrev init))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ;; * String is a common substring completion already. Make list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (message "Making completion list...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; construct the arg before calling `with-output-to-temp-buffer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ;; because that changes the window config
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (let ((arg (list (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (set-marker (make-marker) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (current-window-configuration))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (with-output-to-temp-buffer " *Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (display-completion-list (all-completions init my-obarray)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 'dabbrev--extent-clicked-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (message "Making completion list...done")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (message nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (defun dabbrev-expand (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 "Expand previous word \"dynamically\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 Expands to the most recent, preceding word for which this is a prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 If no suitable preceding word is found, words following point are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 considered. If still no suitable word is found, then look in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 buffers accepted by the function pointed out by variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 `dabbrev-friend-buffer-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 A positive prefix argument, N, says to take the Nth backward *distinct*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 possibility. A negative argument says search forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 If the cursor has not moved from the end of the previous expansion and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 no argument is given, replace the previously-made expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 with the next possible expansion not yet tried.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 The variable `dabbrev-backward-only' may be used to limit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 direction of search to backward if set non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (let (abbrev expansion old direction (orig-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;; abbrev -- the abbrev to expand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; expansion -- the expansion found (eventually) or nil until then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; old -- the text currently in the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; (the abbrev, or the previously-made expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (if (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (markerp dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (marker-position dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (or (eq last-command this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (= dabbrev--last-abbrev-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;; Find a different expansion for the same abbrev as last time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setq abbrev dabbrev--last-abbreviation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (setq old dabbrev--last-expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (setq direction dabbrev--last-direction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; If the user inserts a space after expanding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ;; and then asks to expand again, always fetch the next word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (if (and (eq (preceding-char) ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (markerp dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (marker-position dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (= (point) (1+ dabbrev--last-abbrev-location)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; The "abbrev" to expand is just the space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (setq abbrev " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (if dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (set-buffer dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ;; Find the end of the last "expansion" word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (if (or (eq dabbrev--last-direction 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (and (eq dabbrev--last-direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (< dabbrev--last-expansion-location (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (setq dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (+ dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (length dabbrev--last-expansion))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (goto-char dabbrev--last-expansion-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; Take the following word, with intermediate separators,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; as our expansion this time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (concat "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (setq expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (buffer-substring dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; Record the end of this expansion, in case we repeat this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (setq dabbrev--last-expansion-location (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ;; Indicate that dabbrev--last-expansion-location is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;; at the end of the expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (setq dabbrev--last-direction -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;; We have a different abbrev to expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (dabbrev--reset-global-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (setq direction (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (if dabbrev-backward-only 1 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (setq abbrev (dabbrev--abbrev-at-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (setq old nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ;; Find the expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (or expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (setq expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (dabbrev--find-expansion abbrev direction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (and (eval dabbrev-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (or (not dabbrev-upcase-means-case-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (string= abbrev (downcase abbrev))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ((not expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (dabbrev--reset-global-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (setq buffer-undo-list (cons orig-point buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;; Put back the original abbrev with its original case pattern.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (search-backward old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (insert abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (delete-region (point) (+ (point) (length old)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (error "No%s dynamic expansion for `%s' found"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (if old " further" "") abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if (not (eq dabbrev--last-buffer dabbrev--last-buffer-found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (message "Expansion found in '%s'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (buffer-name dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq dabbrev--last-buffer-found dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (message nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (if (and (or (eq (current-buffer) dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (null dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (numberp dabbrev--last-expansion-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (and (> dabbrev--last-expansion-location (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (setq dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (copy-marker dabbrev--last-expansion-location)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;; Success: stick it in and return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (setq buffer-undo-list (cons orig-point buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (dabbrev--substitute-expansion old abbrev expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;; Save state for re-expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (setq dabbrev--last-expansion expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (setq dabbrev--last-abbreviation abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (setq dabbrev--last-abbrev-location (point-marker))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ;;; Local functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;;; Checks if OTHER-BUFFER has the same major mode as current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (defun dabbrev--same-major-mode-p (other-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (eq major-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (set-buffer other-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 major-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ;;; Back over all abbrev type characters and then moves forward over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;;; all skip characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (defun dabbrev--goto-start-of-abbrev ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;; Move backwards over abbrev chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (if (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (while (and (looking-at dabbrev--abbrev-char-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (or (looking-at dabbrev--abbrev-char-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (and dabbrev-abbrev-skip-leading-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (while (looking-at dabbrev-abbrev-skip-leading-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (forward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;;; Extract the symbol at point to serve as abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (defun dabbrev--abbrev-at-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;; Check for error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (error "No possible abbreviation preceding point"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ;; Return abbrev at point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 ;; Record the end of the abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (setq dabbrev--last-abbrev-location (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;; If we aren't right after an abbreviation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ;; move point back to just after one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; This is so the user can get successive words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 ;; by typing the punctuation followed by M-/.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (not (looking-at (concat "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (or dabbrev-abbrev-char-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 "\\)+"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (if (re-search-backward (or dabbrev-abbrev-char-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (error "No possible abbreviation preceding point"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;; Now find the beginning of that one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (dabbrev--goto-start-of-abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (buffer-substring dabbrev--last-abbrev-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ;;; Initializes all global variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (defun dabbrev--reset-global-variables ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ;; dabbrev--last-obarray and dabbrev--last-completion-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;; must not be reset here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (setq dabbrev--last-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 dabbrev--last-abbreviation nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 dabbrev--last-abbrev-location nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 dabbrev--last-direction nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 dabbrev--last-expansion nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 dabbrev--last-expansion-location nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 dabbrev--friend-buffer-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 dabbrev--last-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 dabbrev--last-buffer-found nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 dabbrev--check-other-buffers dabbrev-check-other-buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 ;;; Find all buffers that are considered "friends" according to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 ;;; function pointed out by dabbrev-friend-buffer-function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (defun dabbrev--select-buffers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (set-buffer (dabbrev--minibuffer-origin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (let ((orig-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (dabbrev-filter-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 buffer (buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (and (not (eq orig-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (boundp 'dabbrev-friend-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (funcall dabbrev-friend-buffer-function buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;;; Search for ABBREV, N times, normally looking forward,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;;; but looking in reverse instead if REVERSE is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (defun dabbrev--try-find (abbrev reverse n ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (let ((expansion nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (and dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (goto-char dabbrev--last-expansion-location))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (let ((case-fold-search ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (count n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (while (and (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq expansion (dabbrev--search abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (setq count (1- count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (and expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (setq dabbrev--last-expansion-location (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 expansion))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;;; Find all expansions of ABBREV
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (defun dabbrev--find-all-expansions (abbrev ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (let ((all-expansions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (while (setq expansion (dabbrev--find-expansion abbrev -1 ignore-case))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (setq all-expansions (cons expansion all-expansions))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 all-expansions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (defun dabbrev--scanning-message ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (message "Scanning `%s'" (buffer-name (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;;; Find one occasion of ABBREV.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;;; DIRECTION > 0 means look that many times backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 ;;; DIRECTION < 0 means look that many times forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 ;;; DIRECTION = 0 means try both backward and forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 ;;; IGNORE-CASE non-nil means ignore case when searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (defun dabbrev--find-expansion (abbrev direction ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (let (expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (set-buffer dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (dabbrev--scanning-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 ((and (not dabbrev-search-these-buffers-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (window-minibuffer-p (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (set-buffer (dabbrev--minibuffer-origin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 ;; In the minibuffer-origin buffer we will only search from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 ;; the top and down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 ;; XEmacs: This is absolutely the stupidest thing I've ever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;; heard of.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 ;;(goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ;;(setq direction -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (dabbrev--scanning-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ;; Look backwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ((and (not dabbrev-search-these-buffers-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (>= direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (setq dabbrev--last-direction (min 1 direction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (setq expansion (dabbrev--try-find abbrev t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (max 1 direction)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 ;; Look forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ((and (or (not dabbrev-search-these-buffers-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (<= direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (setq dabbrev--last-direction -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (setq expansion (dabbrev--try-find abbrev nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (max 1 (- direction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;; Look in other buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;; Start at (point-min) and look forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (setq dabbrev--last-direction -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ;; Make sure that we should check other buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (or dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (mapcar (function get-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 dabbrev-search-these-buffers-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (not dabbrev--check-other-buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (not (or (eq dabbrev--check-other-buffers t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (setq dabbrev--check-other-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (y-or-n-p "Scan other buffers also? ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (let* (friend-buffer-list non-friend-buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (funcall dabbrev-select-buffers-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (if dabbrev-check-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (setq non-friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (nreverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (dabbrev-filter-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 buffer (buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (not (memq buffer dabbrev--friend-buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (append dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 non-friend-buffer-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 ;; Move buffers that are visible on the screen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; to the front of the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (if dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (let ((w (next-window (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (while (not (eq w (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (cons (window-buffer w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (delq (window-buffer w) dabbrev--friend-buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (setq w (next-window w)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;; Walk through the buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (while (and (not expansion) dabbrev--friend-buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (setq dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (car dabbrev--friend-buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (cdr dabbrev--friend-buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (set-buffer dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (dabbrev--scanning-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (setq dabbrev--last-expansion-location (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 expansion)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (defun dabbrev--safe-replace-match (string &optional fixedcase literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (if (eq major-mode 'picture-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (picture-replace-match string fixedcase literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (replace-match string fixedcase literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;;; Substitute the current string in buffer with the expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ;;; OLD is nil or the last expansion substring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 ;;; ABBREV is the abbreviation we are working with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 ;;; EXPANSION is the expansion substring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (defun dabbrev--substitute-expansion (old abbrev expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;;(undo-boundary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (let ((use-case-replace (and (eval dabbrev-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (or (not dabbrev-upcase-means-case-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (string= abbrev (downcase abbrev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (eval dabbrev-case-replace))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (and nil use-case-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (setq old (concat abbrev (or old "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (setq expansion (concat abbrev expansion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (search-backward old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 ;;(store-match-data (list (point-marker) (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (search-backward abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ;; Make case of replacement conform to case of abbreviation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ;; provided (1) that kind of thing is enabled in this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ;; and (2) the replacement itself is all lower case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (dabbrev--safe-replace-match expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (not use-case-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;;; Search function used by dabbrevs library.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;;; ABBREV is string to find as prefix of word. Second arg, REVERSE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ;;; is t for reverse search, nil for forward. Variable dabbrev-limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;;; controls the maximum search region size. Third argment IGNORE-CASE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 ;;; non-nil means treat case as insignificant while looking for a match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ;;; and when comparing with previous matches. Also if that's non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 ;;; and the match is found at the beginning of a sentence and is in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 ;;; lower case except for the initial then it is converted to all lower
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 ;;; case for return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;;; Table of expansions already seen is examined in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;;; `dabbrev--last-table' so that only distinct possibilities are found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ;;; by dabbrev-re-expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ;;; Value is the expansion, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (defun dabbrev--search (abbrev reverse ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (let ((pattern1 (concat (regexp-quote abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 "\\(" dabbrev--abbrev-char-regexp "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (pattern2 (concat (regexp-quote abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (found-string nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;; Limited search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (and dabbrev-limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (narrow-to-region dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (+ (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (if reverse (- dabbrev-limit) dabbrev-limit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;; Look for a distinct expansion, using dabbrev--last-table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (while (and (not found-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (if reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (re-search-backward pattern1 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (re-search-forward pattern1 nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ;; In case we matched in the middle of a word,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ;; back up to start of word and verify we still match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (dabbrev--goto-start-of-abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (if (not (looking-at pattern1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 ;; We have a truly valid match. Find the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (re-search-forward pattern2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (setq found-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (buffer-substring (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (and ignore-case (setq found-string (downcase found-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;; Ignore this match if it's already in the table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (if (dabbrev-filter-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 table-string dabbrev--last-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (string= found-string table-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (setq found-string nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 ;; Prepare to continue searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (if reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (goto-char (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;; If we found something, use it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (if found-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;; Put it into `dabbrev--last-table'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ;; and return it (either downcased, or as is).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (let ((result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (buffer-substring (match-beginning 0) (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (setq dabbrev--last-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (cons found-string dabbrev--last-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (if (and ignore-case (eval dabbrev-case-replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (downcase result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 result)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (provide 'dabbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ;; dabbrev.el ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870