aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2022-05-21 10:20:41 +0300
committerEli Zaretskii2022-05-21 10:20:41 +0300
commit90aae0bca2a4d082ec6e452ca8399b75c6c1d633 (patch)
treecb7dd91cf327f08595ce76555a912b93dc79a37c
parentdfa3e6f424b20fe27d9041b2ce7d69811df5d8cd (diff)
downloademacs-90aae0bca2a4d082ec6e452ca8399b75c6c1d633.tar.gz
emacs-90aae0bca2a4d082ec6e452ca8399b75c6c1d633.zip
Improve documentation strings and prompts in abbrev.el
* lisp/abbrev.el (abbrev-file-name, only-global-abbrevs) (copy-abbrev-table, insert-abbrevs, list-abbrevs) (abbrev-table-name, edit-abbrevs, define-abbrevs) (read-abbrev-file, quietly-read-abbrev-file, write-abbrev-file) (abbrev-edit-save-to-file, abbrev-edit-save-buffer) (add-mode-abbrev, add-global-abbrev, inverse-add-mode-abbrev) (inverse-add-global-abbrev, abbrev-prefix-mark) (expand-region-abbrevs, abbrev-table-get, abbrev-table-put) (abbrev-get, abbrev-minor-mode-table-alist, abbrevs-changed) (abbrev-all-caps, last-abbrev-text, last-abbrev-location) (clear-abbrev-table, define-abbrev, define-global-abbrev) (define-mode-abbrev, abbrev--active-tables, abbrev--symbol) (abbrev-symbol, abbrev-expansion, abbrev-insert) (abbrev-expand-function, abbrev--suggest-above-threshold) (abbrev--suggest-saved-recommendations) (abbrev--suggest-shortest-abbrev, abbrev--suggest-get-totals) (insert-abbrev-table-description, define-abbrev-table) (abbrev-table-menu): Fix doc strings: wording, punctuation, clarity. (add-abbrev, inverse-add-abbrev): Improve the prompt text. (Bug#55527)
-rw-r--r--lisp/abbrev.el249
1 files changed, 134 insertions, 115 deletions
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index de971eb2bd5..fd8cb754d17 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -42,12 +42,12 @@
42 42
43(defcustom abbrev-file-name 43(defcustom abbrev-file-name
44 (locate-user-emacs-file "abbrev_defs" ".abbrev_defs") 44 (locate-user-emacs-file "abbrev_defs" ".abbrev_defs")
45 "Default name of file from which to read abbrevs." 45 "Default name of file from which to read and where to save abbrevs."
46 :initialize 'custom-initialize-delay 46 :initialize 'custom-initialize-delay
47 :type 'file) 47 :type 'file)
48 48
49(defcustom only-global-abbrevs nil 49(defcustom only-global-abbrevs nil
50 "Non-nil means user plans to use global abbrevs only. 50 "Non-nil means user plans to use only global abbrevs.
51This makes the commands that normally define mode-specific abbrevs 51This makes the commands that normally define mode-specific abbrevs
52define global abbrevs instead." 52define global abbrevs instead."
53 :type 'boolean 53 :type 'boolean
@@ -59,7 +59,8 @@ define global abbrevs instead."
59 59
60In Abbrev mode, inserting an abbreviation causes it to expand and 60In Abbrev mode, inserting an abbreviation causes it to expand and
61be replaced by its expansion." 61be replaced by its expansion."
62 ;; It's defined in C, this stops the d-m-m macro defining it again. 62 ;; It's defined in C, this stops the 'define-minor-mode' macro from
63 ;; defining it again.
63 :variable abbrev-mode) 64 :variable abbrev-mode)
64 65
65(put 'abbrev-mode 'safe-local-variable 'booleanp) 66(put 'abbrev-mode 'safe-local-variable 'booleanp)
@@ -83,7 +84,8 @@ be replaced by its expansion."
83 84
84(defun copy-abbrev-table (table) 85(defun copy-abbrev-table (table)
85 "Make a new abbrev-table with the same abbrevs as TABLE. 86 "Make a new abbrev-table with the same abbrevs as TABLE.
86Does not copy property lists." 87This function does not copy property lists of the abbrevs.
88See `define-abbrev' for the documentation of abbrev properties."
87 (let ((new-table (make-abbrev-table))) 89 (let ((new-table (make-abbrev-table)))
88 (obarray-map 90 (obarray-map
89 (lambda (symbol) 91 (lambda (symbol)
@@ -95,8 +97,8 @@ Does not copy property lists."
95 new-table)) 97 new-table))
96 98
97(defun insert-abbrevs () 99(defun insert-abbrevs ()
98 "Insert after point a description of all defined abbrevs. 100 "Insert the description of all defined abbrevs after point.
99Mark is set after the inserted text." 101Set mark after the inserted text."
100 (interactive) 102 (interactive)
101 (push-mark 103 (push-mark
102 (save-excursion 104 (save-excursion
@@ -105,15 +107,15 @@ Mark is set after the inserted text."
105 (point)))) 107 (point))))
106 108
107(defun list-abbrevs (&optional local) 109(defun list-abbrevs (&optional local)
108 "Display a list of defined abbrevs. 110 "Display a list of the defined abbrevs.
109If LOCAL is non-nil, interactively when invoked with a 111If LOCAL is non-nil (interactively, when invoked with a
110prefix arg, display only local, i.e. mode-specific, abbrevs. 112prefix arg), display only local, i.e. mode-specific, abbrevs.
111Otherwise display all abbrevs." 113Otherwise display all the abbrevs."
112 (interactive "P") 114 (interactive "P")
113 (display-buffer (prepare-abbrev-list-buffer local))) 115 (display-buffer (prepare-abbrev-list-buffer local)))
114 116
115(defun abbrev-table-name (table) 117(defun abbrev-table-name (table)
116 "Value is the name of abbrev table TABLE." 118 "Return the name of the specified abbrev TABLE."
117 (let ((tables abbrev-table-name-list) 119 (let ((tables abbrev-table-name-list)
118 found) 120 found)
119 (while (and (not found) tables) 121 (while (and (not found) tables)
@@ -137,33 +139,33 @@ Otherwise display all abbrevs."
137 (dolist (table (nreverse empty-tables)) 139 (dolist (table (nreverse empty-tables))
138 (insert-abbrev-table-description table t))) 140 (insert-abbrev-table-description table t)))
139 ;; Note: `list-abbrevs' can display only local abbrevs, in 141 ;; Note: `list-abbrevs' can display only local abbrevs, in
140 ;; which case editing could lose abbrevs of other tables. Thus 142 ;; which case editing could lose abbrevs of other tables.
141 ;; enter `edit-abbrevs-mode' only if LOCAL is nil. 143 ;; Thus enter `edit-abbrevs-mode' only if LOCAL is nil.
142 (edit-abbrevs-mode)) 144 (edit-abbrevs-mode))
143 (goto-char (point-min)) 145 (goto-char (point-min))
144 (set-buffer-modified-p nil) 146 (set-buffer-modified-p nil)
145 (current-buffer)))) 147 (current-buffer))))
146 148
147(defun edit-abbrevs () 149(defun edit-abbrevs ()
148 "Alter abbrev definitions by editing a list of them. 150 "Alter abbrev definitions by editing the list of abbrevs.
149Selects a buffer containing a list of abbrev definitions with 151This selects a buffer containing the list of abbrev definitions
150point located in the abbrev table for the current buffer, and 152with point located in the abbrev table for the current buffer, and
151turns on `edit-abbrevs-mode' in that buffer. 153turns on `edit-abbrevs-mode' in the buffer with the list of abbrevs.
152 154
153You can edit them and type \\<edit-abbrevs-mode-map>\\[edit-abbrevs-redefine] \ 155You can edit the abbrevs and type \\<edit-abbrevs-mode-map>\\[edit-abbrevs-redefine] \
154to redefine abbrevs 156to redefine abbrevs
155according to your editing. 157according to your editing.
156 158
157The abbrevs editing buffer contains a header line for each 159The abbrevs editing buffer contains a header line for each
158abbrev table, which is the abbrev table name in parentheses. 160abbrev table, which is the abbrev table name in parentheses.
159 161
160This is followed by one line per abbrev in that table: 162The header line is followed by one line per abbrev in that table:
161 163
162 NAME USECOUNT EXPANSION HOOK 164 NAME USECOUNT EXPANSION HOOK
163 165
164where NAME and EXPANSION are strings with quotes, 166where NAME and EXPANSION are strings with quotes,
165USECOUNT is an integer, and HOOK is any valid function 167USECOUNT is an integer, and HOOK is any valid function
166or may be omitted (it is usually omitted)." 168that may be omitted (it is usually omitted)."
167 (interactive) 169 (interactive)
168 (let ((table-name (abbrev-table-name local-abbrev-table))) 170 (let ((table-name (abbrev-table-name local-abbrev-table)))
169 (switch-to-buffer (prepare-abbrev-list-buffer)) 171 (switch-to-buffer (prepare-abbrev-list-buffer))
@@ -184,8 +186,9 @@ or may be omitted (it is usually omitted)."
184 "Define abbrevs according to current visible buffer contents. 186 "Define abbrevs according to current visible buffer contents.
185See documentation of `edit-abbrevs' for info on the format of the 187See documentation of `edit-abbrevs' for info on the format of the
186text you must have in the buffer. 188text you must have in the buffer.
187With argument, eliminate all abbrev definitions except 189If ARG is non-nil (interactively, when invoked with a prefix
188the ones defined from the buffer now." 190argument), eliminate all abbrev definitions except the ones
191defined by the current buffer contents."
189 (interactive "P") 192 (interactive "P")
190 (if arg (kill-all-abbrevs)) 193 (if arg (kill-all-abbrevs))
191 (save-excursion 194 (save-excursion
@@ -216,7 +219,8 @@ the ones defined from the buffer now."
216 "Read abbrev definitions from file written with `write-abbrev-file'. 219 "Read abbrev definitions from file written with `write-abbrev-file'.
217Optional argument FILE is the name of the file to read; 220Optional argument FILE is the name of the file to read;
218it defaults to the value of `abbrev-file-name'. 221it defaults to the value of `abbrev-file-name'.
219Optional second argument QUIETLY non-nil means don't display a message." 222Optional second argument QUIETLY non-nil means don't display a message
223about loading the abbrevs."
220 (interactive 224 (interactive
221 (list 225 (list
222 (read-file-name (format-prompt "Read abbrev file" abbrev-file-name) 226 (read-file-name (format-prompt "Read abbrev file" abbrev-file-name)
@@ -225,22 +229,22 @@ Optional second argument QUIETLY non-nil means don't display a message."
225 (setq abbrevs-changed nil)) 229 (setq abbrevs-changed nil))
226 230
227(defun quietly-read-abbrev-file (&optional file) 231(defun quietly-read-abbrev-file (&optional file)
228 "Read abbrev definitions from file written with `write-abbrev-file'. 232 "Quietly read abbrev definitions from file written with `write-abbrev-file'.
229Optional argument FILE is the name of the file to read; 233Optional argument FILE is the name of the file to read;
230it defaults to the value of `abbrev-file-name'. 234it defaults to the value of `abbrev-file-name'.
231Does not display any message." 235Do not display any messages about loading the abbrevs."
232 ;(interactive "fRead abbrev file: ") 236 ;(interactive "fRead abbrev file: ")
233 (read-abbrev-file file t)) 237 (read-abbrev-file file t))
234 238
235(defun write-abbrev-file (&optional file verbose) 239(defun write-abbrev-file (&optional file verbose)
236 "Write all user-level abbrev definitions to a file of Lisp code. 240 "Write all user-level abbrev definitions to a file of Lisp code.
237This does not include system abbrevs; it includes only the abbrev tables 241This does not include system abbrevs; it includes only the abbrev tables
238listed in listed in `abbrev-table-name-list'. 242listed in `abbrev-table-name-list'.
239The file written can be loaded in another session to define the same abbrevs. 243The file written can be loaded in another session to define the same abbrevs.
240The argument FILE is the file name to write. If omitted or nil, the file 244The argument FILE is the file name to write. If omitted or nil, it defaults
241specified in `abbrev-file-name' is used. 245to the value of `abbrev-file-name'.
242If VERBOSE is non-nil, display a message indicating where abbrevs 246If VERBOSE is non-nil, display a message indicating the file where the
243have been saved." 247abbrevs have been saved."
244 (interactive 248 (interactive
245 (list 249 (list
246 (read-file-name "Write abbrev file: " 250 (read-file-name "Write abbrev file: "
@@ -253,10 +257,10 @@ have been saved."
253 (dolist (table 257 (dolist (table
254 ;; We sort the table in order to ease the automatic 258 ;; We sort the table in order to ease the automatic
255 ;; merging of different versions of the user's abbrevs 259 ;; merging of different versions of the user's abbrevs
256 ;; file. This is useful, for example, for when the 260 ;; file. This is useful, for example, when the
257 ;; user keeps their home directory in a revision 261 ;; user keeps their home directory in a revision
258 ;; control system, and is therefore keeping multiple 262 ;; control system, and therefore keeps multiple
259 ;; slightly-differing copies loosely synchronized. 263 ;; slightly-differing loosely synchronized copies.
260 (sort (copy-sequence abbrev-table-name-list) 264 (sort (copy-sequence abbrev-table-name-list)
261 (lambda (s1 s2) 265 (lambda (s1 s2)
262 (string< (symbol-name s1) 266 (string< (symbol-name s1)
@@ -270,7 +274,7 @@ have been saved."
270 (write-region nil nil file nil (and (not verbose) 0))))) 274 (write-region nil nil file nil (and (not verbose) 0)))))
271 275
272(defun abbrev-edit-save-to-file (file) 276(defun abbrev-edit-save-to-file (file)
273 "Save all user-level abbrev definitions in current buffer to FILE." 277 "Save to FILE all the user-level abbrev definitions in current buffer."
274 (interactive 278 (interactive
275 (list (read-file-name "Save abbrevs to file: " 279 (list (read-file-name "Save abbrevs to file: "
276 (file-name-directory 280 (file-name-directory
@@ -280,7 +284,7 @@ have been saved."
280 (write-abbrev-file file t)) 284 (write-abbrev-file file t))
281 285
282(defun abbrev-edit-save-buffer () 286(defun abbrev-edit-save-buffer ()
283 "Save all user-level abbrev definitions in current buffer. 287 "Save all the user-level abbrev definitions in current buffer.
284The saved abbrevs are written to the file specified by 288The saved abbrevs are written to the file specified by
285`abbrev-file-name'." 289`abbrev-file-name'."
286 (interactive) 290 (interactive)
@@ -288,15 +292,16 @@ The saved abbrevs are written to the file specified by
288 292
289 293
290(defun add-mode-abbrev (arg) 294(defun add-mode-abbrev (arg)
291 "Define mode-specific abbrev for last word(s) before point. 295 "Define a mode-specific abbrev whose expansion is the last word before point.
292Argument is how many words before point form the expansion; 296Prefix argument ARG says how many words before point to use for the expansion;
293or zero means the region is the expansion. 297zero means the entire region is the expansion.
294A negative argument means to undefine the specified abbrev. 298A negative ARG means to undefine the specified abbrev.
295Reads the abbreviation in the minibuffer. 299
300This command reads the abbreviation from the minibuffer.
296 301
297See also `inverse-add-mode-abbrev', which performs the opposite task: 302See also `inverse-add-mode-abbrev', which performs the opposite task:
298if the abbrev text is already in the buffer, use this command to 303if the abbreviation is already in the buffer, use that command to define
299define an abbrev by specifying the expansion in the minibuffer. 304a mode-specific abbrev by specifying its expansion in the minibuffer.
300 305
301Don't use this function in a Lisp program; use `define-abbrev' instead." 306Don't use this function in a Lisp program; use `define-abbrev' instead."
302 (interactive "p") 307 (interactive "p")
@@ -308,15 +313,16 @@ Don't use this function in a Lisp program; use `define-abbrev' instead."
308 "Mode" arg)) 313 "Mode" arg))
309 314
310(defun add-global-abbrev (arg) 315(defun add-global-abbrev (arg)
311 "Define global (all modes) abbrev for last word(s) before point. 316 "Define a global (all modes) abbrev whose expansion is last word before point.
312The prefix argument specifies the number of words before point that form the 317Prefix argument ARG says how many words before point to use for the expansion;
313expansion; or zero means the region is the expansion. 318zero means the entire region is the expansion.
314A negative argument means to undefine the specified abbrev. 319A negative ARG means to undefine the specified abbrev.
315This command uses the minibuffer to read the abbreviation. 320
321This command reads the abbreviation from the minibuffer.
316 322
317See also `inverse-add-global-abbrev', which performs the opposite task: 323See also `inverse-add-global-abbrev', which performs the opposite task:
318if the abbrev text is already in the buffer, use this command to 324if the abbreviation is already in the buffer, use that command to define
319define an abbrev by specifying the expansion in the minibuffer. 325a global abbrev by specifying its expansion in the minibuffer.
320 326
321Don't use this function in a Lisp program; use `define-abbrev' instead." 327Don't use this function in a Lisp program; use `define-abbrev' instead."
322 (interactive "p") 328 (interactive "p")
@@ -330,25 +336,30 @@ Don't use this function in a Lisp program; use `define-abbrev' instead."
330 (save-excursion (forward-word (- arg)) (point)))))) 336 (save-excursion (forward-word (- arg)) (point))))))
331 name) 337 name)
332 (setq name 338 (setq name
333 (read-string (format (if exp "%s abbrev for \"%s\": " 339 (read-string (format (if exp "%s abbrev that expands into \"%s\": "
334 "Undefine %s abbrev: ") 340 "Undefine %s abbrev: ")
335 type exp))) 341 type exp)))
336 (set-text-properties 0 (length name) nil name) 342 (set-text-properties 0 (length name) nil name)
337 (if (or (null exp) 343 (if (or (null exp)
338 (not (abbrev-expansion name table)) 344 (not (abbrev-expansion name table))
339 (y-or-n-p (format "%s expands to \"%s\"; redefine? " 345 (y-or-n-p (format "%s expands into \"%s\"; redefine? "
340 name (abbrev-expansion name table)))) 346 name (abbrev-expansion name table))))
341 (define-abbrev table (downcase name) exp)))) 347 (define-abbrev table (downcase name) exp))))
342 348
343(defun inverse-add-mode-abbrev (n) 349(defun inverse-add-mode-abbrev (n)
344 "Define last word before point as a mode-specific abbrev. 350 "Define the word before point as a mode-specific abbreviation.
345With prefix argument N, defines the Nth word before point. 351With prefix argument N, define the Nth word before point as the
346This command uses the minibuffer to read the expansion. 352abbreviation.
347Expands the abbreviation after defining it. 353
354If `only-global-abbrevs' is non-nil, this command defines a
355global (mode-independent) abbrev instead of a mode-specific one.
356
357This command reads the expansion from the minibuffer, defines the
358abbrev, and then expands the abbreviation in the current buffer.
348 359
349See also `add-mode-abbrev', which performs the opposite task: 360See also `add-mode-abbrev', which performs the opposite task:
350if the expansion is already in the buffer, use this command 361if the expansion is already in the buffer, use that command
351to define an abbrev by specifying the abbrev in the minibuffer." 362to define an abbrev by specifying the abbreviation in the minibuffer."
352 (interactive "p") 363 (interactive "p")
353 (inverse-add-abbrev 364 (inverse-add-abbrev
354 (if only-global-abbrevs 365 (if only-global-abbrevs
@@ -358,14 +369,16 @@ to define an abbrev by specifying the abbrev in the minibuffer."
358 "Mode" n)) 369 "Mode" n))
359 370
360(defun inverse-add-global-abbrev (n) 371(defun inverse-add-global-abbrev (n)
361 "Define last word before point as a global (mode-independent) abbrev. 372 "Define the word before point as a global (mode-independent) abbreviation.
362With prefix argument N, defines the Nth word before point. 373With prefix argument N, define the Nth word before point as the
363This command uses the minibuffer to read the expansion. 374abbreviation.
364Expands the abbreviation after defining it. 375
376This command reads the expansion from the minibuffer, defines the
377abbrev, and then expands the abbreviation in the current buffer.
365 378
366See also `add-global-abbrev', which performs the opposite task: 379See also `add-global-abbrev', which performs the opposite task:
367if the expansion is already in the buffer, use this command 380if the expansion is already in the buffer, use that command
368to define an abbrev by specifying the abbrev in the minibuffer." 381to define an abbrev by specifying the abbreviation in the minibuffer."
369 (interactive "p") 382 (interactive "p")
370 (inverse-add-abbrev global-abbrev-table "Global" n)) 383 (inverse-add-abbrev global-abbrev-table "Global" n))
371 384
@@ -379,10 +392,10 @@ to define an abbrev by specifying the abbrev in the minibuffer."
379 (setq start (point) 392 (setq start (point)
380 name (buffer-substring-no-properties start end))) 393 name (buffer-substring-no-properties start end)))
381 394
382 (setq exp (read-string (format "%s expansion for \"%s\": " type name) 395 (setq exp (read-string (format "Expansion for %s abbrev \"%s\": " type name)
383 nil nil nil t)) 396 nil nil nil t))
384 (when (or (not (abbrev-expansion name table)) 397 (when (or (not (abbrev-expansion name table))
385 (y-or-n-p (format "%s expands to \"%s\"; redefine? " 398 (y-or-n-p (format "%s expands into \"%s\"; redefine? "
386 name (abbrev-expansion name table)))) 399 name (abbrev-expansion name table))))
387 (define-abbrev table (downcase name) exp) 400 (define-abbrev table (downcase name) exp)
388 (save-excursion 401 (save-excursion
@@ -390,10 +403,11 @@ to define an abbrev by specifying the abbrev in the minibuffer."
390 (expand-abbrev))))) 403 (expand-abbrev)))))
391 404
392(defun abbrev-prefix-mark (&optional arg) 405(defun abbrev-prefix-mark (&optional arg)
393 "Mark current point as the beginning of an abbrev. 406 "Mark point as the beginning of an abbreviation.
394The abbrev to be expanded starts here rather than at beginning of 407The abbrev to be expanded starts at point rather than at the
395word. This way, you can expand an abbrev with a prefix: insert 408beginning of a word. This way, you can expand an abbrev with
396the prefix, use this command, then insert the abbrev. 409a prefix: insert the prefix, use this command, then insert the
410abbrev.
397 411
398This command inserts a hyphen after the prefix, and if the abbrev 412This command inserts a hyphen after the prefix, and if the abbrev
399is subsequently expanded, this hyphen will be removed. 413is subsequently expanded, this hyphen will be removed.
@@ -408,8 +422,8 @@ argument."
408 (insert "-")) 422 (insert "-"))
409 423
410(defun expand-region-abbrevs (start end &optional noquery) 424(defun expand-region-abbrevs (start end &optional noquery)
411 "For abbrev occurrence in the region, offer to expand it. 425 "For each abbrev occurrence in the region, offer to expand it.
412The user is asked to type `y' or `n' for each occurrence. 426Ask the user to type `y' or `n' for each occurrence.
413A prefix argument means don't query; expand all abbrevs." 427A prefix argument means don't query; expand all abbrevs."
414 (interactive "r\nP") 428 (interactive "r\nP")
415 (save-excursion 429 (save-excursion
@@ -430,18 +444,19 @@ A prefix argument means don't query; expand all abbrevs."
430;;; Abbrev properties. 444;;; Abbrev properties.
431 445
432(defun abbrev-table-get (table prop) 446(defun abbrev-table-get (table prop)
433 "Get the PROP property of abbrev table TABLE." 447 "Get the property PROP of abbrev table TABLE."
434 (let ((sym (obarray-get table ""))) 448 (let ((sym (obarray-get table "")))
435 (if sym (get sym prop)))) 449 (if sym (get sym prop))))
436 450
437(defun abbrev-table-put (table prop val) 451(defun abbrev-table-put (table prop val)
438 "Set the PROP property of abbrev table TABLE to VAL." 452 "Set the property PROP of abbrev table TABLE to VAL."
439 (let ((sym (obarray-put table ""))) 453 (let ((sym (obarray-put table "")))
440 (set sym nil) ; Make sure it won't be confused for an abbrev. 454 (set sym nil) ; Make sure it won't be confused for an abbrev.
441 (put sym prop val))) 455 (put sym prop val)))
442 456
443(defalias 'abbrev-get 'get 457(defalias 'abbrev-get 'get
444 "Get the property PROP of abbrev ABBREV 458 "Get the property PROP of abbrev ABBREV
459See `define-abbrev' for the effect of some special properties.
445 460
446\(fn ABBREV PROP)") 461\(fn ABBREV PROP)")
447 462
@@ -500,7 +515,8 @@ for any particular abbrev defined in both.")
500(defvar abbrev-minor-mode-table-alist nil 515(defvar abbrev-minor-mode-table-alist nil
501 "Alist of abbrev tables to use for minor modes. 516 "Alist of abbrev tables to use for minor modes.
502Each element looks like (VARIABLE . ABBREV-TABLE); 517Each element looks like (VARIABLE . ABBREV-TABLE);
503ABBREV-TABLE is active whenever VARIABLE's value is non-nil. 518ABBREV-TABLE is active whenever VARIABLE's value is non-nil;
519VARIABLE is supposed to be a minor-mode variable.
504ABBREV-TABLE can also be a list of abbrev tables.") 520ABBREV-TABLE can also be a list of abbrev tables.")
505 521
506(defvar fundamental-mode-abbrev-table 522(defvar fundamental-mode-abbrev-table
@@ -511,11 +527,11 @@ ABBREV-TABLE can also be a list of abbrev tables.")
511 "The abbrev table of mode-specific abbrevs for Fundamental Mode.") 527 "The abbrev table of mode-specific abbrevs for Fundamental Mode.")
512 528
513(defvar abbrevs-changed nil 529(defvar abbrevs-changed nil
514 "Set non-nil by defining or altering any word abbrevs. 530 "Non-nil if any word abbrevs were defined or altered.
515This causes `save-some-buffers' to offer to save the abbrevs.") 531This causes `save-some-buffers' to offer to save the abbrevs.")
516 532
517(defcustom abbrev-all-caps nil 533(defcustom abbrev-all-caps nil
518 "Non-nil means expand multi-word abbrevs all caps if abbrev was so." 534 "Non-nil means expand multi-word abbrevs in all caps if the abbrev was so."
519 :type 'boolean 535 :type 'boolean
520 :group 'abbrev-mode) 536 :group 'abbrev-mode)
521 537
@@ -532,17 +548,17 @@ Trying to expand an abbrev in any other buffer clears `abbrev-start-location'.")
532 "The abbrev-symbol of the last abbrev expanded. See `abbrev-symbol'.") 548 "The abbrev-symbol of the last abbrev expanded. See `abbrev-symbol'.")
533 549
534(defvar last-abbrev-text nil 550(defvar last-abbrev-text nil
535 "The exact text of the last abbrev expanded. 551 "The exact text of the last abbrev that was expanded.
536It is nil if the abbrev has already been unexpanded.") 552It is nil if the abbrev has already been unexpanded.")
537 553
538(defvar last-abbrev-location 0 554(defvar last-abbrev-location 0
539 "The location of the start of the last abbrev expanded.") 555 "The location of the start of the last abbrev that was expanded.")
540 556
541;; (defvar-local local-abbrev-table fundamental-mode-abbrev-table 557;; (defvar-local local-abbrev-table fundamental-mode-abbrev-table
542;; "Local (mode-specific) abbrev table of current buffer.") 558;; "Local (mode-specific) abbrev table of current buffer.")
543 559
544(defun clear-abbrev-table (table) 560(defun clear-abbrev-table (table)
545 "Undefine all abbrevs in abbrev table TABLE, leaving it empty." 561 "Undefine all abbrevs in abbrev table TABLE, leaving TABLE empty."
546 (setq abbrevs-changed t) 562 (setq abbrevs-changed t)
547 (let* ((sym (obarray-get table ""))) 563 (let* ((sym (obarray-get table "")))
548 (dotimes (i (length table)) 564 (dotimes (i (length table))
@@ -557,9 +573,9 @@ It is nil if the abbrev has already been unexpanded.")
557 ;; For backward compatibility, always return nil. 573 ;; For backward compatibility, always return nil.
558 nil) 574 nil)
559 575
560(defun define-abbrev (table name expansion &optional hook &rest props) 576(defun define-abbrev (table abbrev expansion &optional hook &rest props)
561 "Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK. 577 "Define ABBREV in TABLE, to expand into EXPANSION and optionally call HOOK.
562NAME must be a string, and should be lower-case. 578ABBREV must be a string, and should be lower-case.
563EXPANSION should usually be a string. 579EXPANSION should usually be a string.
564To undefine an abbrev, define it with EXPANSION = nil. 580To undefine an abbrev, define it with EXPANSION = nil.
565If HOOK is non-nil, it should be a function of no arguments; 581If HOOK is non-nil, it should be a function of no arguments;
@@ -583,12 +599,12 @@ PROPS is a property list. The following properties are special:
583 overwrite a non-system abbreviation of the same name. 599 overwrite a non-system abbreviation of the same name.
584- `:case-fixed': non-nil means that abbreviations are looked up without 600- `:case-fixed': non-nil means that abbreviations are looked up without
585 case-folding, and the expansion is not capitalized/upcased. 601 case-folding, and the expansion is not capitalized/upcased.
586- `:enable-function': a function of no argument which returns non-nil if the 602- `:enable-function': a function of no arguments which returns non-nil
587 abbrev should be used for a particular call of `expand-abbrev'. 603 if the abbrev should be used for a particular call of `expand-abbrev'.
588 604
589An obsolete but still supported calling form is: 605An obsolete but still supported calling form is:
590 606
591\(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM)." 607\(define-abbrev TABLE ABBREV EXPANSION &optional HOOK COUNT SYSTEM)."
592 (when (and (consp props) (or (null (car props)) (numberp (car props)))) 608 (when (and (consp props) (or (null (car props)) (numberp (car props))))
593 ;; Old-style calling convention. 609 ;; Old-style calling convention.
594 (setq props `(:count ,(car props) 610 (setq props `(:count ,(car props)
@@ -598,7 +614,7 @@ An obsolete but still supported calling form is:
598 (setq props (plist-put props :abbrev-table-modiff 614 (setq props (plist-put props :abbrev-table-modiff
599 (abbrev-table-get table :abbrev-table-modiff))) 615 (abbrev-table-get table :abbrev-table-modiff)))
600 (let ((system-flag (plist-get props :system)) 616 (let ((system-flag (plist-get props :system))
601 (sym (obarray-put table name))) 617 (sym (obarray-put table abbrev)))
602 ;; Don't override a prior user-defined abbrev with a system abbrev, 618 ;; Don't override a prior user-defined abbrev with a system abbrev,
603 ;; unless system-flag is `force'. 619 ;; unless system-flag is `force'.
604 (unless (and (not (memq system-flag '(nil force))) 620 (unless (and (not (memq system-flag '(nil force)))
@@ -618,7 +634,7 @@ An obsolete but still supported calling form is:
618 (if (eq 'force system-flag) (plist-put props :system t) props)) 634 (if (eq 'force system-flag) (plist-put props :system t) props))
619 (abbrev-table-put table :abbrev-table-modiff 635 (abbrev-table-put table :abbrev-table-modiff
620 (1+ (abbrev-table-get table :abbrev-table-modiff)))) 636 (1+ (abbrev-table-get table :abbrev-table-modiff))))
621 name)) 637 abbrev))
622 638
623(defun abbrev--check-chars (abbrev global) 639(defun abbrev--check-chars (abbrev global)
624 "Check if the characters in ABBREV have word syntax in either the 640 "Check if the characters in ABBREV have word syntax in either the
@@ -638,7 +654,7 @@ current (if global is nil) or standard syntax table."
638 (if global "in the standard syntax" "in this mode")))))) 654 (if global "in the standard syntax" "in this mode"))))))
639 655
640(defun define-global-abbrev (abbrev expansion) 656(defun define-global-abbrev (abbrev expansion)
641 "Define ABBREV as a global abbreviation for EXPANSION. 657 "Define ABBREV as a global abbreviation that expands into EXPANSION.
642The characters in ABBREV must all be word constituents in the standard 658The characters in ABBREV must all be word constituents in the standard
643syntax table." 659syntax table."
644 (interactive "sDefine global abbrev: \nsExpansion for %s: ") 660 (interactive "sDefine global abbrev: \nsExpansion for %s: ")
@@ -646,7 +662,7 @@ syntax table."
646 (define-abbrev global-abbrev-table (downcase abbrev) expansion)) 662 (define-abbrev global-abbrev-table (downcase abbrev) expansion))
647 663
648(defun define-mode-abbrev (abbrev expansion) 664(defun define-mode-abbrev (abbrev expansion)
649 "Define ABBREV as a mode-specific abbreviation for EXPANSION. 665 "Define ABBREV as a mode-specific abbreviation that expands into EXPANSION.
650The characters in ABBREV must all be word-constituents in the current mode." 666The characters in ABBREV must all be word-constituents in the current mode."
651 (interactive "sDefine mode abbrev: \nsExpansion for %s: ") 667 (interactive "sDefine mode abbrev: \nsExpansion for %s: ")
652 (unless local-abbrev-table 668 (unless local-abbrev-table
@@ -655,8 +671,8 @@ The characters in ABBREV must all be word-constituents in the current mode."
655 (define-abbrev local-abbrev-table (downcase abbrev) expansion)) 671 (define-abbrev local-abbrev-table (downcase abbrev) expansion))
656 672
657(defun abbrev--active-tables (&optional tables) 673(defun abbrev--active-tables (&optional tables)
658 "Return the list of abbrev tables currently active. 674 "Return the list of abbrev tables that are currently active.
659TABLES if non-nil overrides the usual rules. It can hold 675TABLES, if non-nil, overrides the usual rules. It can hold
660either a single abbrev table or a list of abbrev tables." 676either a single abbrev table or a list of abbrev tables."
661 ;; We could just remove the `tables' arg and let callers use 677 ;; We could just remove the `tables' arg and let callers use
662 ;; (or table (abbrev--active-tables)) but then they'd have to be careful 678 ;; (or table (abbrev--active-tables)) but then they'd have to be careful
@@ -682,7 +698,7 @@ either a single abbrev table or a list of abbrev tables."
682 "Return the symbol representing abbrev named ABBREV in TABLE. 698 "Return the symbol representing abbrev named ABBREV in TABLE.
683This symbol's name is ABBREV, but it is not the canonical symbol of that name; 699This symbol's name is ABBREV, but it is not the canonical symbol of that name;
684it is interned in the abbrev-table TABLE rather than the normal obarray. 700it is interned in the abbrev-table TABLE rather than the normal obarray.
685The value is nil if that abbrev is not defined." 701The value is nil if such an abbrev is not defined."
686 (let* ((case-fold (not (abbrev-table-get table :case-fixed))) 702 (let* ((case-fold (not (abbrev-table-get table :case-fixed)))
687 ;; In case the table doesn't set :case-fixed but some of the 703 ;; In case the table doesn't set :case-fixed but some of the
688 ;; abbrevs do, we have to be careful. 704 ;; abbrevs do, we have to be careful.
@@ -699,11 +715,11 @@ The value is nil if that abbrev is not defined."
699 sym))) 715 sym)))
700 716
701(defun abbrev-symbol (abbrev &optional table) 717(defun abbrev-symbol (abbrev &optional table)
702 "Return the symbol representing abbrev named ABBREV. 718 "Return the symbol representing the abbrev named ABBREV in TABLE.
703This symbol's name is ABBREV, but it is not the canonical symbol of that name; 719This symbol's name is ABBREV, but it is not the canonical symbol of that name;
704it is interned in an abbrev-table rather than the normal obarray. 720it is interned in an abbrev-table rather than the normal obarray.
705The value is nil if that abbrev is not defined. 721The value is nil if such an abbrev is not defined.
706Optional second arg TABLE is abbrev table to look it up in. 722Optional second arg TABLE is the abbrev table to look it up in.
707The default is to try buffer's mode-specific abbrev table, then global table." 723The default is to try buffer's mode-specific abbrev table, then global table."
708 (let ((tables (abbrev--active-tables table)) 724 (let ((tables (abbrev--active-tables table))
709 sym) 725 sym)
@@ -716,7 +732,7 @@ The default is to try buffer's mode-specific abbrev table, then global table."
716 732
717(defun abbrev-expansion (abbrev &optional table) 733(defun abbrev-expansion (abbrev &optional table)
718 "Return the string that ABBREV expands into in the current buffer. 734 "Return the string that ABBREV expands into in the current buffer.
719Optionally specify an abbrev table as second arg; 735Optionally specify an abbrev TABLE as second arg;
720then ABBREV is looked up in that table only." 736then ABBREV is looked up in that table only."
721 (symbol-value (abbrev-symbol abbrev table))) 737 (symbol-value (abbrev-symbol abbrev table)))
722 738
@@ -780,9 +796,9 @@ then ABBREV is looked up in that table only."
780(defun abbrev-insert (abbrev &optional name wordstart wordend) 796(defun abbrev-insert (abbrev &optional name wordstart wordend)
781 "Insert abbrev ABBREV at point. 797 "Insert abbrev ABBREV at point.
782If non-nil, NAME is the name by which this abbrev was found. 798If non-nil, NAME is the name by which this abbrev was found.
783If non-nil, WORDSTART is the place where to insert the abbrev. 799If non-nil, WORDSTART is the buffer position where to insert the abbrev.
784If WORDEND is non-nil, the abbrev replaces the previous text between 800If WORDEND is non-nil, it is a buffer position; the abbrev replaces the
785WORDSTART and WORDEND. 801previous text between WORDSTART and WORDEND.
786Return ABBREV if the expansion should be considered as having taken place. 802Return ABBREV if the expansion should be considered as having taken place.
787The return value can be influenced by a `no-self-insert' property; 803The return value can be influenced by a `no-self-insert' property;
788see `define-abbrev' for details." 804see `define-abbrev' for details."
@@ -847,7 +863,8 @@ see `define-abbrev' for details."
847 863
848(defvar abbrev-expand-function #'abbrev--default-expand 864(defvar abbrev-expand-function #'abbrev--default-expand
849 "Function that `expand-abbrev' uses to perform abbrev expansion. 865 "Function that `expand-abbrev' uses to perform abbrev expansion.
850Takes no argument and should return the abbrev symbol if expansion took place.") 866Takes no arguments, and should return the abbrev symbol if expansion
867took place.")
851 868
852(defcustom abbrev-suggest nil 869(defcustom abbrev-suggest nil
853 "Non-nil means suggest using abbrevs to save typing. 870 "Non-nil means suggest using abbrevs to save typing.
@@ -906,15 +923,17 @@ Expansion is a string of one or more words."
906 923
907(defun abbrev--suggest-above-threshold (expansion) 924(defun abbrev--suggest-above-threshold (expansion)
908 "Return non-nil if the abbrev in EXPANSION provides significant savings. 925 "Return non-nil if the abbrev in EXPANSION provides significant savings.
909A significant saving, here, is the difference in length between 926A significant saving, here, means the difference in length between
910the abbrev and the abbrev expansion. EXPANSION is a cons cell 927the abbrev and its expansion is not below the threshold specified
911where the car is the expansion and the cdr is the abbrev." 928by the value of `abbrev-suggest-hint-threshold'.
929EXPANSION is a cons cell where the car is the expansion and the cdr is
930the abbrev."
912 (>= (- (length (car expansion)) 931 (>= (- (length (car expansion))
913 (length (cdr expansion))) 932 (length (cdr expansion)))
914 abbrev-suggest-hint-threshold)) 933 abbrev-suggest-hint-threshold))
915 934
916(defvar abbrev--suggest-saved-recommendations nil 935(defvar abbrev--suggest-saved-recommendations nil
917 "Keeps a list of expansions that have abbrevs defined. 936 "Keeps the list of expansions that have abbrevs defined.
918The user can show this list by calling 937The user can show this list by calling
919`abbrev-suggest-show-report'.") 938`abbrev-suggest-show-report'.")
920 939
@@ -930,7 +949,7 @@ EXPANSION is a cons cell where the `car' is the expansion and the
930 (push expansion abbrev--suggest-saved-recommendations)) 949 (push expansion abbrev--suggest-saved-recommendations))
931 950
932(defun abbrev--suggest-shortest-abbrev (new current) 951(defun abbrev--suggest-shortest-abbrev (new current)
933 "Return the shortest abbrev of NEW and CURRENT. 952 "Return the shortest of the two abbrevs given by NEW and CURRENT.
934NEW and CURRENT are cons cells where the `car' is the expansion 953NEW and CURRENT are cons cells where the `car' is the expansion
935and the `cdr' is the abbrev." 954and the `cdr' is the abbrev."
936 (if (not current) 955 (if (not current)
@@ -959,8 +978,8 @@ informed about the existing abbrev."
959 978
960(defun abbrev--suggest-get-totals () 979(defun abbrev--suggest-get-totals ()
961 "Return a list of all expansions and how many times they were used. 980 "Return a list of all expansions and how many times they were used.
962Each expansion is a cons cell where the `car' is the expansion 981Each expansion in the returned list is a cons cell where the `car' is the
963and the `cdr' is the number of times the expansion has been 982expansion text and the `cdr' is the number of times the expansion has been
964typed." 983typed."
965 (let (total cell) 984 (let (total cell)
966 (dolist (expansion abbrev--suggest-saved-recommendations) 985 (dolist (expansion abbrev--suggest-saved-recommendations)
@@ -1088,11 +1107,11 @@ Presumes that `standard-output' points to `current-buffer'."
1088(defun insert-abbrev-table-description (name &optional readable) 1107(defun insert-abbrev-table-description (name &optional readable)
1089 "Insert before point a full description of abbrev table named NAME. 1108 "Insert before point a full description of abbrev table named NAME.
1090NAME is a symbol whose value is an abbrev table. 1109NAME is a symbol whose value is an abbrev table.
1091If optional 2nd arg READABLE is non-nil, a human-readable description 1110If optional 2nd arg READABLE is non-nil, insert a human-readable
1092is inserted. 1111description.
1093 1112
1094If READABLE is nil, an expression is inserted. The expression is 1113If READABLE is nil, insert an expression. The expression is
1095a call to `define-abbrev-table' that when evaluated will define 1114a call to `define-abbrev-table' that, when evaluated, will define
1096the abbrev table NAME exactly as it is currently defined. 1115the abbrev table NAME exactly as it is currently defined.
1097Abbrevs marked as \"system abbrevs\" are ignored." 1116Abbrevs marked as \"system abbrevs\" are ignored."
1098 (let ((symbols (abbrev--table-symbols name readable))) 1117 (let ((symbols (abbrev--table-symbols name readable)))
@@ -1139,10 +1158,10 @@ Properties with special meaning:
1139 case-folding, and the expansion is not capitalized/upcased. 1158 case-folding, and the expansion is not capitalized/upcased.
1140- `:regexp' is a regular expression that specifies how to extract the 1159- `:regexp' is a regular expression that specifies how to extract the
1141 name of the abbrev before point. The submatch 1 is treated 1160 name of the abbrev before point. The submatch 1 is treated
1142 as the potential name of an abbrev. If :regexp is nil, the default 1161 as the potential name of an abbrev. If `:regexp' is nil, the default
1143 behavior uses `backward-word' and `forward-word' to extract the name 1162 behavior uses `backward-word' and `forward-word' to extract the name
1144 of the abbrev, which can therefore only be a single word. 1163 of the abbrev, which can therefore by default only be a single word.
1145- `:enable-function' can be set to a function of no argument which returns 1164- `:enable-function' can be set to a function of no arguments which returns
1146 non-nil if and only if the abbrevs in this table should be used for this 1165 non-nil if and only if the abbrevs in this table should be used for this
1147 instance of `expand-abbrev'." 1166 instance of `expand-abbrev'."
1148 (declare (doc-string 3)) 1167 (declare (doc-string 3))
@@ -1171,7 +1190,7 @@ Properties with special meaning:
1171 1190
1172(defun abbrev-table-menu (table &optional prompt sortfun) 1191(defun abbrev-table-menu (table &optional prompt sortfun)
1173 "Return a menu that shows all abbrevs in TABLE. 1192 "Return a menu that shows all abbrevs in TABLE.
1174Selecting an entry runs `abbrev-insert'. 1193Selecting an entry runs `abbrev-insert' for that entry's abbrev.
1175PROMPT is the prompt to use for the keymap. 1194PROMPT is the prompt to use for the keymap.
1176SORTFUN is passed to `sort' to change the default ordering." 1195SORTFUN is passed to `sort' to change the default ordering."
1177 (unless sortfun (setq sortfun 'string-lessp)) 1196 (unless sortfun (setq sortfun 'string-lessp))