annotate lisp/modes/abbrev.el @ 124:9b50b4588a93 r20-1b15

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