2
|
1 ;;; abbrev.el --- abbrev mode commands for Emacs
|
0
|
2
|
2
|
3 ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Keywords: abbrev
|
0
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
|
23
|
|
24 ;;; Synched up with: FSF 19.34 (With some additions)
|
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; This facility is documented in the Emacs Manual.
|
|
29
|
|
30 ;;; Code:
|
0
|
31
|
|
32 ;jwz: this is preloaded so don't ;;;###autoload
|
2
|
33 (defconst only-global-abbrevs nil "\
|
|
34 *t means user plans to use global abbrevs only.
|
|
35 Makes the commands to define mode-specific abbrevs define global ones instead.")
|
0
|
36
|
2
|
37 ;;; XEmacs: the following block of code is not in FSF
|
0
|
38 (defvar abbrev-table-name-list '()
|
|
39 "List of symbols whose values are abbrev tables.")
|
|
40
|
|
41 (defvar abbrevs-changed nil
|
|
42 "Set non-nil by defining or altering any word abbrevs.
|
|
43 This causes `save-some-buffers' to offer to save the abbrevs.")
|
|
44
|
|
45 (defun make-abbrev-table ()
|
|
46 "Create a new, empty abbrev table object."
|
|
47 (make-vector 59 0)) ; 59 is prime
|
|
48
|
|
49 (defun clear-abbrev-table (table)
|
|
50 "Undefine all abbrevs in abbrev table TABLE, leaving it empty."
|
|
51 (fillarray table 0)
|
|
52 (setq abbrevs-changed t)
|
|
53 nil)
|
|
54
|
|
55
|
|
56 (defun define-abbrev-table (name defs)
|
|
57 "Define TABNAME (a symbol) as an abbrev table name.
|
|
58 Define abbrevs in it according to DEFINITIONS, which is a list of elements
|
|
59 of the form (ABBREVNAME EXPANSION HOOK USECOUNT)."
|
|
60 (let ((table (and (boundp name) (symbol-value name))))
|
|
61 (cond ((vectorp table))
|
|
62 ((not table)
|
|
63 (setq table (make-abbrev-table))
|
|
64 (set name table)
|
|
65 (setq abbrev-table-name-list (cons name abbrev-table-name-list)))
|
|
66 (t
|
|
67 (setq table (signal 'wrong-type-argument (list 'vectorp table)))
|
|
68 (set name table)))
|
|
69 (while defs
|
|
70 (apply (function define-abbrev) table (car defs))
|
|
71 (setq defs (cdr defs)))))
|
|
72
|
|
73 (defun define-abbrev (table name &optional expansion hook count)
|
|
74 "Define an abbrev in TABLE named NAME, to expand to EXPANSION or call HOOK.
|
|
75 NAME and EXPANSION are strings. Hook is a function or `nil'.
|
|
76 To undefine an abbrev, define with the an expansion of `nil'."
|
|
77 (or (not expansion)
|
|
78 (stringp expansion)
|
|
79 (setq expansion (signal 'wrong-type-argument
|
|
80 (list 'stringp expansion))))
|
|
81 (or (not count)
|
|
82 (integerp count)
|
|
83 (setq count (signal 'wrong-type-argument
|
|
84 (list 'fixnump count))))
|
|
85 (let* ((sym (intern name table))
|
|
86 (oexp (and (boundp sym) (symbol-value sym)))
|
|
87 (ohook (and (fboundp sym) (symbol-function sym))))
|
|
88 (if (not (and (equal ohook hook)
|
|
89 (stringp oexp)
|
|
90 (stringp expansion)
|
|
91 (string-equal oexp expansion)))
|
|
92 (setq abbrevs-changed t))
|
|
93 (set sym expansion)
|
|
94 (fset sym hook)
|
|
95 (setplist sym (or count 0))
|
|
96 name))
|
|
97
|
|
98
|
|
99 ;; Fixup stuff from bootstrap def of define-abbrev-table in subr.el
|
|
100 (let ((l abbrev-table-name-list))
|
|
101 (while l
|
|
102 (let ((fixup (car l)))
|
|
103 (if (consp fixup)
|
|
104 (progn
|
|
105 (setq abbrev-table-name-list (delq fixup abbrev-table-name-list))
|
|
106 (define-abbrev-table (car fixup) (cdr fixup))))
|
|
107 (setq l (cdr l))))
|
|
108 ;; These are no longer initialised by C code
|
|
109 (if (not global-abbrev-table)
|
|
110 (progn
|
|
111 (setq global-abbrev-table (make-abbrev-table))
|
|
112 (setq abbrev-table-name-list (cons 'global-abbrev-table
|
|
113 abbrev-table-name-list))))
|
|
114 (if (not fundamental-mode-abbrev-table)
|
|
115 (progn
|
|
116 (setq fundamental-mode-abbrev-table (make-abbrev-table))
|
|
117 (setq abbrev-table-name-list (cons 'fundamental-mode-abbrev-table
|
|
118 abbrev-table-name-list))))
|
|
119 (and (eq major-mode 'fundamental-mode)
|
|
120 (not local-abbrev-table)
|
|
121 (setq local-abbrev-table fundamental-mode-abbrev-table)))
|
|
122
|
|
123
|
|
124 (defun define-global-abbrev (name expansion)
|
|
125 "Define ABBREV as a global abbreviation for EXPANSION."
|
|
126 (interactive "sDefine global abbrev: \nsExpansion for %s: ")
|
|
127 (define-abbrev global-abbrev-table
|
|
128 (downcase name) expansion nil 0))
|
|
129
|
|
130 (defun define-mode-abbrev (name expansion)
|
|
131 "Define ABBREV as a mode-specific abbreviation for EXPANSION."
|
|
132 (interactive "sDefine mode abbrev: \nsExpansion for %s: ")
|
|
133 (define-abbrev (or local-abbrev-table
|
|
134 (error "Major mode has no abbrev table"))
|
|
135 (downcase name) nil 0))
|
|
136
|
|
137 (defun abbrev-symbol (abbrev &optional table)
|
|
138 "Return the symbol representing abbrev named ABBREV.
|
|
139 This symbol's name is ABBREV, but it is not the canonical symbol of that name;
|
|
140 it is interned in an abbrev-table rather than the normal obarray.
|
|
141 The value is nil if that abbrev is not defined.
|
|
142 Optional second arg TABLE is abbrev table to look it up in.
|
|
143 The default is to try buffer's mode-specific abbrev table, then global table."
|
|
144 (let ((frob (function (lambda (table)
|
|
145 (let ((sym (intern-soft abbrev table)))
|
|
146 (if (and (boundp sym)
|
|
147 (stringp (symbol-value sym)))
|
|
148 sym
|
|
149 nil))))))
|
|
150 (if table
|
|
151 (funcall frob table)
|
|
152 (or (and local-abbrev-table
|
|
153 (funcall frob local-abbrev-table))
|
|
154 (funcall frob global-abbrev-table)))))
|
|
155
|
|
156 (defun abbrev-expansion (abbrev &optional table)
|
|
157 "Return the string that ABBREV expands into in the current buffer.
|
|
158 Optionally specify an abbrev table as second arg;
|
|
159 then ABBREV is looked up in that table only."
|
|
160 (let ((sym (abbrev-symbol abbrev table)))
|
|
161 (if sym
|
|
162 (symbol-value sym)
|
|
163 nil)))
|
|
164
|
|
165 (defun unexpand-abbrev ()
|
|
166 "Undo the expansion of the last abbrev that expanded.
|
|
167 This differs from ordinary undo in that other editing done since then
|
|
168 is not undone."
|
|
169 (interactive)
|
|
170 (if (or (< last-abbrev-location (point-min))
|
|
171 (> last-abbrev-location (point-max))
|
|
172 (not (stringp last-abbrev-text)))
|
|
173 nil
|
|
174 (let* ((opoint (point))
|
|
175 (val (symbol-value last-abbrev))
|
|
176 (adjust (length val)))
|
|
177 ;; This isn't correct if (symbol-function last-abbrev-text)
|
|
178 ;; was used to do the expansion
|
|
179 (goto-char last-abbrev-location)
|
|
180 (delete-region last-abbrev-location (+ last-abbrev-location adjust))
|
|
181 (insert last-abbrev-text)
|
|
182 (setq adjust (- adjust (length last-abbrev-text)))
|
|
183 (setq last-abbrev-text nil)
|
|
184 (if (< last-abbrev-location opoint)
|
|
185 (goto-char (- opoint adjust))
|
|
186 (goto-char opoint)))))
|
|
187
|
|
188
|
|
189
|
|
190 (defun insert-abbrev-table-description (name human-readable)
|
|
191 "Insert before point a full description of abbrev table named NAME.
|
|
192 NAME is a symbol whose value is an abbrev table.
|
|
193 If optional 2nd arg HUMAN is non-nil, insert a human-readable description.
|
|
194 Otherwise the description is an expression,
|
|
195 a call to `define-abbrev-table', which would
|
|
196 define the abbrev table NAME exactly as it is currently defined."
|
|
197 (let ((table (symbol-value name))
|
|
198 (stream (current-buffer)))
|
|
199 (message "Abbrev-table %s..." name)
|
|
200 (if human-readable
|
|
201 (progn
|
|
202 (prin1 (list name) stream)
|
|
203 ;; Need two terpri's or cretinous edit-abbrevs blows out
|
|
204 (terpri stream)
|
|
205 (terpri stream)
|
|
206 (mapatoms (function (lambda (sym)
|
|
207 (if (symbol-value sym)
|
|
208 (let* ((n (prin1-to-string (symbol-name sym)))
|
|
209 (pos (length n)))
|
|
210 (princ n stream)
|
|
211 (while (< pos 14)
|
|
212 (write-char ?\ stream)
|
|
213 (setq pos (1+ pos)))
|
|
214 (princ (format " %-5S " (symbol-plist sym))
|
|
215 stream)
|
|
216 (if (not (symbol-function sym))
|
|
217 (prin1 (symbol-value sym) stream)
|
|
218 (progn
|
|
219 (setq n (prin1-to-string (symbol-value sym))
|
|
220 pos (+ pos 6 (length n)))
|
|
221 (princ n stream)
|
|
222 (while (< pos 45)
|
|
223 (write-char ?\ stream)
|
|
224 (setq pos (1+ pos)))
|
|
225 (prin1 (symbol-function sym) stream)))
|
|
226 (terpri stream)))))
|
|
227 table)
|
|
228 (terpri stream))
|
|
229 (progn
|
|
230 (princ "\(define-abbrev-table '" stream)
|
|
231 (prin1 name stream)
|
|
232 (princ " '\(\n" stream)
|
|
233 (mapatoms (function (lambda (sym)
|
|
234 (if (symbol-value sym)
|
|
235 (progn
|
|
236 (princ " " stream)
|
|
237 (prin1 (list (symbol-name sym)
|
|
238 (symbol-value sym)
|
|
239 (symbol-function sym)
|
|
240 (symbol-plist sym))
|
|
241 stream)
|
|
242 (terpri stream)))))
|
|
243 table)
|
|
244 (princ " \)\)\n" stream)))
|
|
245 (terpri stream))
|
|
246 (message ""))
|
2
|
247 ;;; End code not in FSF
|
0
|
248
|
|
249 (defun abbrev-mode (arg)
|
|
250 "Toggle abbrev mode.
|
2
|
251 With argument ARG, turn abbrev mode on iff ARG is positive.
|
0
|
252 In abbrev mode, inserting an abbreviation causes it to expand
|
|
253 and be replaced by its expansion."
|
|
254 (interactive "P")
|
|
255 (setq abbrev-mode
|
|
256 (if (null arg) (not abbrev-mode)
|
|
257 (> (prefix-numeric-value arg) 0)))
|
2
|
258 ;; XEmacs change
|
0
|
259 (redraw-modeline))
|
|
260
|
|
261
|
|
262 (defvar edit-abbrevs-map nil
|
|
263 "Keymap used in edit-abbrevs.")
|
|
264 (if edit-abbrevs-map
|
|
265 nil
|
|
266 (setq edit-abbrevs-map (make-sparse-keymap))
|
2
|
267 ;; XEmacs change
|
0
|
268 (set-keymap-name edit-abbrevs-map 'edit-abbrevs-map)
|
|
269 (define-key edit-abbrevs-map "\C-x\C-s" 'edit-abbrevs-redefine)
|
|
270 (define-key edit-abbrevs-map "\C-c\C-c" 'edit-abbrevs-redefine))
|
|
271
|
|
272 (defun kill-all-abbrevs ()
|
|
273 "Undefine all defined abbrevs."
|
|
274 (interactive)
|
|
275 (let ((tables abbrev-table-name-list))
|
|
276 (while tables
|
|
277 (clear-abbrev-table (symbol-value (car tables)))
|
|
278 (setq tables (cdr tables)))))
|
|
279
|
|
280 (defun insert-abbrevs ()
|
|
281 "Insert after point a description of all defined abbrevs.
|
|
282 Mark is set after the inserted text."
|
|
283 (interactive)
|
|
284 (push-mark
|
|
285 (save-excursion
|
|
286 (let ((tables abbrev-table-name-list))
|
|
287 (while tables
|
|
288 (insert-abbrev-table-description (car tables) t)
|
|
289 (setq tables (cdr tables))))
|
|
290 (point))))
|
|
291
|
|
292 (defun list-abbrevs ()
|
|
293 "Display a list of all defined abbrevs."
|
|
294 (interactive)
|
|
295 (display-buffer (prepare-abbrev-list-buffer)))
|
|
296
|
|
297 (defun prepare-abbrev-list-buffer ()
|
|
298 (save-excursion
|
|
299 (set-buffer (get-buffer-create "*Abbrevs*"))
|
|
300 (erase-buffer)
|
|
301 (let ((tables abbrev-table-name-list))
|
|
302 (while tables
|
|
303 (insert-abbrev-table-description (car tables) t)
|
|
304 (setq tables (cdr tables))))
|
|
305 (goto-char (point-min))
|
|
306 (set-buffer-modified-p nil)
|
|
307 (edit-abbrevs-mode))
|
|
308 (get-buffer-create "*Abbrevs*"))
|
|
309
|
|
310 (defun edit-abbrevs-mode ()
|
|
311 "Major mode for editing the list of abbrev definitions.
|
|
312 \\{edit-abbrevs-map}"
|
|
313 (interactive)
|
|
314 (setq major-mode 'edit-abbrevs-mode)
|
|
315 (setq mode-name "Edit-Abbrevs")
|
|
316 (use-local-map edit-abbrevs-map))
|
|
317
|
|
318 (defun edit-abbrevs ()
|
|
319 "Alter abbrev definitions by editing a list of them.
|
|
320 Selects a buffer containing a list of abbrev definitions.
|
2
|
321 You can edit them and type \\<edit-abbrevs-map>\\[edit-abbrevs-redefine] to redefine abbrevs
|
0
|
322 according to your editing.
|
|
323 Buffer contains a header line for each abbrev table,
|
|
324 which is the abbrev table name in parentheses.
|
|
325 This is followed by one line per abbrev in that table:
|
|
326 NAME USECOUNT EXPANSION HOOK
|
|
327 where NAME and EXPANSION are strings with quotes,
|
|
328 USECOUNT is an integer, and HOOK is any valid function
|
|
329 or may be omitted (it is usually omitted)."
|
|
330 (interactive)
|
|
331 (switch-to-buffer (prepare-abbrev-list-buffer)))
|
|
332
|
|
333 (defun edit-abbrevs-redefine ()
|
|
334 "Redefine abbrevs according to current buffer contents."
|
|
335 (interactive)
|
|
336 (define-abbrevs t)
|
|
337 (set-buffer-modified-p nil))
|
|
338
|
|
339 (defun define-abbrevs (&optional arg)
|
|
340 "Define abbrevs according to current visible buffer contents.
|
2
|
341 See documentation of `edit-abbrevs' for info on the format of the
|
0
|
342 text you must have in the buffer.
|
|
343 With argument, eliminate all abbrev definitions except
|
|
344 the ones defined from the buffer now."
|
|
345 (interactive "P")
|
|
346 (if arg (kill-all-abbrevs))
|
|
347 (save-excursion
|
|
348 (goto-char (point-min))
|
|
349 (while (and (not (eobp)) (re-search-forward "^(" nil t))
|
|
350 (let* ((buf (current-buffer))
|
|
351 (table (read buf))
|
2
|
352 abbrevs name hook exp count)
|
0
|
353 (forward-line 1)
|
|
354 (while (progn (forward-line 1)
|
|
355 (not (eolp)))
|
2
|
356 (setq name (read buf) count (read buf) exp (read buf))
|
|
357 (skip-chars-backward " \t\n\f")
|
|
358 (setq hook (if (not (eolp)) (read buf)))
|
|
359 (skip-chars-backward " \t\n\f")
|
|
360 (setq abbrevs (cons (list name exp hook count) abbrevs)))
|
0
|
361 (define-abbrev-table table abbrevs)))))
|
|
362
|
|
363 (defun read-abbrev-file (&optional file quietly)
|
2
|
364 "Read abbrev definitions from file written with `write-abbrev-file'.
|
|
365 Optional argument FILE is the name of the file to read;
|
|
366 it defaults to the value of `abbrev-file-name'.
|
|
367 Optional second argument QUIETLY non-nil means don't print anything."
|
0
|
368 (interactive "fRead abbrev file: ")
|
|
369 (load (if (and file (> (length file) 0)) file abbrev-file-name)
|
|
370 nil quietly)
|
|
371 (setq save-abbrevs t abbrevs-changed nil))
|
|
372
|
|
373 (defun quietly-read-abbrev-file (&optional file)
|
|
374 "Read abbrev definitions from file written with write-abbrev-file.
|
2
|
375 Optional argument FILE is the name of the file to read;
|
|
376 it defaults to the value of `abbrev-file-name'.
|
|
377 Does not print anything."
|
0
|
378 ;(interactive "fRead abbrev file: ")
|
|
379 (read-abbrev-file file t))
|
|
380
|
|
381 (defun write-abbrev-file (file)
|
2
|
382 "Write all abbrev definitions to a file of Lisp code.
|
|
383 The file written can be loaded in another session to define the same abbrevs.
|
|
384 The argument FILE is the file name to write."
|
0
|
385 (interactive
|
|
386 (list
|
|
387 (read-file-name "Write abbrev file: "
|
|
388 (file-name-directory (expand-file-name abbrev-file-name))
|
|
389 abbrev-file-name)))
|
|
390 (or (and file (> (length file) 0))
|
|
391 (setq file abbrev-file-name))
|
|
392 (save-excursion
|
|
393 (set-buffer (get-buffer-create " write-abbrev-file"))
|
|
394 (erase-buffer)
|
|
395 (let ((tables abbrev-table-name-list))
|
|
396 (while tables
|
|
397 (insert-abbrev-table-description (car tables) nil)
|
|
398 (setq tables (cdr tables))))
|
|
399 (write-region 1 (point-max) file)
|
|
400 (erase-buffer)))
|
|
401
|
|
402 (defun add-mode-abbrev (arg)
|
2
|
403 "Define mode-specific abbrev for last word(s) before point.
|
0
|
404 Argument is how many words before point form the expansion;
|
|
405 or zero means the region is the expansion.
|
|
406 A negative argument means to undefine the specified abbrev.
|
|
407 Reads the abbreviation in the minibuffer.
|
|
408
|
2
|
409 Don't use this function in a Lisp program; use `define-abbrev' instead."
|
0
|
410 ;; XEmacs change:
|
|
411 (interactive "P")
|
2
|
412 (add-abbrev
|
|
413 (if only-global-abbrevs
|
|
414 global-abbrev-table
|
|
415 (or local-abbrev-table
|
|
416 (error "No per-mode abbrev table")))
|
|
417 "Mode" arg))
|
0
|
418
|
|
419 (defun add-global-abbrev (arg)
|
2
|
420 "Define global (all modes) abbrev for last word(s) before point.
|
|
421 The prefix argument specifies the number of words before point that form the
|
|
422 expansion; or zero means the region is the expansion.
|
0
|
423 A negative argument means to undefine the specified abbrev.
|
2
|
424 This command uses the minibuffer to read the abbreviation.
|
0
|
425
|
2
|
426 Don't use this function in a Lisp program; use `define-abbrev' instead."
|
0
|
427 ;; XEmacs change:
|
|
428 (interactive "P")
|
|
429 (add-abbrev global-abbrev-table "Global" arg))
|
|
430
|
|
431 (defun add-abbrev (table type arg)
|
|
432 ;; XEmacs change:
|
|
433 (if (and (not arg) (region-active-p)) (setq arg 0)
|
|
434 (setq arg (prefix-numeric-value arg)))
|
|
435 (let ((exp (and (>= arg 0)
|
|
436 (buffer-substring
|
|
437 (point)
|
|
438 (if (= arg 0) (mark)
|
|
439 (save-excursion (forward-word (- arg)) (point))))))
|
|
440 name)
|
|
441 (setq name
|
|
442 (read-string (format (if exp "%s abbrev for \"%s\": "
|
|
443 "Undefine %s abbrev: ")
|
|
444 type exp)))
|
2
|
445 (set-text-properties 0 (length name) nil name)
|
0
|
446 (if (or (null exp)
|
|
447 (not (abbrev-expansion name table))
|
|
448 (y-or-n-p (format "%s expands to \"%s\"; redefine? "
|
|
449 name (abbrev-expansion name table))))
|
|
450 (define-abbrev table (downcase name) exp))))
|
|
451
|
|
452 (defun inverse-add-mode-abbrev (arg)
|
|
453 "Define last word before point as a mode-specific abbrev.
|
2
|
454 With prefix argument N, defines the Nth word before point.
|
|
455 This command uses the minibuffer to read the expansion.
|
0
|
456 Expands the abbreviation after defining it."
|
|
457 (interactive "p")
|
2
|
458 (inverse-add-abbrev
|
|
459 (if only-global-abbrevs
|
|
460 global-abbrev-table
|
|
461 (or local-abbrev-table
|
|
462 (error "No per-mode abbrev table")))
|
|
463 "Mode" arg))
|
0
|
464
|
|
465 (defun inverse-add-global-abbrev (arg)
|
|
466 "Define last word before point as a global (mode-independent) abbrev.
|
2
|
467 With prefix argument N, defines the Nth word before point.
|
|
468 This command uses the minibuffer to read the expansion.
|
0
|
469 Expands the abbreviation after defining it."
|
|
470 (interactive "p")
|
|
471 (inverse-add-abbrev global-abbrev-table "Global" arg))
|
|
472
|
|
473 (defun inverse-add-abbrev (table type arg)
|
|
474 (let (name nameloc exp)
|
|
475 (save-excursion
|
|
476 (forward-word (- arg))
|
|
477 (setq name (buffer-substring (point) (progn (forward-word 1)
|
|
478 (setq nameloc (point))))))
|
2
|
479 (set-text-properties 0 (length name) nil name)
|
0
|
480 (setq exp (read-string (format "%s expansion for \"%s\": "
|
|
481 type name)))
|
|
482 (if (or (not (abbrev-expansion name table))
|
|
483 (y-or-n-p (format "%s expands to \"%s\"; redefine? "
|
|
484 name (abbrev-expansion name table))))
|
|
485 (progn
|
|
486 (define-abbrev table (downcase name) exp)
|
|
487 (save-excursion
|
|
488 (goto-char nameloc)
|
|
489 (expand-abbrev))))))
|
|
490
|
|
491 (defun abbrev-prefix-mark (&optional arg)
|
|
492 "Mark current point as the beginning of an abbrev.
|
2
|
493 Abbrev to be expanded starts here rather than at beginning of word.
|
|
494 This way, you can expand an abbrev with a prefix: insert the prefix,
|
|
495 use this command, then insert the abbrev."
|
0
|
496 (interactive "P")
|
|
497 (or arg (expand-abbrev))
|
|
498 (setq abbrev-start-location (point-marker)
|
|
499 abbrev-start-location-buffer (current-buffer))
|
|
500 (insert "-"))
|
|
501
|
|
502 (defun expand-region-abbrevs (start end &optional noquery)
|
|
503 "For abbrev occurrence in the region, offer to expand it.
|
|
504 The user is asked to type y or n for each occurrence.
|
2
|
505 A prefix argument means don't query; expand all abbrevs.
|
|
506 If called from a Lisp program, arguments are START END &optional NOQUERY."
|
0
|
507 (interactive "r\nP")
|
|
508 (save-excursion
|
|
509 (goto-char start)
|
|
510 (let ((lim (- (point-max) end))
|
|
511 pnt string)
|
|
512 (while (and (not (eobp))
|
|
513 (progn (forward-word 1)
|
|
514 (<= (setq pnt (point)) (- (point-max) lim))))
|
|
515 (if (abbrev-expansion
|
|
516 (setq string
|
|
517 (buffer-substring
|
|
518 (save-excursion (forward-word -1) (point))
|
|
519 pnt)))
|
|
520 (if (or noquery (y-or-n-p (format "Expand `%s'? " string)))
|
|
521 (expand-abbrev)))))))
|
2
|
522
|
|
523 ;;; abbrev.el ends here
|