annotate lisp/packages/dabbrev.el @ 110:fe104dbd9147 r20-1b7

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