annotate lisp/abbrev.el @ 442:abe6d1db359e r21-2-36

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