Mercurial > emacs
annotate lisp/abbrev.el @ 85720:79ffe1cb3583
(isearch-other-meta-char): Call `isearch-edit-string' when mouse is
clicked on the isearch message.
(isearch-resume): Call `isearch-update' at the end. Rename argument
`search' to `string' to conform to the isearch terminology.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Sun, 28 Oct 2007 14:49:07 +0000 |
parents | beb909dfc54d |
children | 13ae285f009a |
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 | 2 |
74439 | 3 ;; Copyright (C) 1985, 1986, 1987, 1992, 2001, 2002, 2003, 2004, |
75347 | 4 ;; 2005, 2006, 2007 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 |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1329
diff
changeset
|
8 |
411 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
76421
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
411 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
411 | 25 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
26 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
28 ;; 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
|
29 |
85710
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
30 ;; Todo: |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
31 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
32 ;; - Make abbrev-file-name obey user-emacs-directory. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
33 ;; - Cleanup name space. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
34 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
35 ;;; Code: |
411 | 36 |
85710
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
37 (eval-when-compile (require 'cl)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
38 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
39 (defgroup abbrev-mode nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
40 "Word abbreviations mode." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
41 :link '(custom-manual "(emacs)Abbrevs") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
42 :group 'abbrev) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
43 |
42560
099200f97432
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
41142
diff
changeset
|
44 (defcustom only-global-abbrevs nil |
56576
ceca427e7f83
(only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents:
56078
diff
changeset
|
45 "Non-nil means user plans to use global abbrevs only. |
19307 | 46 This makes the commands that normally define mode-specific abbrevs |
47 define global abbrevs instead." | |
48 :type 'boolean | |
22250
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
19307
diff
changeset
|
49 :group 'abbrev-mode |
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
19307
diff
changeset
|
50 :group 'convenience) |
411 | 51 |
28822
1c03ffa9c07d
(abbrev-mode): Make ARG optional.
Gerd Moellmann <gerd@gnu.org>
parents:
28186
diff
changeset
|
52 (defun abbrev-mode (&optional arg) |
56078
bd7bc33213fd
(abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
54134
diff
changeset
|
53 "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
|
54 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
|
55 positive, otherwise turn it off. In Abbrev mode, inserting an |
7c8949dbfa0d
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78236
diff
changeset
|
56 abbreviation causes it to expand and be replaced by its expansion." |
411 | 57 (interactive "P") |
58 (setq abbrev-mode | |
59 (if (null arg) (not abbrev-mode) | |
60 (> (prefix-numeric-value arg) 0))) | |
11558
03792bb111ab
(abbrev-mode): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
9180
diff
changeset
|
61 (force-mode-line-update)) |
19307 | 62 |
63 (defcustom abbrev-mode nil | |
56078
bd7bc33213fd
(abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
54134
diff
changeset
|
64 "Enable or disable Abbrev mode. |
24596
5f4d21e85cf6
(abbrev-mode): Customizing sets the default value.
Richard M. Stallman <rms@gnu.org>
parents:
24550
diff
changeset
|
65 Non-nil means automatically expand abbrevs as they are inserted. |
5f4d21e85cf6
(abbrev-mode): Customizing sets the default value.
Richard M. Stallman <rms@gnu.org>
parents:
24550
diff
changeset
|
66 |
56078
bd7bc33213fd
(abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
54134
diff
changeset
|
67 Setting this variable with `setq' changes it for the current buffer. |
24596
5f4d21e85cf6
(abbrev-mode): Customizing sets the default value.
Richard M. Stallman <rms@gnu.org>
parents:
24550
diff
changeset
|
68 Changing it with \\[customize] sets the default value. |
56078
bd7bc33213fd
(abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
54134
diff
changeset
|
69 Interactively, use the command `abbrev-mode' |
bd7bc33213fd
(abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
54134
diff
changeset
|
70 to enable or disable Abbrev mode in the current buffer." |
19307 | 71 :type 'boolean |
72 :group 'abbrev-mode) | |
70268
8fb69c1e87e8
(abbrev-mode): Tighten the safety predicate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70216
diff
changeset
|
73 ;;;###autoload(put 'abbrev-mode 'safe-local-variable 'booleanp) |
19307 | 74 |
411 | 75 |
56576
ceca427e7f83
(only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents:
56078
diff
changeset
|
76 (defvar edit-abbrevs-map |
ceca427e7f83
(only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents:
56078
diff
changeset
|
77 (let ((map (make-sparse-keymap))) |
ceca427e7f83
(only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents:
56078
diff
changeset
|
78 (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
|
79 (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
|
80 map) |
56078
bd7bc33213fd
(abbrev-mode, edit-abbrevs-map): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
54134
diff
changeset
|
81 "Keymap used in `edit-abbrevs'.") |
411 | 82 |
83 (defun kill-all-abbrevs () | |
84 "Undefine all defined abbrevs." | |
85 (interactive) | |
86 (let ((tables abbrev-table-name-list)) | |
87 (while tables | |
88 (clear-abbrev-table (symbol-value (car tables))) | |
89 (setq tables (cdr tables))))) | |
90 | |
47424
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
91 (defun copy-abbrev-table (table) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
92 "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
|
93 (let ((new-table (make-abbrev-table))) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
94 (mapatoms |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
95 (lambda (symbol) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
96 (define-abbrev new-table |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
97 (symbol-name symbol) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
98 (symbol-value symbol) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
99 (symbol-function symbol))) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
100 table) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
101 new-table)) |
472a93499802
(copy-abbrev-table): New function.
Richard M. Stallman <rms@gnu.org>
parents:
42560
diff
changeset
|
102 |
411 | 103 (defun insert-abbrevs () |
104 "Insert after point a description of all defined abbrevs. | |
105 Mark is set after the inserted text." | |
106 (interactive) | |
107 (push-mark | |
108 (save-excursion | |
61744
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
109 (let ((tables abbrev-table-name-list)) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
110 (while tables |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
111 (insert-abbrev-table-description (car tables) t) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
112 (setq tables (cdr tables)))) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
113 (point)))) |
411 | 114 |
31230
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
115 (defun list-abbrevs (&optional local) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
116 "Display a list of defined abbrevs. |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
117 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
|
118 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
|
119 Otherwise display all abbrevs." |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
120 (interactive "P") |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
121 (display-buffer (prepare-abbrev-list-buffer local))) |
411 | 122 |
31230
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
123 (defun abbrev-table-name (table) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
124 "Value is the name of abbrev table TABLE." |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
125 (let ((tables abbrev-table-name-list) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
126 found) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
127 (while (and (not found) tables) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
128 (when (eq (symbol-value (car tables)) table) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
129 (setq found (car tables))) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
130 (setq tables (cdr tables))) |
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
131 found)) |
42560
099200f97432
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
41142
diff
changeset
|
132 |
31230
200fc9dc31f4
(list-abbrevs): Add optional parameter LOCAL.
Gerd Moellmann <gerd@gnu.org>
parents:
28822
diff
changeset
|
133 (defun prepare-abbrev-list-buffer (&optional local) |
411 | 134 (save-excursion |
33961
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
135 (let ((table local-abbrev-table)) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
136 (set-buffer (get-buffer-create "*Abbrevs*")) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
137 (erase-buffer) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
138 (if local |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
139 (insert-abbrev-table-description (abbrev-table-name table) t) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
140 (dolist (table abbrev-table-name-list) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
141 (insert-abbrev-table-description table t))) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
142 (goto-char (point-min)) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
143 (set-buffer-modified-p nil) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
144 (edit-abbrevs-mode) |
f7744f7fd432
(prepare-abbrev-list-buffer): Get the value of
Gerd Moellmann <gerd@gnu.org>
parents:
31230
diff
changeset
|
145 (current-buffer)))) |
411 | 146 |
147 (defun edit-abbrevs-mode () | |
148 "Major mode for editing the list of abbrev definitions. | |
149 \\{edit-abbrevs-map}" | |
150 (interactive) | |
63371
6d35491e8a34
(edit-abbrevs-mode): Use kill-all-local-variables and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
61744
diff
changeset
|
151 (kill-all-local-variables) |
411 | 152 (setq major-mode 'edit-abbrevs-mode) |
153 (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
|
154 (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
|
155 (run-mode-hooks 'edit-abbrevs-mode-hook)) |
411 | 156 |
157 (defun edit-abbrevs () | |
158 "Alter abbrev definitions by editing a list of them. | |
159 Selects a buffer containing a list of abbrev definitions. | |
160 You can edit them and type \\<edit-abbrevs-map>\\[edit-abbrevs-redefine] to redefine abbrevs | |
161 according to your editing. | |
162 Buffer contains a header line for each abbrev table, | |
163 which is the abbrev table name in parentheses. | |
164 This is followed by one line per abbrev in that table: | |
165 NAME USECOUNT EXPANSION HOOK | |
166 where NAME and EXPANSION are strings with quotes, | |
167 USECOUNT is an integer, and HOOK is any valid function | |
168 or may be omitted (it is usually omitted)." | |
169 (interactive) | |
170 (switch-to-buffer (prepare-abbrev-list-buffer))) | |
171 | |
172 (defun edit-abbrevs-redefine () | |
173 "Redefine abbrevs according to current buffer contents." | |
174 (interactive) | |
70091
4427f1e01f3e
(edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents:
69818
diff
changeset
|
175 (save-restriction |
4427f1e01f3e
(edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents:
69818
diff
changeset
|
176 (widen) |
4427f1e01f3e
(edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents:
69818
diff
changeset
|
177 (define-abbrevs t) |
4427f1e01f3e
(edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents:
69818
diff
changeset
|
178 (set-buffer-modified-p nil))) |
411 | 179 |
180 (defun define-abbrevs (&optional arg) | |
181 "Define abbrevs according to current visible buffer contents. | |
182 See documentation of `edit-abbrevs' for info on the format of the | |
183 text you must have in the buffer. | |
184 With argument, eliminate all abbrev definitions except | |
185 the ones defined from the buffer now." | |
186 (interactive "P") | |
187 (if arg (kill-all-abbrevs)) | |
188 (save-excursion | |
61744
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
189 (goto-char (point-min)) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
190 (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
|
191 (let* ((buf (current-buffer)) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
192 (table (read buf)) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
193 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
|
194 (forward-line 1) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
195 (while (progn (forward-line 1) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
196 (not (eolp))) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
197 (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
|
198 (if (equal count '(sys)) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
199 (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
|
200 (setq exp (read buf)) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
201 (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
|
202 (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
|
203 (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
|
204 (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
|
205 (define-abbrev-table table abbrevs))))) |
411 | 206 |
207 (defun read-abbrev-file (&optional file quietly) | |
208 "Read abbrev definitions from file written with `write-abbrev-file'. | |
209 Optional argument FILE is the name of the file to read; | |
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 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
|
212 (interactive |
4427f1e01f3e
(edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents:
69818
diff
changeset
|
213 (list |
4427f1e01f3e
(edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents:
69818
diff
changeset
|
214 (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
|
215 abbrev-file-name) |
4427f1e01f3e
(edit-abbrevs-redefine): Temporarily widen.
Richard M. Stallman <rms@gnu.org>
parents:
69818
diff
changeset
|
216 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
|
217 (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
|
218 (setq abbrevs-changed nil)) |
411 | 219 |
220 (defun quietly-read-abbrev-file (&optional file) | |
56576
ceca427e7f83
(only-global-abbrevs): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents:
56078
diff
changeset
|
221 "Read abbrev definitions from file written with `write-abbrev-file'. |
411 | 222 Optional argument FILE is the name of the file to read; |
223 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
|
224 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
|
225 ;(interactive "fRead abbrev file: ") |
411 | 226 (read-abbrev-file file t)) |
227 | |
54134
16aaa8fe949d
(write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
228 (defun write-abbrev-file (&optional file) |
16aaa8fe949d
(write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
229 "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
|
230 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
|
231 listed in listed in `abbrev-table-name-list'. |
411 | 232 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
|
233 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
|
234 specified in `abbrev-file-name' is used." |
411 | 235 (interactive |
236 (list | |
237 (read-file-name "Write abbrev file: " | |
238 (file-name-directory (expand-file-name abbrev-file-name)) | |
239 abbrev-file-name))) | |
240 (or (and file (> (length file) 0)) | |
241 (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
|
242 (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
|
243 (with-temp-file file |
7c5f68b0dbd3
(write-abbrev-file): Simplify, and put a coding cookie
Dave Love <fx@gnu.org>
parents:
47654
diff
changeset
|
244 (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
|
245 (dolist (table |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
246 ;; 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
|
247 ;; 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
|
248 ;; 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
|
249 ;; 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
|
250 ;; 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
|
251 ;; slightly-differing copies loosely synchronized. |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
252 (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
|
253 (lambda (s1 s2) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
254 (string< (symbol-name s1) |
f585c8c92ae1
(write-abbrev-file): Write table entries in alphabetical order
Eli Zaretskii <eliz@gnu.org>
parents:
61448
diff
changeset
|
255 (symbol-name s2))))) |
49405
7c5f68b0dbd3
(write-abbrev-file): Simplify, and put a coding cookie
Dave Love <fx@gnu.org>
parents:
47654
diff
changeset
|
256 (insert-abbrev-table-description table nil))))) |
411 | 257 |
258 (defun add-mode-abbrev (arg) | |
259 "Define mode-specific abbrev for last word(s) before point. | |
260 Argument is how many words before point form the expansion; | |
261 or zero means the region is the expansion. | |
262 A negative argument means to undefine the specified abbrev. | |
263 Reads the abbreviation in the minibuffer. | |
264 | |
265 Don't use this function in a Lisp program; use `define-abbrev' instead." | |
266 (interactive "p") | |
267 (add-abbrev | |
268 (if only-global-abbrevs | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49405
diff
changeset
|
269 global-abbrev-table |
411 | 270 (or local-abbrev-table |
271 (error "No per-mode abbrev table"))) | |
272 "Mode" arg)) | |
273 | |
274 (defun add-global-abbrev (arg) | |
275 "Define global (all modes) abbrev for last word(s) before point. | |
276 The prefix argument specifies the number of words before point that form the | |
277 expansion; or zero means the region is the expansion. | |
278 A negative argument means to undefine the specified abbrev. | |
279 This command uses the minibuffer to read the abbreviation. | |
280 | |
281 Don't use this function in a Lisp program; use `define-abbrev' instead." | |
282 (interactive "p") | |
283 (add-abbrev global-abbrev-table "Global" arg)) | |
284 | |
285 (defun add-abbrev (table type arg) | |
286 (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
|
287 (buffer-substring-no-properties |
411 | 288 (point) |
289 (if (= arg 0) (mark) | |
290 (save-excursion (forward-word (- arg)) (point)))))) | |
291 name) | |
292 (setq name | |
293 (read-string (format (if exp "%s abbrev for \"%s\": " | |
294 "Undefine %s abbrev: ") | |
295 type exp))) | |
9180
569ed1f55710
(add-abbrev, inverse-add-abbrev):
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
296 (set-text-properties 0 (length name) nil name) |
411 | 297 (if (or (null exp) |
298 (not (abbrev-expansion name table)) | |
299 (y-or-n-p (format "%s expands to \"%s\"; redefine? " | |
300 name (abbrev-expansion name table)))) | |
301 (define-abbrev table (downcase name) exp)))) | |
42560
099200f97432
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
41142
diff
changeset
|
302 |
64525
83ccf4fe94c3
(expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
303 (defun inverse-add-mode-abbrev (n) |
411 | 304 "Define last word before point as a mode-specific abbrev. |
305 With prefix argument N, defines the Nth word before point. | |
306 This command uses the minibuffer to read the expansion. | |
307 Expands the abbreviation after defining it." | |
308 (interactive "p") | |
309 (inverse-add-abbrev | |
310 (if only-global-abbrevs | |
42560
099200f97432
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
41142
diff
changeset
|
311 global-abbrev-table |
411 | 312 (or local-abbrev-table |
313 (error "No per-mode abbrev table"))) | |
64525
83ccf4fe94c3
(expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
314 "Mode" n)) |
411 | 315 |
64525
83ccf4fe94c3
(expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
316 (defun inverse-add-global-abbrev (n) |
411 | 317 "Define last word before point as a global (mode-independent) abbrev. |
318 With prefix argument N, defines the Nth word before point. | |
319 This command uses the minibuffer to read the expansion. | |
320 Expands the abbreviation after defining it." | |
321 (interactive "p") | |
64525
83ccf4fe94c3
(expand-region-abbrevs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
322 (inverse-add-abbrev global-abbrev-table "Global" n)) |
411 | 323 |
324 (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
|
325 (let (name exp start end) |
411 | 326 (save-excursion |
28186
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
327 (forward-word (1+ (- arg))) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
328 (setq end (point)) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
329 (backward-word 1) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
330 (setq start (point) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
331 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
|
332 |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
333 (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
|
334 nil nil nil t)) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
335 (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
|
336 (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
|
337 name (abbrev-expansion name table)))) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
338 (define-abbrev table (downcase name) exp) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
339 (save-excursion |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
340 (goto-char end) |
a552a942b327
(inverse-add-abbrev): Identify word by first moving
Gerd Moellmann <gerd@gnu.org>
parents:
26079
diff
changeset
|
341 (expand-abbrev))))) |
411 | 342 |
343 (defun abbrev-prefix-mark (&optional arg) | |
344 "Mark current point as the beginning of an abbrev. | |
345 Abbrev to be expanded starts here rather than at beginning of word. | |
346 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
|
347 use this command, then insert the abbrev. This command inserts a |
16aaa8fe949d
(write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
348 temporary hyphen after the prefix \(until the intended abbrev |
16aaa8fe949d
(write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
349 expansion occurs). |
16aaa8fe949d
(write-abbrev-file): Make argument optional. Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
350 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
|
351 ARG is non-nil. Interactively, ARG is the prefix argument." |
411 | 352 (interactive "P") |
353 (or arg (expand-abbrev)) | |
354 (setq abbrev-start-location (point-marker) | |
355 abbrev-start-location-buffer (current-buffer)) | |
356 (insert "-")) | |
357 | |
358 (defun expand-region-abbrevs (start end &optional noquery) | |
359 "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
|
360 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
|
361 A prefix argument means don't query; expand all abbrevs." |
411 | 362 (interactive "r\nP") |
363 (save-excursion | |
364 (goto-char start) | |
365 (let ((lim (- (point-max) end)) | |
366 pnt string) | |
367 (while (and (not (eobp)) | |
368 (progn (forward-word 1) | |
369 (<= (setq pnt (point)) (- (point-max) lim)))) | |
370 (if (abbrev-expansion | |
371 (setq string | |
26079
bc18b027a049
(add-abbrev, inverse-add-abbrev, expand-region-abbrevs): Remove
Dave Love <fx@gnu.org>
parents:
24596
diff
changeset
|
372 (buffer-substring-no-properties |
411 | 373 (save-excursion (forward-word -1) (point)) |
374 pnt))) | |
375 (if (or noquery (y-or-n-p (format "Expand `%s'? " string))) | |
376 (expand-abbrev))))))) | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
411
diff
changeset
|
377 |
85710
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
378 ;;; Abbrev properties. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
379 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
380 (defun abbrev-table-get (table prop) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
381 "Get the PROP property of abbrev table TABLE." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
382 (let ((sym (intern-soft "" table))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
383 (if sym (get sym prop)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
384 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
385 (defun abbrev-table-put (table prop val) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
386 "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
|
387 (let ((sym (intern "" table))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
388 (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
|
389 (put sym prop val))) |
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 (defun abbrev-get (sym prop) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
392 "Get the property PROP of abbrev SYM." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
393 (let ((plist (symbol-plist sym))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
394 (if (listp plist) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
395 (plist-get plist prop) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
396 (if (eq 'count prop) plist)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
397 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
398 (defun abbrev-put (sym prop val) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
399 "Set the property PROP of abbrev SYM to value VAL. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
400 See `define-abbrev' for the effect of some special properties." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
401 (let ((plist (symbol-plist sym))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
402 (if (consp plist) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
403 (put sym prop val) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
404 (setplist sym (if (eq 'count prop) val |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
405 (list 'count plist prop val)))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
406 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
407 (defmacro abbrev-with-wrapper-hook (var &rest body) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
408 "Run BODY wrapped with the VAR hook. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
409 VAR is a special hook: its functions are called with one argument which |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
410 is the \"original\" code (the BODY), so the hook function can wrap the |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
411 original function, can call it several times, or even not call it at all. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
412 VAR is normally a symbol (a variable) in which case it is treated like a hook, |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
413 with a buffer-local and a global part. But it can also be an arbitrary expression. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
414 This is similar to an `around' advice." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
415 (declare (indent 1) (debug t)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
416 ;; We need those two gensyms because CL's lexical scoping is not available |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
417 ;; for function arguments :-( |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
418 (let ((funs (make-symbol "funs")) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
419 (global (make-symbol "global"))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
420 ;; Since the hook is a wrapper, the loop has to be done via |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
421 ;; recursion: a given hook function will call its parameter in order to |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
422 ;; continue looping. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
423 `(labels ((runrestofhook (,funs ,global) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
424 ;; `funs' holds the functions left on the hook and `global' |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
425 ;; holds the functions left on the global part of the hook |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
426 ;; (in case the hook is local). |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
427 (lexical-let ((funs ,funs) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
428 (global ,global)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
429 (if (consp funs) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
430 (if (eq t (car funs)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
431 (runrestofhook (append global (cdr funs)) nil) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
432 (funcall (car funs) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
433 (lambda () (runrestofhook (cdr funs) global)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
434 ;; Once there are no more functions on the hook, run |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
435 ;; the original body. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
436 ,@body)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
437 (runrestofhook ,var |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
438 ;; The global part of the hook, if any. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
439 ,(if (symbolp var) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
440 `(if (local-variable-p ',var) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
441 (default-value ',var))))))) |
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 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
444 ;;; 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
|
445 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
446 (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
|
447 global-abbrev-table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
448 "List of symbols whose values are abbrev tables.") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
449 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
450 (defun make-abbrev-table (&optional props) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
451 "Create a new, empty abbrev table object. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
452 PROPS is a " |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
453 ;; The value 59 is an arbitrary prime number. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
454 (let ((table (make-vector 59 0))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
455 ;; 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
|
456 ;; 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
|
457 ;; 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
|
458 ;; `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
|
459 ;; needs to be refreshed. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
460 ;; 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
|
461 ;; vector is really an abbrev-table. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
462 (abbrev-table-put table :abbrev-table-modiff 0) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
463 (while (consp props) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
464 (abbrev-table-put table (pop props) (pop props))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
465 table)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
466 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
467 (defun abbrev-table-p (object) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
468 (and (vectorp object) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
469 (numberp (abbrev-table-get object :abbrev-table-modiff)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
470 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
471 (defvar global-abbrev-table (make-abbrev-table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
472 "The abbrev table whose abbrevs affect all buffers. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
473 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
|
474 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
|
475 for any particular abbrev defined in both.") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
476 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
477 (defvar abbrev-minor-mode-table-alist nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
478 "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
|
479 Each element looks like (VARIABLE . ABBREV-TABLE); |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
480 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
|
481 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
482 (defvar fundamental-mode-abbrev-table |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
483 (let ((table (make-abbrev-table))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
484 ;; 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
|
485 (setq-default local-abbrev-table table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
486 table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
487 "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
|
488 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
489 (defvar abbrevs-changed nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
490 "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
|
491 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
|
492 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
493 (defcustom abbrev-all-caps nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
494 "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
|
495 :type 'boolean |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
496 :group 'abbrev-mode) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
497 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
498 (defvar abbrev-start-location nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
499 "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
|
500 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
|
501 Calling `expand-abbrev' sets this to nil.") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
502 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
503 (defvar abbrev-start-location-buffer nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
504 "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
|
505 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
|
506 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
507 (defvar last-abbrev nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
508 "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
|
509 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
510 (defvar last-abbrev-text nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
511 "The exact text of the last abbrev expanded. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
512 nil if the abbrev has already been unexpanded.") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
513 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
514 (defvar last-abbrev-location 0 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
515 "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
|
516 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
517 ;; (defvar local-abbrev-table fundamental-mode-abbrev-table |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
518 ;; "Local (mode-specific) abbrev table of current buffer.") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
519 ;; (make-variable-buffer-local 'local-abbrev-table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
520 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
521 (defcustom pre-abbrev-expand-hook nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
522 "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
|
523 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
|
524 the current abbrev table before abbrev lookup happens." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
525 :type 'hook |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
526 :group 'abbrev-mode) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
527 (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
|
528 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
529 (defun clear-abbrev-table (table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
530 "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
|
531 (setq abbrevs-changed t) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
532 (dotimes (i (length table)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
533 (aset table i 0))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
534 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
535 (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
|
536 "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
|
537 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
|
538 EXPANSION should usually be a string. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
539 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
|
540 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
|
541 it is called after EXPANSION is inserted. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
542 If EXPANSION is not a string, the abbrev is a special one, |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
543 which does not expand in the usual way but only runs HOOK. |
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 PROPS is a property list. The following properties are special: |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
546 - `count': the value for the abbrev's usage-count, which is incremented each time |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
547 the abbrev is used (the default is zero). |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
548 - `system-flag': if non-nil, says that this is a \"system\" abbreviation |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
549 which should not be saved in the user's abbreviation file. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
550 Unless `system-flag' is `force', a system abbreviation will not |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
551 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
|
552 - `: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
|
553 case-folding, and the expansion is not capitalized/upcased. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
554 - `:enable-function': a function of no argument which returns non-nil iff the |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
555 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
|
556 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
557 An obsolete but still supported calling form is: |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
558 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
559 \(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM-FLAG)." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
560 (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
|
561 ;; Old-style calling convention. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
562 (setq props (list* 'count (car props) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
563 (if (cadr props) (list 'system-flag (cadr props)))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
564 (unless (plist-get props 'count) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
565 (setq props (plist-put props 'count 0))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
566 (let ((system-flag (plist-get props 'system-flag)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
567 (sym (intern name table))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
568 ;; 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
|
569 ;; unless system-flag is `force'. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
570 (unless (and (not (memq system-flag '(nil force))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
571 (boundp sym) (symbol-value sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
572 (not (abbrev-get sym 'system-flag))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
573 (unless (or system-flag |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
574 (and (boundp sym) (fboundp sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
575 ;; load-file-name |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
576 (equal (symbol-value sym) expansion) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
577 (equal (symbol-function sym) hook))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
578 (setq abbrevs-changed t)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
579 (set sym expansion) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
580 (fset sym hook) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
581 (setplist sym props) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
582 (abbrev-table-put table :abbrev-table-modiff |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
583 (1+ (abbrev-table-get table :abbrev-table-modiff)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
584 name)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
585 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
586 (defun abbrev--check-chars (abbrev global) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
587 "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
|
588 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
|
589 (with-syntax-table |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
590 (cond ((null global) (standard-syntax-table)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
591 ;; ((syntax-table-p global) global) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
592 (t (syntax-table))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
593 (when (string-match "\\W" abbrev) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
594 (let ((badchars ()) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
595 (pos 0)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
596 (while (string-match "\\W" abbrev pos) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
597 (pushnew (aref abbrev (match-beginning 0)) badchars) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
598 (setq pos (1+ pos))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
599 (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
|
600 (apply 'string (nreverse badchars)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
601 (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
|
602 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
603 (defun define-global-abbrev (abbrev expansion) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
604 "Define ABBREV as a global abbreviation for EXPANSION. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
605 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
|
606 syntax table." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
607 (interactive "sDefine global abbrev: \nsExpansion for %s: ") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
608 (abbrev--check-chars abbrev 'global) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
609 (define-abbrev global-abbrev-table (downcase abbrev) expansion)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
610 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
611 (defun define-mode-abbrev (abbrev expansion) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
612 "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
|
613 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
|
614 (interactive "sDefine mode abbrev: \nsExpansion for %s: ") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
615 (unless local-abbrev-table |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
616 (error "Major mode has no abbrev table")) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
617 (abbrev--check-chars abbrev nil) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
618 (define-abbrev local-abbrev-table (downcase abbrev) expansion)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
619 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
620 (defun abbrev--active-tables (&optional tables) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
621 "Return the list of abbrev tables currently active. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
622 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
|
623 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
|
624 ;; 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
|
625 ;; (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
|
626 ;; 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
|
627 (cond |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
628 ((consp tables) tables) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
629 ((vectorp tables) (list tables)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
630 (t |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
631 (let ((tables (if (listp local-abbrev-table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
632 (append local-abbrev-table |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
633 (list global-abbrev-table)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
634 (list local-abbrev-table global-abbrev-table)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
635 ;; Add the minor-mode abbrev tables. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
636 (dolist (x abbrev-minor-mode-table-alist) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
637 (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
|
638 (setq tables |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
639 (if (listp (cdr x)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
640 (append (cdr x) tables) (cons (cdr x) tables))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
641 tables)))) |
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 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
644 (defun abbrev-symbol (abbrev &optional table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
645 "Return the symbol representing abbrev named ABBREV. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 (let ((tables (abbrev--active-tables table)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
652 sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
653 (while (and tables (not (symbol-value sym))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
654 (let ((table (pop tables)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
655 (case-fold (not (abbrev-table-get table :case-fixed)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
656 (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
|
657 ;; 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
|
658 ;; abbrevs do, we have to be careful. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
659 (setq sym |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
660 ;; First try without case-folding. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
661 (or (intern-soft abbrev table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
662 (when case-fold |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
663 ;; 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
|
664 (let ((sym (intern-soft (downcase abbrev) table))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
665 ;; 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
|
666 (and sym (not (abbrev-get sym :case-fixed)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
667 sym))))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
668 (if (symbol-value sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
669 sym))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
670 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
671 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
672 (defun abbrev-expansion (abbrev &optional table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
673 "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
|
674 Optionally specify an abbrev table as second arg; |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
675 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
|
676 (symbol-value (abbrev-symbol abbrev table))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
677 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
678 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
679 (defun abbrev--before-point () |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
680 "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
|
681 (unless (eq abbrev-start-location-buffer (current-buffer)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
682 (setq abbrev-start-location nil)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
683 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
684 (let ((tables (abbrev--active-tables)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
685 (pos (point)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
686 start end name res) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
687 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
688 (if abbrev-start-location |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
689 (progn |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
690 (setq start abbrev-start-location) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
691 (setq abbrev-start-location nil) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
692 ;; Remove the hyphen inserted by `abbrev-prefix-mark'. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
693 (if (and (< start (point-max)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
694 (eq (char-after start) ?-)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
695 (delete-region start (1+ start))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
696 (skip-syntax-backward " ") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
697 (setq end (point)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
698 (setq name (buffer-substring start end)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
699 (goto-char pos) ; Restore point. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
700 (list (abbrev-symbol name tables) name start end)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
701 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
702 (while (and tables (not (car res))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
703 (let* ((table (pop tables)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
704 (enable-fun (abbrev-table-get table :enable-function))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
705 (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
|
706 (setq res |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
707 (and (or (not enable-fun) (funcall enable-fun)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
708 (looking-back (or (abbrev-table-get table :regexp) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
709 "\\<\\(\\w+\\)\\W*") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
710 (line-beginning-position)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
711 (setq start (match-beginning 1)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
712 (setq end (match-end 1)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
713 (setq name (buffer-substring start end)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
714 ;; This will also look it up in parent tables. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
715 ;; This is not on purpose, but it seems harmless. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
716 (list (abbrev-symbol name table) name start end))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
717 ;; Restore point. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
718 (goto-char pos))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
719 res))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
720 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
721 (defvar abbrev-expand-functions nil |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
722 "Wrapper hook around `expand-abbrev'. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
723 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
|
724 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
|
725 the abbrev symbol if expansion took place.") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
726 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
727 (defun expand-abbrev () |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
728 "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
|
729 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
|
730 Returns the abbrev symbol, if expansion took place." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
731 (interactive) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
732 (run-hooks 'pre-abbrev-expand-hook) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
733 (abbrev-with-wrapper-hook abbrev-expand-functions |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
734 (destructuring-bind (&optional sym name wordstart wordend) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
735 (abbrev--before-point) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
736 (when sym |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
737 (let ((value sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
738 (unless (or ;; executing-kbd-macro |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
739 noninteractive |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
740 (window-minibuffer-p (selected-window))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
741 ;; 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
|
742 ;; 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
|
743 (undo-boundary)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
744 ;; Now sym is the abbrev symbol. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
745 (setq last-abbrev-text name) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
746 (setq last-abbrev sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
747 (setq last-abbrev-location wordstart) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
748 ;; Increment use count. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
749 (abbrev-put sym 'count (1+ (abbrev-get sym 'count))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
750 ;; 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
|
751 ;; and insert the expansion. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
752 (when (stringp (symbol-value sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
753 (goto-char wordend) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
754 (insert (symbol-value sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
755 (delete-region wordstart wordend) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
756 (let ((case-fold-search nil)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
757 ;; If the abbrev's name is different from the buffer text (the |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
758 ;; only difference should be capitalization), then we may want |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
759 ;; to adjust the capitalization of the expansion. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
760 (when (and (not (equal name (symbol-name sym))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
761 (string-match "[[:upper:]]" name)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
762 (if (not (string-match "[[:lower:]]" name)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
763 ;; Abbrev was all caps. If expansion is multiple words, |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
764 ;; normally capitalize each word. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
765 (if (and (not abbrev-all-caps) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
766 (save-excursion |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
767 (> (progn (backward-word 1) (point)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
768 (progn (goto-char wordstart) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
769 (forward-word 1) (point))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
770 (upcase-initials-region wordstart (point)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
771 (upcase-region wordstart (point))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
772 ;; Abbrev included some caps. Cap first initial of expansion. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
773 (let ((end (point))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
774 ;; Find the initial. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
775 (goto-char wordstart) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
776 (skip-syntax-forward "^w" (1- end)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
777 ;; Change just that. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
778 (upcase-initials-region (point) (1+ (point)))))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
779 (when (symbol-function sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
780 (let* ((hook (symbol-function sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
781 (expanded |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
782 ;; If the abbrev has a hook function, run it. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
783 (funcall hook))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
784 ;; In addition, if the hook function is a symbol with |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
785 ;; a non-nil `no-self-insert' property, let the value it |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
786 ;; returned specify whether we consider that an expansion took |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
787 ;; place. If it returns nil, no expansion has been done. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
788 (if (and (symbolp hook) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
789 (null expanded) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
790 (get hook 'no-self-insert)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
791 (setq value nil)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
792 value))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
793 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
794 (defun unexpand-abbrev () |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
795 "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
|
796 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
|
797 is not undone." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
798 (interactive) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
799 (save-excursion |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
800 (unless (or (< last-abbrev-location (point-min)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
801 (> last-abbrev-location (point-max))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
802 (goto-char last-abbrev-location) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
803 (when (stringp last-abbrev-text) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
804 ;; 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
|
805 ;; to do the expansion. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
806 (let ((val (symbol-value last-abbrev))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
807 (unless (stringp val) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
808 (error "value of abbrev-symbol must be a string")) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
809 (delete-region (point) (+ (point) (length val))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
810 ;; 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
|
811 (insert last-abbrev-text) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
812 (setq last-abbrev-text nil)))))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
813 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
814 (defun abbrev--write (sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
815 "Write the abbrev in a `read'able form. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
816 Only writes the non-system abbrevs. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
817 Presumes that `standard-output' points to `current-buffer'." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
818 (unless (or (null (symbol-value sym)) (abbrev-get sym 'system-flag)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
819 (insert " (") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
820 (prin1 name) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
821 (insert " ") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
822 (prin1 (symbol-value sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
823 (insert " ") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
824 (prin1 (symbol-function sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
825 (insert " ") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
826 (prin1 (abbrev-get sym 'count)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
827 (insert ")\n"))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
828 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
829 (defun abbrev--describe (sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
830 (when (symbol-value sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
831 (prin1 (symbol-name sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
832 (if (null (abbrev-get sym 'system-flag)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
833 (indent-to 15 1) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
834 (insert " (sys)") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
835 (indent-to 20 1)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
836 (prin1 (abbrev-get sym 'count)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
837 (indent-to 20 1) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
838 (prin1 (symbol-value sym)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
839 (when (symbol-function sym) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
840 (indent-to 45 1) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
841 (prin1 (symbol-function sym))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
842 (terpri))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
843 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
844 (defun insert-abbrev-table-description (name &optional readable) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
845 "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
|
846 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
|
847 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
|
848 is inserted. Otherwise the description is an expression, |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
849 a call to `define-abbrev-table', which would |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
850 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
|
851 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
852 Abbrevs marked as \"system abbrevs\" are omitted." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
853 (let ((table (symbol-value name)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
854 (symbols ())) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
855 (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
|
856 (setq symbols (sort symbols 'string-lessp)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
857 (let ((standard-output (current-buffer))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
858 (if readable |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
859 (progn |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
860 (insert "(") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
861 (prin1 name) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
862 (insert ")\n\n") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
863 (mapc 'abbrev--describe symbols) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
864 (insert "\n\n")) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
865 (insert "(define-abbrev-table '") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
866 (prin1 name) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
867 (insert " '(") |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
868 (mapc 'abbrev--write symbols) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
869 (insert " ))\n\n")) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
870 nil))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
871 |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
872 (defun define-abbrev-table (tablename definitions |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
873 &optional docstring &rest props) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
874 "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
|
875 Define abbrevs in it according to DEFINITIONS, which is a list of elements |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
876 of the form (ABBREVNAME EXPANSION HOOK USECOUNT SYSTEMFLAG). |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
877 \(If the list is shorter than that, omitted elements default to nil). |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
878 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
|
879 Properties with special meaning: |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
880 - `: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
|
881 abbreviations. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
882 - `: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
|
883 case-folding, and the expansion is not capitalized/upcased. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
884 - `:regexp' describes the form of abbrevs. It defaults to \\<\\(\\w+\\)\\W* which |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
885 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
|
886 as the potential name of an abbrev. |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
887 - `:enable-function' can be set to a function of no argument which returns |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
888 non-nil iff the abbrevs in this table should be used for this instance |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
889 of `expand-abbrev'." |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
890 (let ((table (if (boundp tablename) (symbol-value tablename)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
891 (unless table |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
892 (setq table (make-abbrev-table props)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
893 (set tablename table) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
894 (push tablename abbrev-table-name-list)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
895 (when (stringp docstring) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
896 (put tablename 'variable-documentation docstring)) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
897 (dolist (elt definitions) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
898 (apply 'define-abbrev table elt)))) |
beb909dfc54d
Rewrite abbrev.c in Elisp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78492
diff
changeset
|
899 |
76421
1a0fcbc9da8c
(abbrev): Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
75347
diff
changeset
|
900 (provide 'abbrev) |
1a0fcbc9da8c
(abbrev): Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
75347
diff
changeset
|
901 |
70216
0bf240af6e61
(abbrev-mode): Tighten up a bit the safety predicate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70102
diff
changeset
|
902 ;; arch-tag: dbd6f3ae-dfe3-40ba-b00f-f9e3ff960df5 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
411
diff
changeset
|
903 ;;; abbrev.el ends here |