annotate lisp/abbrev.el @ 4134:ac5a714be3a2

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