annotate lisp/abbrev.el @ 112235:b1eac6d41a93

[Gnus] Update copyright years.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sat, 15 Jan 2011 00:35:35 +0000
parents 417b1e4d63cd
children 61f7601898b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 411
diff changeset
1 ;;; abbrev.el --- abbrev mode commands for Emacs
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
74439
ddcbd2c1b70d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 70268
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 2001, 2002, 2003, 2004,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 108358
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
5
38697
a19197c6442f Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents: 33961
diff changeset
6 ;; Maintainer: FSF
22250
a77d473867b8 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 19307
diff changeset
7 ;; Keywords: abbrev convenience
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 108358
diff changeset
8 ;; Package: emacs
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1329
diff changeset
9
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94356
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94356
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94356
diff changeset
15 ;; (at your option) any later version.
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94356
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
25 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
26
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
27 ;; This facility is documented in the Emacs Manual.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
28
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
29 ;; Todo:
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
30
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
31 ;; - Cleanup name space.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
32
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
33 ;;; Code:
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
35 (eval-when-compile (require 'cl))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
36
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
37 (defgroup abbrev-mode nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
38 "Word abbreviations mode."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
39 :link '(custom-manual "(emacs)Abbrevs")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
40 :group 'abbrev)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
41
104712
c4fb8f245750 * paths.el (abbrev-file-name): Move to abbrev.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104156
diff changeset
42 (defcustom abbrev-file-name
c4fb8f245750 * paths.el (abbrev-file-name): Move to abbrev.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104156
diff changeset
43 (locate-user-emacs-file "abbrev_defs" ".abbrev_defs")
104961
0ea87b098bb0 * custom.el (custom-delayed-init-variables): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104712
diff changeset
44 "Default name of file from which to read abbrevs."
0ea87b098bb0 * custom.el (custom-delayed-init-variables): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104712
diff changeset
45 :initialize 'custom-initialize-delay
104712
c4fb8f245750 * paths.el (abbrev-file-name): Move to abbrev.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104156
diff changeset
46 :type 'file)
c4fb8f245750 * paths.el (abbrev-file-name): Move to abbrev.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104156
diff changeset
47
42560
099200f97432 Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents: 41142
diff changeset
48 (defcustom only-global-abbrevs nil
56576
ceca427e7f83 (only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 56078
diff changeset
49 "Non-nil means user plans to use global abbrevs only.
19307
5745bc43cfe9 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16689
diff changeset
50 This makes the commands that normally define mode-specific abbrevs
5745bc43cfe9 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16689
diff changeset
51 define global abbrevs instead."
5745bc43cfe9 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16689
diff changeset
52 :type 'boolean
22250
a77d473867b8 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 19307
diff changeset
53 :group 'abbrev-mode
a77d473867b8 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 19307
diff changeset
54 :group 'convenience)
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
93513
b97d6aea2d95 (abbrev-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92948
diff changeset
56 (define-minor-mode abbrev-mode
56078
bd7bc33213fd (abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 54134
diff changeset
57 "Toggle Abbrev mode in the current buffer.
78492
7c8949dbfa0d Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
58 With optional argument ARG, turn abbrev mode on if ARG is
7c8949dbfa0d Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
59 positive, otherwise turn it off. In Abbrev mode, inserting an
111222
cdad894f9ed0 Remove duplicate Lisp definitions of define-minor-mode variables defined in C.
Glenn Morris <rgm@gnu.org>
parents: 111202
diff changeset
60 abbreviation causes it to expand and be replaced by its expansion."
cdad894f9ed0 Remove duplicate Lisp definitions of define-minor-mode variables defined in C.
Glenn Morris <rgm@gnu.org>
parents: 111202
diff changeset
61 ;; It's defined in C, this stops the d-m-m macro defining it again.
cdad894f9ed0 Remove duplicate Lisp definitions of define-minor-mode variables defined in C.
Glenn Morris <rgm@gnu.org>
parents: 111202
diff changeset
62 :variable abbrev-mode)
24596
5f4d21e85cf6 (abbrev-mode): Customizing sets the default value.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
63
92948
73a01bf5cb80 * faces.el (xw-defined-colors):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87754
diff changeset
64 (put 'abbrev-mode 'safe-local-variable 'booleanp)
19307
5745bc43cfe9 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16689
diff changeset
65
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
56576
ceca427e7f83 (only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 56078
diff changeset
67 (defvar edit-abbrevs-map
ceca427e7f83 (only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 56078
diff changeset
68 (let ((map (make-sparse-keymap)))
ceca427e7f83 (only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 56078
diff changeset
69 (define-key map "\C-x\C-s" 'edit-abbrevs-redefine)
ceca427e7f83 (only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 56078
diff changeset
70 (define-key map "\C-c\C-c" 'edit-abbrevs-redefine)
ceca427e7f83 (only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 56078
diff changeset
71 map)
56078
bd7bc33213fd (abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 54134
diff changeset
72 "Keymap used in `edit-abbrevs'.")
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 (defun kill-all-abbrevs ()
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 "Undefine all defined abbrevs."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (interactive)
86216
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
77 (dolist (tablesym abbrev-table-name-list)
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
78 (clear-abbrev-table (symbol-value tablesym))))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
47424
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
80 (defun copy-abbrev-table (table)
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
81 "Make a new abbrev-table with the same abbrevs as TABLE."
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
82 (let ((new-table (make-abbrev-table)))
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
83 (mapatoms
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
84 (lambda (symbol)
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
85 (define-abbrev new-table
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
86 (symbol-name symbol)
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
87 (symbol-value symbol)
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
88 (symbol-function symbol)))
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
89 table)
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
90 new-table))
472a93499802 (copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents: 42560
diff changeset
91
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 (defun insert-abbrevs ()
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 "Insert after point a description of all defined abbrevs.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 Mark is set after the inserted text."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (interactive)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 (push-mark
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 (save-excursion
86216
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
98 (dolist (tablesym abbrev-table-name-list)
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
99 (insert-abbrev-table-description tablesym t))
61744
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
100 (point))))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101
31230
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
102 (defun list-abbrevs (&optional local)
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
103 "Display a list of defined abbrevs.
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
104 If LOCAL is non-nil, interactively when invoked with a
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
105 prefix arg, display only local, i.e. mode-specific, abbrevs.
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
106 Otherwise display all abbrevs."
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
107 (interactive "P")
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
108 (display-buffer (prepare-abbrev-list-buffer local)))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109
31230
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
110 (defun abbrev-table-name (table)
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
111 "Value is the name of abbrev table TABLE."
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
112 (let ((tables abbrev-table-name-list)
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
113 found)
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
114 (while (and (not found) tables)
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
115 (when (eq (symbol-value (car tables)) table)
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
116 (setq found (car tables)))
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
117 (setq tables (cdr tables)))
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
118 found))
42560
099200f97432 Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents: 41142
diff changeset
119
31230
200fc9dc31f4 (list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents: 28822
diff changeset
120 (defun prepare-abbrev-list-buffer (&optional local)
112224
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
121 (let ((local-table local-abbrev-table))
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
122 (with-current-buffer (get-buffer-create "*Abbrevs*")
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
123 (erase-buffer)
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
124 (if local
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
125 (insert-abbrev-table-description
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
126 (abbrev-table-name local-table) t)
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
127 (dolist (table abbrev-table-name-list)
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
128 (insert-abbrev-table-description table t)))
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
129 (goto-char (point-min))
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
130 (set-buffer-modified-p nil)
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
131 (edit-abbrevs-mode)
4af12aa726d1 Abbrev.el fix for bug #7733. (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 112218
diff changeset
132 (current-buffer))))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (defun edit-abbrevs-mode ()
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 "Major mode for editing the list of abbrev definitions.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 \\{edit-abbrevs-map}"
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (interactive)
63371
6d35491e8a34 (edit-abbrevs-mode): Use kill-all-local-variables and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents: 61744
diff changeset
138 (kill-all-local-variables)
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (setq major-mode 'edit-abbrevs-mode)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 (setq mode-name "Edit-Abbrevs")
63371
6d35491e8a34 (edit-abbrevs-mode): Use kill-all-local-variables and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents: 61744
diff changeset
141 (use-local-map edit-abbrevs-map)
6d35491e8a34 (edit-abbrevs-mode): Use kill-all-local-variables and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents: 61744
diff changeset
142 (run-mode-hooks 'edit-abbrevs-mode-hook))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (defun edit-abbrevs ()
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 "Alter abbrev definitions by editing a list of them.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 Selects a buffer containing a list of abbrev definitions.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 You can edit them and type \\<edit-abbrevs-map>\\[edit-abbrevs-redefine] to redefine abbrevs
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 according to your editing.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 Buffer contains a header line for each abbrev table,
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 which is the abbrev table name in parentheses.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 This is followed by one line per abbrev in that table:
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 NAME USECOUNT EXPANSION HOOK
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 where NAME and EXPANSION are strings with quotes,
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 USECOUNT is an integer, and HOOK is any valid function
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 or may be omitted (it is usually omitted)."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (interactive)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (switch-to-buffer (prepare-abbrev-list-buffer)))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (defun edit-abbrevs-redefine ()
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 "Redefine abbrevs according to current buffer contents."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (interactive)
70091
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
162 (save-restriction
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
163 (widen)
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
164 (define-abbrevs t)
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
165 (set-buffer-modified-p nil)))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (defun define-abbrevs (&optional arg)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 "Define abbrevs according to current visible buffer contents.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 See documentation of `edit-abbrevs' for info on the format of the
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 text you must have in the buffer.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 With argument, eliminate all abbrev definitions except
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 the ones defined from the buffer now."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (interactive "P")
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (if arg (kill-all-abbrevs))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (save-excursion
61744
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
176 (goto-char (point-min))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
177 (while (and (not (eobp)) (re-search-forward "^(" nil t))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
178 (let* ((buf (current-buffer))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
179 (table (read buf))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
180 abbrevs name hook exp count sys)
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
181 (forward-line 1)
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
182 (while (progn (forward-line 1)
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
183 (not (eolp)))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
184 (setq name (read buf) count (read buf))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
185 (if (equal count '(sys))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
186 (setq sys t count (read buf)))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
187 (setq exp (read buf))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
188 (skip-chars-backward " \t\n\f")
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
189 (setq hook (if (not (eolp)) (read buf)))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
190 (skip-chars-backward " \t\n\f")
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
191 (setq abbrevs (cons (list name exp hook count sys) abbrevs)))
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
192 (define-abbrev-table table abbrevs)))))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (defun read-abbrev-file (&optional file quietly)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 "Read abbrev definitions from file written with `write-abbrev-file'.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 Optional argument FILE is the name of the file to read;
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 it defaults to the value of `abbrev-file-name'.
40904
0f074a905ca2 (read-abbrev-file): Don't set save-abbrevs.
Richard M. Stallman <rms@gnu.org>
parents: 38697
diff changeset
198 Optional second argument QUIETLY non-nil means don't display a message."
70091
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
199 (interactive
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
200 (list
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
201 (read-file-name (format "Read abbrev file (default %s): "
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
202 abbrev-file-name)
4427f1e01f3e (edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents: 69818
diff changeset
203 nil abbrev-file-name t)))
70102
2ae2af972533 (read-abbrev-file): Use abbrev-file-name if optional
Reiner Steib <Reiner.Steib@gmx.de>
parents: 70091
diff changeset
204 (load (or file abbrev-file-name) nil quietly)
40904
0f074a905ca2 (read-abbrev-file): Don't set save-abbrevs.
Richard M. Stallman <rms@gnu.org>
parents: 38697
diff changeset
205 (setq abbrevs-changed nil))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (defun quietly-read-abbrev-file (&optional file)
56576
ceca427e7f83 (only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 56078
diff changeset
208 "Read abbrev definitions from file written with `write-abbrev-file'.
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 Optional argument FILE is the name of the file to read;
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 it defaults to the value of `abbrev-file-name'.
40904
0f074a905ca2 (read-abbrev-file): Don't set save-abbrevs.
Richard M. Stallman <rms@gnu.org>
parents: 38697
diff changeset
211 Does not display any message."
61744
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
212 ;(interactive "fRead abbrev file: ")
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (read-abbrev-file file t))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214
54134
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
215 (defun write-abbrev-file (&optional file)
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
216 "Write all user-level abbrev definitions to a file of Lisp code.
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
217 This does not include system abbrevs; it includes only the abbrev tables
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
218 listed in listed in `abbrev-table-name-list'.
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 The file written can be loaded in another session to define the same abbrevs.
54134
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
220 The argument FILE is the file name to write. If omitted or nil, the file
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
221 specified in `abbrev-file-name' is used."
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (interactive
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (list
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (read-file-name "Write abbrev file: "
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (file-name-directory (expand-file-name abbrev-file-name))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 abbrev-file-name)))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (or (and file (> (length file) 0))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (setq file abbrev-file-name))
49405
7c5f68b0dbd3 (write-abbrev-file): Simplify, and put a coding cookie
Dave Love <fx@gnu.org>
parents: 47654
diff changeset
229 (let ((coding-system-for-write 'emacs-mule))
7c5f68b0dbd3 (write-abbrev-file): Simplify, and put a coding cookie
Dave Love <fx@gnu.org>
parents: 47654
diff changeset
230 (with-temp-file file
7c5f68b0dbd3 (write-abbrev-file): Simplify, and put a coding cookie
Dave Love <fx@gnu.org>
parents: 47654
diff changeset
231 (insert ";;-*-coding: emacs-mule;-*-\n")
61744
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
232 (dolist (table
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
233 ;; We sort the table in order to ease the automatic
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
234 ;; merging of different versions of the user's abbrevs
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
235 ;; file. This is useful, for example, for when the
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
236 ;; user keeps their home directory in a revision
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
237 ;; control system, and is therefore keeping multiple
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
238 ;; slightly-differing copies loosely synchronized.
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
239 (sort (copy-sequence abbrev-table-name-list)
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
240 (lambda (s1 s2)
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
241 (string< (symbol-name s1)
f585c8c92ae1 (write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents: 61448
diff changeset
242 (symbol-name s2)))))
49405
7c5f68b0dbd3 (write-abbrev-file): Simplify, and put a coding cookie
Dave Love <fx@gnu.org>
parents: 47654
diff changeset
243 (insert-abbrev-table-description table nil)))))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (defun add-mode-abbrev (arg)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 "Define mode-specific abbrev for last word(s) before point.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 Argument is how many words before point form the expansion;
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 or zero means the region is the expansion.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 A negative argument means to undefine the specified abbrev.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 Reads the abbreviation in the minibuffer.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 Don't use this function in a Lisp program; use `define-abbrev' instead."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (interactive "p")
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (add-abbrev
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (if only-global-abbrevs
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49405
diff changeset
256 global-abbrev-table
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (or local-abbrev-table
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (error "No per-mode abbrev table")))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 "Mode" arg))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (defun add-global-abbrev (arg)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 "Define global (all modes) abbrev for last word(s) before point.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 The prefix argument specifies the number of words before point that form the
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 expansion; or zero means the region is the expansion.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 A negative argument means to undefine the specified abbrev.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 This command uses the minibuffer to read the abbreviation.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 Don't use this function in a Lisp program; use `define-abbrev' instead."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (interactive "p")
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (add-abbrev global-abbrev-table "Global" arg))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (defun add-abbrev (table type arg)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 (let ((exp (and (>= arg 0)
26079
bc18b027a049 (add-abbrev, inverse-add-abbrev, expand-region-abbrevs): Remove
Dave Love <fx@gnu.org>
parents: 24596
diff changeset
274 (buffer-substring-no-properties
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 (point)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (if (= arg 0) (mark)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (save-excursion (forward-word (- arg)) (point))))))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 name)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (setq name
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (read-string (format (if exp "%s abbrev for \"%s\": "
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 "Undefine %s abbrev: ")
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 type exp)))
9180
569ed1f55710 (add-abbrev, inverse-add-abbrev):
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
283 (set-text-properties 0 (length name) nil name)
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 (if (or (null exp)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (not (abbrev-expansion name table))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (y-or-n-p (format "%s expands to \"%s\"; redefine? "
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 name (abbrev-expansion name table))))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 (define-abbrev table (downcase name) exp))))
42560
099200f97432 Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents: 41142
diff changeset
289
64525
83ccf4fe94c3 (expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
290 (defun inverse-add-mode-abbrev (n)
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 "Define last word before point as a mode-specific abbrev.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 With prefix argument N, defines the Nth word before point.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 This command uses the minibuffer to read the expansion.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 Expands the abbreviation after defining it."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (interactive "p")
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 (inverse-add-abbrev
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (if only-global-abbrevs
42560
099200f97432 Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents: 41142
diff changeset
298 global-abbrev-table
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (or local-abbrev-table
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (error "No per-mode abbrev table")))
64525
83ccf4fe94c3 (expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
301 "Mode" n))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302
64525
83ccf4fe94c3 (expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
303 (defun inverse-add-global-abbrev (n)
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 "Define last word before point as a global (mode-independent) abbrev.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 With prefix argument N, defines the Nth word before point.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 This command uses the minibuffer to read the expansion.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 Expands the abbreviation after defining it."
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 (interactive "p")
64525
83ccf4fe94c3 (expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
309 (inverse-add-abbrev global-abbrev-table "Global" n))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 (defun inverse-add-abbrev (table type arg)
28186
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
312 (let (name exp start end)
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 (save-excursion
28186
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
314 (forward-word (1+ (- arg)))
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
315 (setq end (point))
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
316 (backward-word 1)
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
317 (setq start (point)
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
318 name (buffer-substring-no-properties start end)))
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
319
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
320 (setq exp (read-string (format "%s expansion for \"%s\": " type name)
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
321 nil nil nil t))
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
322 (when (or (not (abbrev-expansion name table))
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
323 (y-or-n-p (format "%s expands to \"%s\"; redefine? "
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
324 name (abbrev-expansion name table))))
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
325 (define-abbrev table (downcase name) exp)
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
326 (save-excursion
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
327 (goto-char end)
a552a942b327 (inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents: 26079
diff changeset
328 (expand-abbrev)))))
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 (defun abbrev-prefix-mark (&optional arg)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 "Mark current point as the beginning of an abbrev.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 Abbrev to be expanded starts here rather than at beginning of word.
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 This way, you can expand an abbrev with a prefix: insert the prefix,
54134
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
334 use this command, then insert the abbrev. This command inserts a
108358
12652a85296d * abbrev.el: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
335 temporary hyphen after the prefix (until the intended abbrev
54134
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
336 expansion occurs).
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
337 If the prefix is itself an abbrev, this command expands it, unless
16aaa8fe949d (write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
338 ARG is non-nil. Interactively, ARG is the prefix argument."
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 (interactive "P")
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (or arg (expand-abbrev))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 (setq abbrev-start-location (point-marker)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 abbrev-start-location-buffer (current-buffer))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (insert "-"))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (defun expand-region-abbrevs (start end &optional noquery)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 "For abbrev occurrence in the region, offer to expand it.
64525
83ccf4fe94c3 (expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
347 The user is asked to type `y' or `n' for each occurrence.
83ccf4fe94c3 (expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
348 A prefix argument means don't query; expand all abbrevs."
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (interactive "r\nP")
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (save-excursion
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (goto-char start)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 (let ((lim (- (point-max) end))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 pnt string)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 (while (and (not (eobp))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 (progn (forward-word 1)
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 (<= (setq pnt (point)) (- (point-max) lim))))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (if (abbrev-expansion
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (setq string
26079
bc18b027a049 (add-abbrev, inverse-add-abbrev, expand-region-abbrevs): Remove
Dave Love <fx@gnu.org>
parents: 24596
diff changeset
359 (buffer-substring-no-properties
411
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (save-excursion (forward-word -1) (point))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 pnt)))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (if (or noquery (y-or-n-p (format "Expand `%s'? " string)))
cb75ab565260 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (expand-abbrev)))))))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 411
diff changeset
364
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
365 ;;; Abbrev properties.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
366
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
367 (defun abbrev-table-get (table prop)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
368 "Get the PROP property of abbrev table TABLE."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
369 (let ((sym (intern-soft "" table)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
370 (if sym (get sym prop))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
371
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
372 (defun abbrev-table-put (table prop val)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
373 "Set the PROP property of abbrev table TABLE to VAL."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
374 (let ((sym (intern "" table)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
375 (set sym nil) ; Make sure it won't be confused for an abbrev.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
376 (put sym prop val)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
377
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
378 (defalias 'abbrev-get 'get
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
379 "Get the property PROP of abbrev ABBREV
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
380
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
381 \(fn ABBREV PROP)")
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
382
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
383 (defalias 'abbrev-put 'put
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
384 "Set the property PROP of abbrev ABREV to value VAL.
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
385 See `define-abbrev' for the effect of some special properties.
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
386
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
387 \(fn ABBREV PROP VAL)")
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
388
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
389 ;;; Code that used to be implemented in src/abbrev.c
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
390
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
391 (defvar abbrev-table-name-list '(fundamental-mode-abbrev-table
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
392 global-abbrev-table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
393 "List of symbols whose values are abbrev tables.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
394
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
395 (defun make-abbrev-table (&optional props)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
396 "Create a new, empty abbrev table object.
94136
d6f5ce5bbc4f Docstring improvements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94135
diff changeset
397 PROPS is a list of properties."
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
398 ;; The value 59 is an arbitrary prime number.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
399 (let ((table (make-vector 59 0)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
400 ;; Each abbrev-table has a `modiff' counter which can be used to detect
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
401 ;; when an abbreviation was added. An example of use would be to
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
402 ;; construct :regexp dynamically as the union of all abbrev names, so
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
403 ;; `modiff' can let us detect that an abbrev was added and hence :regexp
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
404 ;; needs to be refreshed.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
405 ;; The presence of `modiff' entry is also used as a tag indicating this
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
406 ;; vector is really an abbrev-table.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
407 (abbrev-table-put table :abbrev-table-modiff 0)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
408 (while (consp props)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
409 (abbrev-table-put table (pop props) (pop props)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
410 table))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
411
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
412 (defun abbrev-table-p (object)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
413 (and (vectorp object)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
414 (numberp (abbrev-table-get object :abbrev-table-modiff))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
415
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
416 (defvar global-abbrev-table (make-abbrev-table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
417 "The abbrev table whose abbrevs affect all buffers.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
418 Each buffer may also have a local abbrev table.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
419 If it does, the local table overrides the global one
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
420 for any particular abbrev defined in both.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
421
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
422 (defvar abbrev-minor-mode-table-alist nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
423 "Alist of abbrev tables to use for minor modes.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
424 Each element looks like (VARIABLE . ABBREV-TABLE);
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
425 ABBREV-TABLE is active whenever VARIABLE's value is non-nil.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
426
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
427 (defvar fundamental-mode-abbrev-table
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
428 (let ((table (make-abbrev-table)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
429 ;; Set local-abbrev-table's default to be fundamental-mode-abbrev-table.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
430 (setq-default local-abbrev-table table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
431 table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
432 "The abbrev table of mode-specific abbrevs for Fundamental Mode.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
433
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
434 (defvar abbrevs-changed nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
435 "Set non-nil by defining or altering any word abbrevs.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
436 This causes `save-some-buffers' to offer to save the abbrevs.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
437
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
438 (defcustom abbrev-all-caps nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
439 "Non-nil means expand multi-word abbrevs all caps if abbrev was so."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
440 :type 'boolean
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
441 :group 'abbrev-mode)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
442
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
443 (defvar abbrev-start-location nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
444 "Buffer position for `expand-abbrev' to use as the start of the abbrev.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
445 When nil, use the word before point as the abbrev.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
446 Calling `expand-abbrev' sets this to nil.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
447
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
448 (defvar abbrev-start-location-buffer nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
449 "Buffer that `abbrev-start-location' has been set for.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
450 Trying to expand an abbrev in any other buffer clears `abbrev-start-location'.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
451
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
452 (defvar last-abbrev nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
453 "The abbrev-symbol of the last abbrev expanded. See `abbrev-symbol'.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
454
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
455 (defvar last-abbrev-text nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
456 "The exact text of the last abbrev expanded.
108358
12652a85296d * abbrev.el: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
457 It is nil if the abbrev has already been unexpanded.")
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
458
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
459 (defvar last-abbrev-location 0
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
460 "The location of the start of the last abbrev expanded.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
461
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
462 ;; (defvar local-abbrev-table fundamental-mode-abbrev-table
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
463 ;; "Local (mode-specific) abbrev table of current buffer.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
464 ;; (make-variable-buffer-local 'local-abbrev-table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
465
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
466 (defcustom pre-abbrev-expand-hook nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
467 "Function or functions to be called before abbrev expansion is done.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
468 This is the first thing that `expand-abbrev' does, and so this may change
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
469 the current abbrev table before abbrev lookup happens."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
470 :type 'hook
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
471 :group 'abbrev-mode)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
472 (make-obsolete-variable 'pre-abbrev-expand-hook 'abbrev-expand-functions "23.1")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
473
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
474 (defun clear-abbrev-table (table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
475 "Undefine all abbrevs in abbrev table TABLE, leaving it empty."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
476 (setq abbrevs-changed t)
86216
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
477 (let* ((sym (intern-soft "" table)))
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
478 (dotimes (i (length table))
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
479 (aset table i 0))
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
480 ;; Preserve the table's properties.
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
481 (assert sym)
87754
2957493cf354 (clear-abbrev-table): Can't pass a symbol to intern.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
482 (let ((newsym (intern "" table)))
2957493cf354 (clear-abbrev-table): Can't pass a symbol to intern.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
483 (set newsym nil) ; Make sure it won't be confused for an abbrev.
2957493cf354 (clear-abbrev-table): Can't pass a symbol to intern.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
484 (setplist newsym (symbol-plist sym)))
86216
93c3f233e481 (kill-all-abbrevs, insert-abbrevs, prepare-abbrev-list-buffer): Use dolist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86158
diff changeset
485 (abbrev-table-put table :abbrev-table-modiff
102351
a11b9c55c39c (clear-abbrev-table): Always return nil (Bug#2515).
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
486 (1+ (abbrev-table-get table :abbrev-table-modiff))))
102352
c61c29e47d6a Add comment.
Chong Yidong <cyd@stupidchicken.com>
parents: 102351
diff changeset
487 ;; For backward compatibility, always return nil.
102351
a11b9c55c39c (clear-abbrev-table): Always return nil (Bug#2515).
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
488 nil)
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
489
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
490 (defun define-abbrev (table name expansion &optional hook &rest props)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
491 "Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
492 NAME must be a string, and should be lower-case.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
493 EXPANSION should usually be a string.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
494 To undefine an abbrev, define it with EXPANSION = nil.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
495 If HOOK is non-nil, it should be a function of no arguments;
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
496 it is called after EXPANSION is inserted.
98808
8ed760341617 (define-abbrev): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 95571
diff changeset
497 If EXPANSION is not a string (and not nil), the abbrev is a
8ed760341617 (define-abbrev): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 95571
diff changeset
498 special one, which does not expand in the usual way but only
8ed760341617 (define-abbrev): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 95571
diff changeset
499 runs HOOK.
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
500
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
501 PROPS is a property list. The following properties are special:
94136
d6f5ce5bbc4f Docstring improvements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94135
diff changeset
502 - `:count': the value for the abbrev's usage-count, which is incremented each
d6f5ce5bbc4f Docstring improvements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94135
diff changeset
503 time the abbrev is used (the default is zero).
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
504 - `:system': if non-nil, says that this is a \"system\" abbreviation
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
505 which should not be saved in the user's abbreviation file.
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
506 Unless `:system' is `force', a system abbreviation will not
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
507 overwrite a non-system abbreviation of the same name.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
508 - `:case-fixed': non-nil means that abbreviations are looked up without
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
509 case-folding, and the expansion is not capitalized/upcased.
94356
4b4c0c613ce9 (define-abbrev): Don't use `iff' in doc-strings.
Glenn Morris <rgm@gnu.org>
parents: 94353
diff changeset
510 - `:enable-function': a function of no argument which returns non-nil if the
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
511 abbrev should be used for a particular call of `expand-abbrev'.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
512
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
513 An obsolete but still supported calling form is:
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
514
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
515 \(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM)."
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
516 (when (and (consp props) (or (null (car props)) (numberp (car props))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
517 ;; Old-style calling convention.
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
518 (setq props (list* :count (car props)
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
519 (if (cadr props) (list :system (cadr props))))))
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
520 (unless (plist-get props :count)
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
521 (setq props (plist-put props :count 0)))
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
522 (let ((system-flag (plist-get props :system))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
523 (sym (intern name table)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
524 ;; Don't override a prior user-defined abbrev with a system abbrev,
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
525 ;; unless system-flag is `force'.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
526 (unless (and (not (memq system-flag '(nil force)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
527 (boundp sym) (symbol-value sym)
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
528 (not (abbrev-get sym :system)))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
529 (unless (or system-flag
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
530 (and (boundp sym) (fboundp sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
531 ;; load-file-name
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
532 (equal (symbol-value sym) expansion)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
533 (equal (symbol-function sym) hook)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
534 (setq abbrevs-changed t))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
535 (set sym expansion)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
536 (fset sym hook)
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
537 (setplist sym
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
538 ;; Don't store the `force' value of `system-flag' into
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
539 ;; the :system property.
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
540 (if (eq 'force system-flag) (plist-put props :system t) props))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
541 (abbrev-table-put table :abbrev-table-modiff
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
542 (1+ (abbrev-table-get table :abbrev-table-modiff))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
543 name))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
544
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
545 (defun abbrev--check-chars (abbrev global)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
546 "Check if the characters in ABBREV have word syntax in either the
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
547 current (if global is nil) or standard syntax table."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
548 (with-syntax-table
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
549 (cond ((null global) (standard-syntax-table))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
550 ;; ((syntax-table-p global) global)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
551 (t (syntax-table)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
552 (when (string-match "\\W" abbrev)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
553 (let ((badchars ())
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
554 (pos 0))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
555 (while (string-match "\\W" abbrev pos)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
556 (pushnew (aref abbrev (match-beginning 0)) badchars)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
557 (setq pos (1+ pos)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
558 (error "Some abbrev characters (%s) are not word constituents %s"
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
559 (apply 'string (nreverse badchars))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
560 (if global "in the standard syntax" "in this mode"))))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
561
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
562 (defun define-global-abbrev (abbrev expansion)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
563 "Define ABBREV as a global abbreviation for EXPANSION.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
564 The characters in ABBREV must all be word constituents in the standard
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
565 syntax table."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
566 (interactive "sDefine global abbrev: \nsExpansion for %s: ")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
567 (abbrev--check-chars abbrev 'global)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
568 (define-abbrev global-abbrev-table (downcase abbrev) expansion))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
569
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
570 (defun define-mode-abbrev (abbrev expansion)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
571 "Define ABBREV as a mode-specific abbreviation for EXPANSION.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
572 The characters in ABBREV must all be word-constituents in the current mode."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
573 (interactive "sDefine mode abbrev: \nsExpansion for %s: ")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
574 (unless local-abbrev-table
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
575 (error "Major mode has no abbrev table"))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
576 (abbrev--check-chars abbrev nil)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
577 (define-abbrev local-abbrev-table (downcase abbrev) expansion))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
578
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
579 (defun abbrev--active-tables (&optional tables)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
580 "Return the list of abbrev tables currently active.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
581 TABLES if non-nil overrides the usual rules. It can hold
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
582 either a single abbrev table or a list of abbrev tables."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
583 ;; We could just remove the `tables' arg and let callers use
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
584 ;; (or table (abbrev--active-tables)) but then they'd have to be careful
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
585 ;; to treat the distinction between a single table and a list of tables.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
586 (cond
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
587 ((consp tables) tables)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
588 ((vectorp tables) (list tables))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
589 (t
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
590 (let ((tables (if (listp local-abbrev-table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
591 (append local-abbrev-table
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
592 (list global-abbrev-table))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
593 (list local-abbrev-table global-abbrev-table))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
594 ;; Add the minor-mode abbrev tables.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
595 (dolist (x abbrev-minor-mode-table-alist)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
596 (when (and (symbolp (car x)) (boundp (car x)) (symbol-value (car x)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
597 (setq tables
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
598 (if (listp (cdr x))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
599 (append (cdr x) tables) (cons (cdr x) tables)))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
600 tables))))
85923
a6bcf6e8ed42 (define-abbrev-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 85920
diff changeset
601
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
602
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
603 (defun abbrev-symbol (abbrev &optional table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
604 "Return the symbol representing abbrev named ABBREV.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
605 This symbol's name is ABBREV, but it is not the canonical symbol of that name;
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
606 it is interned in an abbrev-table rather than the normal obarray.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
607 The value is nil if that abbrev is not defined.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
608 Optional second arg TABLE is abbrev table to look it up in.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
609 The default is to try buffer's mode-specific abbrev table, then global table."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
610 (let ((tables (abbrev--active-tables table))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
611 sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
612 (while (and tables (not (symbol-value sym)))
85837
07865f189760 (abbrev-symbol): Correct let->let*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85773
diff changeset
613 (let* ((table (pop tables))
07865f189760 (abbrev-symbol): Correct let->let*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85773
diff changeset
614 (case-fold (not (abbrev-table-get table :case-fixed))))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
615 (setq tables (append (abbrev-table-get table :parents) tables))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
616 ;; In case the table doesn't set :case-fixed but some of the
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
617 ;; abbrevs do, we have to be careful.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
618 (setq sym
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
619 ;; First try without case-folding.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
620 (or (intern-soft abbrev table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
621 (when case-fold
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
622 ;; We didn't find any abbrev, try case-folding.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
623 (let ((sym (intern-soft (downcase abbrev) table)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
624 ;; Only use it if it doesn't require :case-fixed.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
625 (and sym (not (abbrev-get sym :case-fixed))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
626 sym)))))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
627 (if (symbol-value sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
628 sym)))
85923
a6bcf6e8ed42 (define-abbrev-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 85920
diff changeset
629
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
630
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
631 (defun abbrev-expansion (abbrev &optional table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
632 "Return the string that ABBREV expands into in the current buffer.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
633 Optionally specify an abbrev table as second arg;
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
634 then ABBREV is looked up in that table only."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
635 (symbol-value (abbrev-symbol abbrev table)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
636
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
637
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
638 (defun abbrev--before-point ()
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
639 "Try and find an abbrev before point. Return it if found, nil otherwise."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
640 (unless (eq abbrev-start-location-buffer (current-buffer))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
641 (setq abbrev-start-location nil))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
642
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
643 (let ((tables (abbrev--active-tables))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
644 (pos (point))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
645 start end name res)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
646
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
647 (if abbrev-start-location
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
648 (progn
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
649 (setq start abbrev-start-location)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
650 (setq abbrev-start-location nil)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
651 ;; Remove the hyphen inserted by `abbrev-prefix-mark'.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
652 (if (and (< start (point-max))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
653 (eq (char-after start) ?-))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
654 (delete-region start (1+ start)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
655 (skip-syntax-backward " ")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
656 (setq end (point))
85837
07865f189760 (abbrev-symbol): Correct let->let*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85773
diff changeset
657 (when (> end start)
07865f189760 (abbrev-symbol): Correct let->let*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85773
diff changeset
658 (setq name (buffer-substring start end))
07865f189760 (abbrev-symbol): Correct let->let*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85773
diff changeset
659 (goto-char pos) ; Restore point.
07865f189760 (abbrev-symbol): Correct let->let*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85773
diff changeset
660 (list (abbrev-symbol name tables) name start end)))
85923
a6bcf6e8ed42 (define-abbrev-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 85920
diff changeset
661
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
662 (while (and tables (not (car res)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
663 (let* ((table (pop tables))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
664 (enable-fun (abbrev-table-get table :enable-function)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
665 (setq tables (append (abbrev-table-get table :parents) tables))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
666 (setq res
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
667 (and (or (not enable-fun) (funcall enable-fun))
106233
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
668 (let ((re (abbrev-table-get table :regexp)))
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
669 (if (null re)
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
670 ;; We used to default `re' to "\\<\\(\\w+\\)\\W*"
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
671 ;; but when words-include-escapes is set, that
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
672 ;; is not right and fixing it is boring.
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
673 (let ((lim (point)))
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
674 (backward-word 1)
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
675 (setq start (point))
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
676 (forward-word 1)
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
677 (setq end (min (point) lim)))
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
678 (when (looking-back re (line-beginning-position))
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
679 (setq start (match-beginning 1))
13733fc37569 (abbrev--before-point): Use word-motion functions
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106109
diff changeset
680 (setq end (match-end 1)))))
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
681 (setq name (buffer-substring start end))
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
682 (let ((abbrev (abbrev-symbol name table)))
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
683 (when abbrev
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
684 (setq enable-fun (abbrev-get abbrev :enable-function))
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
685 (and (or (not enable-fun) (funcall enable-fun))
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
686 ;; This will also look it up in parent tables.
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
687 ;; This is not on purpose, but it seems harmless.
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
688 (list abbrev name start end))))))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
689 ;; Restore point.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
690 (goto-char pos)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
691 res)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
692
94137
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
693 (defun abbrev-insert (abbrev &optional name wordstart wordend)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
694 "Insert abbrev ABBREV at point.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
695 If non-nil, NAME is the name by which this abbrev was found.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
696 If non-nil, WORDSTART is the place where to insert the abbrev.
103215
bbd292613696 Minor doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 102352
diff changeset
697 If WORDEND is non-nil, the abbrev replaces the previous text between
94137
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
698 WORDSTART and WORDEND.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
699 Return ABBREV if the expansion should be considered as having taken place."
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
700 (unless name (setq name (symbol-name abbrev)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
701 (unless wordstart (setq wordstart (point)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
702 (unless wordend (setq wordend wordstart))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
703 ;; Increment use count.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
704 (abbrev-put abbrev :count (1+ (abbrev-get abbrev :count)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
705 (let ((value abbrev))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
706 ;; If this abbrev has an expansion, delete the abbrev
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
707 ;; and insert the expansion.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
708 (when (stringp (symbol-value abbrev))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
709 (goto-char wordstart)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
710 ;; Insert at beginning so that markers at the end (e.g. point)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
711 ;; are preserved.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
712 (insert (symbol-value abbrev))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
713 (delete-char (- wordend wordstart))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
714 (let ((case-fold-search nil))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
715 ;; If the abbrev's name is different from the buffer text (the
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
716 ;; only difference should be capitalization), then we may want
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
717 ;; to adjust the capitalization of the expansion.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
718 (when (and (not (equal name (symbol-name abbrev)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
719 (string-match "[[:upper:]]" name))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
720 (if (not (string-match "[[:lower:]]" name))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
721 ;; Abbrev was all caps. If expansion is multiple words,
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
722 ;; normally capitalize each word.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
723 (if (and (not abbrev-all-caps)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
724 (save-excursion
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
725 (> (progn (backward-word 1) (point))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
726 (progn (goto-char wordstart)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
727 (forward-word 1) (point)))))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
728 (upcase-initials-region wordstart (point))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
729 (upcase-region wordstart (point)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
730 ;; Abbrev included some caps. Cap first initial of expansion.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
731 (let ((end (point)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
732 ;; Find the initial.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
733 (goto-char wordstart)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
734 (skip-syntax-forward "^w" (1- end))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
735 ;; Change just that.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
736 (upcase-initials-region (point) (1+ (point)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
737 (goto-char end))))))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
738 ;; Now point is at the end of the expansion and the beginning is
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
739 ;; in last-abbrev-location.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
740 (when (symbol-function abbrev)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
741 (let* ((hook (symbol-function abbrev))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
742 (expanded
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
743 ;; If the abbrev has a hook function, run it.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
744 (funcall hook)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
745 ;; In addition, if the hook function is a symbol with
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
746 ;; a non-nil `no-self-insert' property, let the value it
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
747 ;; returned specify whether we consider that an expansion took
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
748 ;; place. If it returns nil, no expansion has been done.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
749 (if (and (symbolp hook)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
750 (null expanded)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
751 (get hook 'no-self-insert))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
752 (setq value nil))))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
753 value))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
754
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
755 (defvar abbrev-expand-functions nil
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
756 "Wrapper hook around `expand-abbrev'.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
757 The functions on this special hook are called with one argument:
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
758 a function that performs the abbrev expansion. It should return
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
759 the abbrev symbol if expansion took place.")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
760
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
761 (defun expand-abbrev ()
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
762 "Expand the abbrev before point, if there is an abbrev there.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
763 Effective when explicitly called even when `abbrev-mode' is nil.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
764 Returns the abbrev symbol, if expansion took place."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
765 (interactive)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
766 (run-hooks 'pre-abbrev-expand-hook)
106109
42ca82b4620b * abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104961
diff changeset
767 (with-wrapper-hook abbrev-expand-functions ()
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
768 (destructuring-bind (&optional sym name wordstart wordend)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
769 (abbrev--before-point)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
770 (when sym
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
771 (let ((value sym))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
772 (unless (or ;; executing-kbd-macro
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
773 noninteractive
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
774 (window-minibuffer-p (selected-window)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
775 ;; Add an undo boundary, in case we are doing this for
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
776 ;; a self-inserting command which has avoided making one so far.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
777 (undo-boundary))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
778 ;; Now sym is the abbrev symbol.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
779 (setq last-abbrev-text name)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
780 (setq last-abbrev sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
781 (setq last-abbrev-location wordstart)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
782 ;; If this abbrev has an expansion, delete the abbrev
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
783 ;; and insert the expansion.
94137
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
784 (abbrev-insert sym name wordstart wordend))))))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
785
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
786 (defun unexpand-abbrev ()
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
787 "Undo the expansion of the last abbrev that expanded.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
788 This differs from ordinary undo in that other editing done since then
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
789 is not undone."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
790 (interactive)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
791 (save-excursion
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
792 (unless (or (< last-abbrev-location (point-min))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
793 (> last-abbrev-location (point-max)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
794 (goto-char last-abbrev-location)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
795 (when (stringp last-abbrev-text)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
796 ;; This isn't correct if last-abbrev's hook was used
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
797 ;; to do the expansion.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
798 (let ((val (symbol-value last-abbrev)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
799 (unless (stringp val)
95571
49efb79bb63b (unexpand-abbrev): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94733
diff changeset
800 (error "Value of abbrev-symbol must be a string"))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
801 ;; Don't inherit properties here; just copy from old contents.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
802 (insert last-abbrev-text)
95571
49efb79bb63b (unexpand-abbrev): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94733
diff changeset
803 ;; Delete after inserting, to better preserve markers.
49efb79bb63b (unexpand-abbrev): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94733
diff changeset
804 (delete-region (point) (+ (point) (length val)))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
805 (setq last-abbrev-text nil))))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
806
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
807 (defun abbrev--write (sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
808 "Write the abbrev in a `read'able form.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
809 Only writes the non-system abbrevs.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
810 Presumes that `standard-output' points to `current-buffer'."
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
811 (unless (or (null (symbol-value sym)) (abbrev-get sym :system))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
812 (insert " (")
86158
61154518604b (abbrev--write): Fix error in transcription from C.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85991
diff changeset
813 (prin1 (symbol-name sym))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
814 (insert " ")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
815 (prin1 (symbol-value sym))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
816 (insert " ")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
817 (prin1 (symbol-function sym))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
818 (insert " ")
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
819 (prin1 (abbrev-get sym :count))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
820 (insert ")\n")))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
821
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
822 (defun abbrev--describe (sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
823 (when (symbol-value sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
824 (prin1 (symbol-name sym))
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
825 (if (null (abbrev-get sym :system))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
826 (indent-to 15 1)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
827 (insert " (sys)")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
828 (indent-to 20 1))
85773
13ae285f009a Rename `count' and `system-flag' to :count and :system. Update all users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85710
diff changeset
829 (prin1 (abbrev-get sym :count))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
830 (indent-to 20 1)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
831 (prin1 (symbol-value sym))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
832 (when (symbol-function sym)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
833 (indent-to 45 1)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
834 (prin1 (symbol-function sym)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
835 (terpri)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
836
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
837 (defun insert-abbrev-table-description (name &optional readable)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
838 "Insert before point a full description of abbrev table named NAME.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
839 NAME is a symbol whose value is an abbrev table.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
840 If optional 2nd arg READABLE is non-nil, a human-readable description
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
841 is inserted. Otherwise the description is an expression,
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
842 a call to `define-abbrev-table', which would
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
843 define the abbrev table NAME exactly as it is currently defined.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
844
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
845 Abbrevs marked as \"system abbrevs\" are omitted."
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
846 (let ((table (symbol-value name))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
847 (symbols ()))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
848 (mapatoms (lambda (sym) (if (symbol-value sym) (push sym symbols))) table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
849 (setq symbols (sort symbols 'string-lessp))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
850 (let ((standard-output (current-buffer)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
851 (if readable
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
852 (progn
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
853 (insert "(")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
854 (prin1 name)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
855 (insert ")\n\n")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
856 (mapc 'abbrev--describe symbols)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
857 (insert "\n\n"))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
858 (insert "(define-abbrev-table '")
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
859 (prin1 name)
104156
226d6219da5a * abbrev.el (insert-abbrev-table-description): Prettify output.
Chong Yidong <cyd@stupidchicken.com>
parents: 103215
diff changeset
860 (if (null symbols)
226d6219da5a * abbrev.el (insert-abbrev-table-description): Prettify output.
Chong Yidong <cyd@stupidchicken.com>
parents: 103215
diff changeset
861 (insert " '())\n\n")
226d6219da5a * abbrev.el (insert-abbrev-table-description): Prettify output.
Chong Yidong <cyd@stupidchicken.com>
parents: 103215
diff changeset
862 (insert "\n '(\n")
226d6219da5a * abbrev.el (insert-abbrev-table-description): Prettify output.
Chong Yidong <cyd@stupidchicken.com>
parents: 103215
diff changeset
863 (mapc 'abbrev--write symbols)
226d6219da5a * abbrev.el (insert-abbrev-table-description): Prettify output.
Chong Yidong <cyd@stupidchicken.com>
parents: 103215
diff changeset
864 (insert " ))\n\n")))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
865 nil)))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
866
94135
ad63f799c98d (define-abbrev-table): Fontify dosctrings as such.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93513
diff changeset
867 (put 'define-abbrev-table 'doc-string-elt 3)
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
868 (defun define-abbrev-table (tablename definitions
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
869 &optional docstring &rest props)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
870 "Define TABLENAME (a symbol) as an abbrev table name.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
871 Define abbrevs in it according to DEFINITIONS, which is a list of elements
94136
d6f5ce5bbc4f Docstring improvements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94135
diff changeset
872 of the form (ABBREVNAME EXPANSION ...) that are passed to `define-abbrev'.
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
873 PROPS is a property list to apply to the table.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
874 Properties with special meaning:
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
875 - `:parents' contains a list of abbrev tables from which this table inherits
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
876 abbreviations.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
877 - `:case-fixed' non-nil means that abbreviations are looked up without
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
878 case-folding, and the expansion is not capitalized/upcased.
85923
a6bcf6e8ed42 (define-abbrev-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 85920
diff changeset
879 - `:regexp' describes the form of abbrevs. It defaults to \\=\\<\\(\\w+\\)\\W* which
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
880 means that an abbrev can only be a single word. The submatch 1 is treated
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
881 as the potential name of an abbrev.
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
882 - `:enable-function' can be set to a function of no argument which returns
94733
67bcaf883753 (define-abbrev-table): Don't use `iff' in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
883 non-nil if and only if the abbrevs in this table should be used for this
67bcaf883753 (define-abbrev-table): Don't use `iff' in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
884 instance of `expand-abbrev'."
85991
dd802e6c104e (define-abbrev-table): Record the variable definition.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85925
diff changeset
885 ;; We used to manually add the docstring, but we also want to record this
dd802e6c104e (define-abbrev-table): Record the variable definition.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85925
diff changeset
886 ;; location as the definition of the variable (in load-history), so we may
dd802e6c104e (define-abbrev-table): Record the variable definition.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85925
diff changeset
887 ;; as well just use `defvar'.
dd802e6c104e (define-abbrev-table): Record the variable definition.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85925
diff changeset
888 (eval `(defvar ,tablename nil ,@(if (stringp docstring) (list docstring))))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
889 (let ((table (if (boundp tablename) (symbol-value tablename))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
890 (unless table
94353
f7eb2887e5b5 (define-abbrev-table): Apply props even if the table exists already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94137
diff changeset
891 (setq table (make-abbrev-table))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
892 (set tablename table)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
893 (push tablename abbrev-table-name-list))
94353
f7eb2887e5b5 (define-abbrev-table): Apply props even if the table exists already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94137
diff changeset
894 ;; We used to just pass them to `make-abbrev-table', but that fails
f7eb2887e5b5 (define-abbrev-table): Apply props even if the table exists already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94137
diff changeset
895 ;; if the table was pre-existing as is the case if it was created by
f7eb2887e5b5 (define-abbrev-table): Apply props even if the table exists already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94137
diff changeset
896 ;; loading the user's abbrev file.
f7eb2887e5b5 (define-abbrev-table): Apply props even if the table exists already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94137
diff changeset
897 (while (consp props)
f7eb2887e5b5 (define-abbrev-table): Apply props even if the table exists already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94137
diff changeset
898 (abbrev-table-put table (pop props) (pop props)))
85710
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
899 (dolist (elt definitions)
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
900 (apply 'define-abbrev table elt))))
beb909dfc54d Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78492
diff changeset
901
94137
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
902 (defun abbrev-table-menu (table &optional prompt sortfun)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
903 "Return a menu that shows all abbrevs in TABLE.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
904 Selecting an entry runs `abbrev-insert'.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
905 PROMPT is the prompt to use for the keymap.
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
906 SORTFUN is passed to `sort' to change the default ordering."
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
907 (unless sortfun (setq sortfun 'string-lessp))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
908 (let ((entries ()))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
909 (mapatoms (lambda (abbrev)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
910 (when (symbol-value abbrev)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
911 (let ((name (symbol-name abbrev)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
912 (push `(,(intern name) menu-item ,name
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
913 (lambda () (interactive)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
914 (abbrev-insert ',abbrev)))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
915 entries))))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
916 table)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
917 (nconc (make-sparse-keymap prompt)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
918 (sort entries (lambda (x y)
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
919 (funcall sortfun (nth 2 x) (nth 2 y)))))))
b745a29952ba (abbrev-insert): New function extracted from expand-abbrev.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94136
diff changeset
920
76421
1a0fcbc9da8c (abbrev): Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents: 75347
diff changeset
921 (provide 'abbrev)
1a0fcbc9da8c (abbrev): Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents: 75347
diff changeset
922
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 411
diff changeset
923 ;;; abbrev.el ends here