comparison lisp/abbrev.el @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children 1ccc32a20af4
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
65 (fillarray table 0) 65 (fillarray table 0)
66 (setq abbrevs-changed t) 66 (setq abbrevs-changed t)
67 nil) 67 nil)
68 68
69 69
70 (defun define-abbrev-table (name defs) 70 (defun define-abbrev-table (table-name definitions)
71 "Define TABNAME (a symbol) as an abbrev table name. 71 "Define TABLE-NAME (a symbol) as an abbrev table name.
72 Define abbrevs in it according to DEFINITIONS, which is a list of elements 72 Define abbrevs in it according to DEFINITIONS, which is a list of elements
73 of the form (ABBREVNAME EXPANSION HOOK USECOUNT)." 73 of the form (ABBREVNAME EXPANSION HOOK USECOUNT)."
74 (let ((table (and (boundp name) (symbol-value name)))) 74 (let ((table (and (boundp table-name) (symbol-value table-name))))
75 (cond ((vectorp table)) 75 (cond ((vectorp table))
76 ((not table) 76 ((not table)
77 (setq table (make-abbrev-table)) 77 (setq table (make-abbrev-table))
78 (set name table) 78 (set table-name table)
79 (setq abbrev-table-name-list (cons name abbrev-table-name-list))) 79 (setq abbrev-table-name-list (cons table-name abbrev-table-name-list)))
80 (t 80 (t
81 (setq table (signal 'wrong-type-argument (list 'vectorp table))) 81 (setq table (wrong-type-argument 'vectorp table))
82 (set name table))) 82 (set table-name table)))
83 (while defs 83 (while definitions
84 (apply (function define-abbrev) table (car defs)) 84 (apply (function define-abbrev) table (car definitions))
85 (setq defs (cdr defs))))) 85 (setq definitions (cdr definitions)))))
86 86
87 (defun define-abbrev (table name &optional expansion hook count) 87 (defun define-abbrev (table name &optional expansion hook count)
88 "Define an abbrev in TABLE named NAME, to expand to EXPANSION or call HOOK. 88 "Define an abbrev in TABLE named NAME, to expand to EXPANSION or call HOOK.
89 NAME and EXPANSION are strings. Hook is a function or `nil'. 89 NAME and EXPANSION are strings. Hook is a function or `nil'.
90 To undefine an abbrev, define it with an expansion of `nil'." 90 To undefine an abbrev, define it with an expansion of `nil'."
91 (or (not expansion) 91 (unless (or (null expansion) (stringp expansion))
92 (stringp expansion) 92 (setq expansion (wrong-type-argument 'stringp expansion)))
93 (setq expansion (signal 'wrong-type-argument 93
94 (list 'stringp expansion)))) 94 (unless (or (null count) (integerp count))
95 (or (not count) 95 (setq count (wrong-type-argument 'fixnump count)))
96 (integerp count) 96
97 (setq count (signal 'wrong-type-argument 97 (unless (vectorp table)
98 (list 'fixnump count)))) 98 (setq table (wrong-type-argument 'vectorp table)))
99 (or (vectorp table) 99
100 (setq table (signal 'wrong-type-argument
101 (list 'vectorp table))))
102 (let* ((sym (intern name table)) 100 (let* ((sym (intern name table))
103 (oexp (and (boundp sym) (symbol-value sym))) 101 (oexp (and (boundp sym) (symbol-value sym)))
104 (ohook (and (fboundp sym) (symbol-function sym)))) 102 (ohook (and (fboundp sym) (symbol-function sym))))
105 (unless (and (equal ohook hook) 103 (unless (and (equal ohook hook)
106 (stringp oexp) 104 (stringp oexp)
205 (goto-char (- opoint adjust)) 203 (goto-char (- opoint adjust))
206 (goto-char opoint))))) 204 (goto-char opoint)))))
207 205
208 206
209 207
210 (defun insert-abbrev-table-description (name human-readable) 208 (defun insert-abbrev-table-description (name &optional human-readable)
211 "Insert before point a full description of abbrev table named NAME. 209 "Insert before point a full description of abbrev table named NAME.
212 NAME is a symbol whose value is an abbrev table. 210 NAME is a symbol whose value is an abbrev table.
213 If optional 2nd arg HUMAN is non-nil, insert a human-readable description. 211 If optional second argument HUMAN-READABLE is non-nil, insert a
214 Otherwise the description is an expression, 212 human-readable description. Otherwise the description is an
215 a call to `define-abbrev-table', which would 213 expression, a call to `define-abbrev-table', which would define the
216 define the abbrev table NAME exactly as it is currently defined." 214 abbrev table NAME exactly as it is currently defined."
217 (let ((table (symbol-value name)) 215 (let ((table (symbol-value name))
218 (stream (current-buffer))) 216 (stream (current-buffer)))
219 (message "Abbrev-table %s..." name) 217 (message "Abbrev-table %s..." name)
220 (if human-readable 218 (if human-readable
221 (progn 219 (progn
266 (message "")) 264 (message ""))
267 ;;; End code not in FSF 265 ;;; End code not in FSF
268 266
269 (defun abbrev-mode (arg) 267 (defun abbrev-mode (arg)
270 "Toggle abbrev mode. 268 "Toggle abbrev mode.
271 With argument ARG, turn abbrev mode on iff ARG is positive. 269 With argument ARG, enable abbrev mode if ARG is positive, else disable.
272 In abbrev mode, inserting an abbreviation causes it to expand 270 In abbrev mode, inserting an abbreviation causes it to expand
273 and be replaced by its expansion." 271 and be replaced by its expansion."
274 (interactive "P") 272 (interactive "P")
275 (setq abbrev-mode 273 (setq abbrev-mode
276 (if (null arg) (not abbrev-mode) 274 (if (null arg) (not abbrev-mode)
389 (load (if (and file (> (length file) 0)) file abbrev-file-name) 387 (load (if (and file (> (length file) 0)) file abbrev-file-name)
390 nil quietly) 388 nil quietly)
391 (setq save-abbrevs t abbrevs-changed nil)) 389 (setq save-abbrevs t abbrevs-changed nil))
392 390
393 (defun quietly-read-abbrev-file (&optional file) 391 (defun quietly-read-abbrev-file (&optional file)
394 "Read abbrev definitions from file written with write-abbrev-file. 392 "Read abbrev definitions from file written with `write-abbrev-file'.
395 Optional argument FILE is the name of the file to read; 393 Optional argument FILE is the name of the file to read;
396 it defaults to the value of `abbrev-file-name'. 394 it defaults to the value of `abbrev-file-name'.
397 Does not print anything." 395 Does not print anything."
398 ;(interactive "fRead abbrev file: ") 396 ;(interactive "fRead abbrev file: ")
399 (read-abbrev-file file t)) 397 (read-abbrev-file file t))
458 ;; XEmacs change: 456 ;; XEmacs change:
459 (interactive "P") 457 (interactive "P")
460 (add-abbrev global-abbrev-table "Global" arg)) 458 (add-abbrev global-abbrev-table "Global" arg))
461 459
462 (defun add-abbrev (table type arg) 460 (defun add-abbrev (table type arg)
461 "Add an abbreviation to abbrev table TABLE.
462 TYPE is a string describing in English the kind of abbrev this will be
463 (typically, \"global\" or \"mode-specific\"); this is used in
464 prompting the user. ARG is the number of words in the expansion.
465
466 Return the symbol that internally represents the new abbrev, or nil if
467 the user declines to confirm redefining an existing abbrev."
463 ;; XEmacs change: 468 ;; XEmacs change:
464 (let ((exp (abbrev-string-to-be-defined arg)) 469 (let ((exp (abbrev-string-to-be-defined arg))
465 name) 470 name)
466 (setq name 471 (setq name
467 (read-string (format (if exp "%s abbrev for \"%s\": " 472 (read-string (format (if exp "%s abbrev for \"%s\": "