annotate lisp/modes/abbrev.el @ 173:8eaf7971accc r20-3b13

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