annotate lisp/modes/abbrev.el @ 0:376386a54a3c r19-14

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