annotate lisp/packages/dabbrev.el @ 149:538048ae2ab8 r20-3b1

Import from CVS: tag r20-3b1
author cvs
date Mon, 13 Aug 2007 09:36:16 +0200
parents cca96a509cfe
children 929b76928fce
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 ;;----------------------------------------------------------------
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
101
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
102 (defgroup dabbrev nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
103 "Dynamic Abbreviations"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
104 :tag "Dynamic Abbreviations"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
105 :group 'abbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
107 (defcustom dabbrev-backward-only nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
108 "*If non-nil, `dabbrev-expand' only looks backwards."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
109 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
110 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
112 (defcustom dabbrev-limit nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
113 "*Limits region searched by `dabbrev-expand' to this many chars away."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
114 :type '(choice (const :tag "off" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
115 integer)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
116 :group 'dabbrev)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
117
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
118 (defcustom dabbrev-abbrev-skip-leading-regexp nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "*Regexp for skipping leading characters of an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 Example: Set this to \"\\\\$\" for programming languages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 in which variable names may appear with or without a leading `$'.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
123 \(For example, in Makefiles.)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
125 Set this to nil if no characters should be skipped."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
126 :type '(choice regexp
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
127 (const :tag "off" nil))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
128 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; XEmacs change: The old defaults are just too obnoxious. Rarely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; do you actually want the case-folding behavior here, even though
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; it's useful to have case-fold-search set to t most of the time.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
133 (defcustom dabbrev-case-fold-search nil ;;'case-fold-search
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "*Non-nil if dabbrev searches should ignore case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 A value of nil means case is significant.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 The value of this variable is an expression; it is evaluated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 and the resulting value determines the decision.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 For example: setting this to `case-fold-search' means evaluate that
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
140 variable to see whether its value is nil."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
141 :type 'sexp
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
142 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
144 (defcustom dabbrev-upcase-means-case-search nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 "*The significance of an uppercase character in an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 nil means case fold search, non-nil means case sensitive search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 This variable has an effect only when the value of
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
149 `dabbrev-case-fold-search' evaluates to t."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
150 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
151 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; XEmacs change: likewise here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; I recommend that you set this to nil.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
155 (defcustom dabbrev-case-replace nil ;;'case-replace
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "*Non-nil means dabbrev should preserve case when expanding the abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 More precisely, it preserves the case pattern of the abbreviation as you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 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
159 The value of this variable is an expression; it is evaluated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 and the resulting value determines the decision.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 For example, setting this to `case-replace' means evaluate that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 variable to see if its value is t or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 This variable has an effect only when the value of
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
165 `dabbrev-case-fold-search' evaluates to t."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
166 :type 'sexp
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
167 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
169 (defcustom dabbrev-abbrev-char-regexp nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 "*Regexp to recognize a character in an abbreviation or expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 This regexp will be surrounded with \\\\( ... \\\\) when actually used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 Set this variable to \"\\\\sw\" if you want ordinary words or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 \"\\\\sw\\\\|\\\\s_\" if you want symbols (including characters whose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 syntax is \"symbol\" as well as those whose syntax is \"word\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 The value nil has a special meaning: the abbreviation is from point to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 previous word-start, but the search is for symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 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
181 while `yes', `or', `no' and `p' are considered words. If this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 variable is nil, then expanding `yes-or-no-' looks for a symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 starting with or containing `no-'. If you set this variable to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 \"\\\\sw\\\\|\\\\s_\", that expansion looks for a symbol starting with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 `yes-or-no-'. Finally, if you set this variable to \"\\\\sw\", then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 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
187 but expanding `yes-or-no' looks for a word starting with `no'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
189 The recommended value is \"\\\\sw\\\\|\\\\s_\"."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
190 :type '(choice (const nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
191 regexp)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
192 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
194 (defcustom dabbrev-check-all-buffers t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 "*Non-nil means dabbrev package should search *all* buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 Dabbrev always searches the current buffer first. Then, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 `dabbrev-check-other-buffers' says so, it searches the buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 designated by `dabbrev-select-buffers-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 Then, if `dabbrev-check-all-buffers' is non-nil, dabbrev searches
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
202 all the other buffers."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
203 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
204 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
206 (defcustom dabbrev-check-other-buffers t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 "*Should \\[dabbrev-expand] look in other buffers?\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 nil: Don't look in other buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 t: Also look for expansions in the buffers pointed out by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 `dabbrev-select-buffers-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 Anything else: When we can't find any more expansions in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 the current buffer, then ask the user whether to look in other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 buffers too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
216 The default value is t."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
217 :type '(choice (const :tag "off" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
218 (const :tag "on" t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
219 (const :tag "ask" other))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
220 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; I guess setting this to a function that selects all C- or C++-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; mode buffers would be a good choice for a debugging buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;; when debugging C- or C++-code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (defvar dabbrev-select-buffers-function 'dabbrev--select-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 "A function that selects buffers that should be searched by dabbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 The function should take no arguments and return a list of buffers to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 search for expansions. Have a look at `dabbrev--select-buffers' for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 an example.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 A mode setting this variable should make it buffer local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
233 (defcustom dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "*A function to decide whether dabbrev should search OTHER-BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 The function should take one argument, OTHER-BUFFER, and return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 non-nil if that buffer should be searched. Have a look at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 `dabbrev--same-major-mode-p' for an example.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 The value of `dabbrev-friend-buffer-function' has an effect only if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 the value of `dabbrev-select-buffers-function' uses it. The function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 `dabbrev--select-buffers' is one function you can use here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
243 A mode setting this variable should make it buffer local."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
244 :type 'function
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
245 :group 'dabbrev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 2
diff changeset
247 (defcustom dabbrev-search-these-buffers-only nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "If non-nil, a list of buffers which dabbrev should search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 If this variable is non-nil, dabbrev will only look in these buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 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
251 this list.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
253 ;;----------------------------------------------------------------
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
254 ;; Internal variables
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
255 ;;----------------------------------------------------------------
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; Last obarray of completions in `dabbrev-completion'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (defvar dabbrev--last-obarray nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; Table of expansions seen so far
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defvar dabbrev--last-table nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Last string we tried to expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defvar dabbrev--last-abbreviation nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; Location last abbreviation began
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (defvar dabbrev--last-abbrev-location nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;; Direction of last dabbrevs search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defvar dabbrev--last-direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;; Last expansion of an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defvar dabbrev--last-expansion nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; Location the last expansion was found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defvar dabbrev--last-expansion-location nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; The list of remaining buffers with the same mode as current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defvar dabbrev--friend-buffer-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; The buffer we looked in last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defvar dabbrev--last-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; The buffer we found the expansion last time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defvar dabbrev--last-buffer-found nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;; The buffer we last did a completion in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defvar dabbrev--last-completion-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
290 ;; Non-nil means we should upcase
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
291 ;; when copying successive words.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
292 (defvar dabbrev--last-case-pattern nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
293
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; Same as dabbrev-check-other-buffers, but is set for every expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (defvar dabbrev--check-other-buffers dabbrev-check-other-buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; The regexp for recognizing a character in an abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defvar dabbrev--abbrev-char-regexp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
300 ;;----------------------------------------------------------------
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
301 ;; Macros
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
302 ;;----------------------------------------------------------------
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;; Get the buffer that mini-buffer was activated from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defsubst dabbrev--minibuffer-origin ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (car (cdr (buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;; Make a list of some of the elements of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;; Check each element of LIST, storing it temporarily in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ;; variable ELEMENT, and include it in the result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; if CONDITION evaluates non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (defmacro dabbrev-filter-elements (element list condition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (` (let (dabbrev-result dabbrev-tail (, element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (setq dabbrev-tail (, list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (while dabbrev-tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (setq (, element) (car dabbrev-tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (if (, condition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (setq dabbrev-result (cons (, element) dabbrev-result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq dabbrev-tail (cdr dabbrev-tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (nreverse dabbrev-result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (defun dabbrev--extent-clicked-on (event extent user-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (let ((buffer (first user-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (point (second user-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (init (third user-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (wconfig (fourth user-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (set-window-configuration wconfig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (dabbrev--substitute-expansion nil init (extent-string extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
332 ;;----------------------------------------------------------------
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
333 ;; Exported functions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
334 ;;----------------------------------------------------------------
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;; XEmacs changes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (define-key global-map [(meta /)] 'dabbrev-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;;;??? Do we want this?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (define-key global-map [(meta control /)] 'dabbrev-completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defun dabbrev-completion (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 "Completion on current word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 Like \\[dabbrev-expand] but finds all expansions in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 and presents suggestions for completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 With a prefix argument, it searches all buffers accepted by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 function pointed out by `dabbrev-friend-buffer-function' to find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 If the prefix argument is 16 (which comes from C-u C-u),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 then it searches *all* buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 With no prefix argument, it reuses an old completion list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 if there is a suitable one already."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (dabbrev--reset-global-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (let* ((dabbrev-check-other-buffers (and arg t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (dabbrev-check-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (and arg (= (prefix-numeric-value arg) 16)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (abbrev (dabbrev--abbrev-at-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (ignore-case-p (and (eval dabbrev-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (or (not dabbrev-upcase-means-case-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (string= abbrev (downcase abbrev)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (my-obarray dabbrev--last-obarray)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (if (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 my-obarray
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (or (eq dabbrev--last-completion-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (eq dabbrev--last-completion-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (dabbrev--minibuffer-origin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 dabbrev--last-abbreviation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (>= (length abbrev) (length dabbrev--last-abbreviation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (string= dabbrev--last-abbreviation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (substring abbrev 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (length dabbrev--last-abbreviation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (setq init (try-completion abbrev my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ;; We can reuse the existing completion list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; New abbreviation to expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (setq dabbrev--last-abbreviation abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;; Find all expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (let ((completion-list
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
391 (dabbrev--find-all-expansions abbrev ignore-case-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
392 (completion-ignore-case ignore-case-p))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ;; Make an obarray with all expansions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (setq my-obarray (make-vector (length completion-list) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (or (> (length my-obarray) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (error "No dynamic expansion for \"%s\" found%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (if dabbrev--check-other-buffers "" " in this-buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ((or (not ignore-case-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (not dabbrev-case-replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (intern string my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 completion-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ((string= abbrev (upcase abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (intern (upcase string) my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 completion-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ((string= (substring abbrev 0 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (upcase (substring abbrev 0 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (intern (capitalize string) my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 completion-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (mapcar (function (lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (intern (downcase string) my-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 completion-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (setq dabbrev--last-obarray my-obarray)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (setq dabbrev--last-completion-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ;; Find the longest common string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (setq init (try-completion abbrev my-obarray)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; Let the user choose between the expansions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (or (stringp init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (setq init abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ;; * Replace string fragment with matched common substring completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ((and (not (string-equal init ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (not (string-equal (downcase init) (downcase abbrev))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (if (> (length (all-completions init my-obarray)) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (message "Repeat `%s' to see all completions"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (key-description (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (message "The only possible completion"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (dabbrev--substitute-expansion nil abbrev init))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;; * String is a common substring completion already. Make list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (message "Making completion list...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ;; construct the arg before calling `with-output-to-temp-buffer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;; because that changes the window config
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (let ((arg (list (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (set-marker (make-marker) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (current-window-configuration))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (with-output-to-temp-buffer " *Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (display-completion-list (all-completions init my-obarray)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
447 :activate-callback
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 'dabbrev--extent-clicked-on
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
449 :user-data arg)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (message "Making completion list...done")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (message nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (defun dabbrev-expand (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 "Expand previous word \"dynamically\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 Expands to the most recent, preceding word for which this is a prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 If no suitable preceding word is found, words following point are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 considered. If still no suitable word is found, then look in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 buffers accepted by the function pointed out by variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 `dabbrev-friend-buffer-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 A positive prefix argument, N, says to take the Nth backward *distinct*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 possibility. A negative argument says search forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 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
468 no argument is given, replace the previously-made expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 with the next possible expansion not yet tried.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 The variable `dabbrev-backward-only' may be used to limit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 direction of search to backward if set non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (interactive "*P")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
476 (let (abbrev record-case-pattern
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
477 expansion old direction (orig-point (point)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; abbrev -- the abbrev to expand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; expansion -- the expansion found (eventually) or nil until then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; old -- the text currently in the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;; (the abbrev, or the previously-made expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (if (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (markerp dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (marker-position dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (or (eq last-command this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (= dabbrev--last-abbrev-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; Find a different expansion for the same abbrev as last time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (setq abbrev dabbrev--last-abbreviation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (setq old dabbrev--last-expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (setq direction dabbrev--last-direction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;; If the user inserts a space after expanding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;; and then asks to expand again, always fetch the next word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (if (and (eq (preceding-char) ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (markerp dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (marker-position dabbrev--last-abbrev-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (= (point) (1+ dabbrev--last-abbrev-location)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ;; The "abbrev" to expand is just the space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (setq abbrev " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (if dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (set-buffer dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ;; Find the end of the last "expansion" word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (if (or (eq dabbrev--last-direction 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (and (eq dabbrev--last-direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (< dabbrev--last-expansion-location (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (setq dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (+ dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (length dabbrev--last-expansion))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (goto-char dabbrev--last-expansion-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ;; Take the following word, with intermediate separators,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;; as our expansion this time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (concat "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (setq expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (buffer-substring dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (point)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
522 (if dabbrev--last-case-pattern
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
523 (setq expansion (upcase expansion)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;; Record the end of this expansion, in case we repeat this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (setq dabbrev--last-expansion-location (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; Indicate that dabbrev--last-expansion-location is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;; at the end of the expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (setq dabbrev--last-direction -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; We have a different abbrev to expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (dabbrev--reset-global-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (setq direction (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (if dabbrev-backward-only 1 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (setq abbrev (dabbrev--abbrev-at-point))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
537 (setq record-case-pattern t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (setq old nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;; Find the expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (or expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (setq expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (dabbrev--find-expansion abbrev direction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (and (eval dabbrev-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (or (not dabbrev-upcase-means-case-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (string= abbrev (downcase abbrev))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ((not expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (dabbrev--reset-global-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (setq buffer-undo-list (cons orig-point buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;; Put back the original abbrev with its original case pattern.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (search-backward old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (insert abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (delete-region (point) (+ (point) (length old)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (error "No%s dynamic expansion for `%s' found"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (if old " further" "") abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (if (not (eq dabbrev--last-buffer dabbrev--last-buffer-found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (message "Expansion found in '%s'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (buffer-name dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (setq dabbrev--last-buffer-found dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (message nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (if (and (or (eq (current-buffer) dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (null dabbrev--last-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (numberp dabbrev--last-expansion-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (and (> dabbrev--last-expansion-location (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (setq dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (copy-marker dabbrev--last-expansion-location)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ;; Success: stick it in and return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq buffer-undo-list (cons orig-point buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (dabbrev--substitute-expansion old abbrev expansion)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
577
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
578 ;; If we are not copying successive words now,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
579 ;; set dabbrev--last-case-pattern.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
580 (and record-case-pattern
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
581 (setq dabbrev--last-case-pattern
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
582 (and (eval dabbrev-case-fold-search)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
583 (not dabbrev-upcase-means-case-search)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
584 (equal abbrev (upcase abbrev)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
585
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ;; Save state for re-expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (setq dabbrev--last-expansion expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (setq dabbrev--last-abbreviation abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (setq dabbrev--last-abbrev-location (point-marker))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
591 ;;----------------------------------------------------------------
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
592 ;; Local functions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
593 ;;----------------------------------------------------------------
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ;;; Checks if OTHER-BUFFER has the same major mode as current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (defun dabbrev--same-major-mode-p (other-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (eq major-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (set-buffer other-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 major-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 ;;; Back over all abbrev type characters and then moves forward over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ;;; all skip characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (defun dabbrev--goto-start-of-abbrev ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ;; Move backwards over abbrev chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (if (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (while (and (looking-at dabbrev--abbrev-char-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (or (looking-at dabbrev--abbrev-char-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (and dabbrev-abbrev-skip-leading-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (while (looking-at dabbrev-abbrev-skip-leading-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (forward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 ;;; Extract the symbol at point to serve as abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (defun dabbrev--abbrev-at-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;; Check for error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (error "No possible abbreviation preceding point"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 ;; Return abbrev at point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 ;; Record the end of the abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (setq dabbrev--last-abbrev-location (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ;; If we aren't right after an abbreviation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; move point back to just after one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;; This is so the user can get successive words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ;; by typing the punctuation followed by M-/.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (not (looking-at (concat "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (or dabbrev-abbrev-char-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 "\\)+"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (if (re-search-backward (or dabbrev-abbrev-char-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (error "No possible abbreviation preceding point"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;; Now find the beginning of that one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (dabbrev--goto-start-of-abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (buffer-substring dabbrev--last-abbrev-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 ;;; Initializes all global variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (defun dabbrev--reset-global-variables ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 ;; dabbrev--last-obarray and dabbrev--last-completion-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;; must not be reset here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (setq dabbrev--last-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 dabbrev--last-abbreviation nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 dabbrev--last-abbrev-location nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 dabbrev--last-direction nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 dabbrev--last-expansion nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 dabbrev--last-expansion-location nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 dabbrev--friend-buffer-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 dabbrev--last-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 dabbrev--last-buffer-found nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 dabbrev--check-other-buffers dabbrev-check-other-buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 ;;; Find all buffers that are considered "friends" according to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 ;;; function pointed out by dabbrev-friend-buffer-function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (defun dabbrev--select-buffers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (and (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (set-buffer (dabbrev--minibuffer-origin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (let ((orig-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (dabbrev-filter-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 buffer (buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (and (not (eq orig-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (boundp 'dabbrev-friend-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (funcall dabbrev-friend-buffer-function buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ;;; Search for ABBREV, N times, normally looking forward,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 ;;; but looking in reverse instead if REVERSE is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (defun dabbrev--try-find (abbrev reverse n ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (let ((expansion nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (and dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (goto-char dabbrev--last-expansion-location))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (let ((case-fold-search ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (count n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (while (and (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (setq expansion (dabbrev--search abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (setq count (1- count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (and expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (setq dabbrev--last-expansion-location (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 expansion))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ;;; Find all expansions of ABBREV
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (defun dabbrev--find-all-expansions (abbrev ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (let ((all-expansions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (while (setq expansion (dabbrev--find-expansion abbrev -1 ignore-case))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (setq all-expansions (cons expansion all-expansions))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 all-expansions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (defun dabbrev--scanning-message ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (message "Scanning `%s'" (buffer-name (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;;; Find one occasion of ABBREV.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;;; DIRECTION > 0 means look that many times backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;;; DIRECTION < 0 means look that many times forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;;; DIRECTION = 0 means try both backward and forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;;; IGNORE-CASE non-nil means ignore case when searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (defun dabbrev--find-expansion (abbrev direction ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (let (expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (set-buffer dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (dabbrev--scanning-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 ((and (not dabbrev-search-these-buffers-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (window-minibuffer-p (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (set-buffer (dabbrev--minibuffer-origin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;; In the minibuffer-origin buffer we will only search from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;; the top and down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;; XEmacs: This is absolutely the stupidest thing I've ever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;; heard of.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;;(goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;;(setq direction -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (dabbrev--scanning-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; Look backwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ((and (not dabbrev-search-these-buffers-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (>= direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (setq dabbrev--last-direction (min 1 direction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (setq expansion (dabbrev--try-find abbrev t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (max 1 direction)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;; Look forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ((and (or (not dabbrev-search-these-buffers-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (<= direction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (setq dabbrev--last-direction -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (setq expansion (dabbrev--try-find abbrev nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (max 1 (- direction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ;; Look in other buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ;; Start at (point-min) and look forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; ------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (setq dabbrev--last-direction -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 ;; Make sure that we should check other buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (or dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (mapcar (function get-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 dabbrev-search-these-buffers-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (not dabbrev--check-other-buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (not (or (eq dabbrev--check-other-buffers t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (setq dabbrev--check-other-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (y-or-n-p "Scan other buffers also? ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (let* (friend-buffer-list non-friend-buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (funcall dabbrev-select-buffers-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (if dabbrev-check-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (setq non-friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (nreverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (dabbrev-filter-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 buffer (buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (not (memq buffer dabbrev--friend-buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (append dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 non-friend-buffer-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 ;; Move buffers that are visible on the screen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 ;; to the front of the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (if dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (let ((w (next-window (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (while (not (eq w (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (cons (window-buffer w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (delq (window-buffer w) dabbrev--friend-buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (setq w (next-window w)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;; Walk through the buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (while (and (not expansion) dabbrev--friend-buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (setq dabbrev--last-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (car dabbrev--friend-buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (setq dabbrev--friend-buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (cdr dabbrev--friend-buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (set-buffer dabbrev--last-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (dabbrev--scanning-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (setq dabbrev--last-expansion-location (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 expansion)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (defun dabbrev--safe-replace-match (string &optional fixedcase literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (if (eq major-mode 'picture-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (picture-replace-match string fixedcase literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (replace-match string fixedcase literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;;; Substitute the current string in buffer with the expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ;;; OLD is nil or the last expansion substring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ;;; ABBREV is the abbreviation we are working with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 ;;; EXPANSION is the expansion substring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (defun dabbrev--substitute-expansion (old abbrev expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ;;(undo-boundary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (let ((use-case-replace (and (eval dabbrev-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (or (not dabbrev-upcase-means-case-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (string= abbrev (downcase abbrev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (eval dabbrev-case-replace))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (and nil use-case-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (setq old (concat abbrev (or old "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (setq expansion (concat abbrev expansion)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
825 ;; If the given abbrev is mixed case and its case pattern
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
826 ;; matches the start of the expansion,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
827 ;; copy the expansion's case
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
828 ;; instead of downcasing all the rest.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
829 (if (and (string= abbrev
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
830 (substring expansion 0 (length abbrev)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
831 (not (string= abbrev (downcase abbrev)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
832 (not (string= abbrev (upcase abbrev))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
833 (setq use-case-replace nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
834 (if (equal abbrev " ")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
835 (setq use-case-replace nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
836 (if use-case-replace
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
837 (setq expansion (downcase expansion)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (search-backward old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ;;(store-match-data (list (point-marker) (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (search-backward abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;; Make case of replacement conform to case of abbreviation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 ;; provided (1) that kind of thing is enabled in this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;; and (2) the replacement itself is all lower case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (dabbrev--safe-replace-match expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (not use-case-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 ;;;----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 ;;; Search function used by dabbrevs library.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;;; ABBREV is string to find as prefix of word. Second arg, REVERSE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ;;; is t for reverse search, nil for forward. Variable dabbrev-limit
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
856 ;;; controls the maximum search region size. Third argument IGNORE-CASE
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ;;; non-nil means treat case as insignificant while looking for a match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ;;; and when comparing with previous matches. Also if that's non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ;;; 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
860 ;;; lower case except for the initial then it is converted to all lower
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 ;;; case for return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;;; Table of expansions already seen is examined in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ;;; `dabbrev--last-table' so that only distinct possibilities are found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ;;; by dabbrev-re-expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 ;;; Value is the expansion, or nil if not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (defun dabbrev--search (abbrev reverse ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (let ((pattern1 (concat (regexp-quote abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 "\\(" dabbrev--abbrev-char-regexp "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (pattern2 (concat (regexp-quote abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (found-string nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;; Limited search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (and dabbrev-limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (narrow-to-region dabbrev--last-expansion-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (+ (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (if reverse (- dabbrev-limit) dabbrev-limit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ;; Look for a distinct expansion, using dabbrev--last-table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;;--------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (while (and (not found-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (if reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (re-search-backward pattern1 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (re-search-forward pattern1 nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 ;; In case we matched in the middle of a word,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ;; back up to start of word and verify we still match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (dabbrev--goto-start-of-abbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (if (not (looking-at pattern1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 ;; We have a truly valid match. Find the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (re-search-forward pattern2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (setq found-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (buffer-substring (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (and ignore-case (setq found-string (downcase found-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 ;; Ignore this match if it's already in the table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (if (dabbrev-filter-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 table-string dabbrev--last-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (string= found-string table-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (setq found-string nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 ;; Prepare to continue searching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (if reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (goto-char (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 ;; If we found something, use it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (if found-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 ;; Put it into `dabbrev--last-table'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 ;; and return it (either downcased, or as is).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (let ((result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (buffer-substring (match-beginning 0) (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (setq dabbrev--last-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (cons found-string dabbrev--last-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (if (and ignore-case (eval dabbrev-case-replace))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
919 ;; XEmacs: FSF has just `result', which makes absolutely
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
920 ;; no sense in this context
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (downcase result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 result)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (provide 'dabbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 ;; dabbrev.el ends here