X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Fabbrev.el;h=75ce53b9b3236274dc94bcf59501e639e5d73458;hb=c5202dd83f0118ffb33a0ed364bef7833b0717e7;hp=dec62a1142984bda7f36fc789e4d6131eeb3e3b2;hpb=6883ee56ec887c2c48abe5b06b5e66aa74031910;p=chise%2Fxemacs-chise.git.1 diff --git a/lisp/abbrev.el b/lisp/abbrev.el index dec62a1..75ce53b 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -67,38 +67,30 @@ This causes `save-some-buffers' to offer to save the abbrevs.") nil) -(defun define-abbrev-table (name defs) - "Define TABNAME (a symbol) as an abbrev table name. +(defun define-abbrev-table (table-name definitions) + "Define TABLE-NAME (a symbol) as an abbrev table name. Define abbrevs in it according to DEFINITIONS, which is a list of elements of the form (ABBREVNAME EXPANSION HOOK USECOUNT)." - (let ((table (and (boundp name) (symbol-value name)))) + (let ((table (and (boundp table-name) (symbol-value table-name)))) (cond ((vectorp table)) ((not table) (setq table (make-abbrev-table)) - (set name table) - (setq abbrev-table-name-list (cons name abbrev-table-name-list))) + (set table-name table) + (setq abbrev-table-name-list (cons table-name abbrev-table-name-list))) (t - (setq table (signal 'wrong-type-argument (list 'vectorp table))) - (set name table))) - (while defs - (apply (function define-abbrev) table (car defs)) - (setq defs (cdr defs))))) + (setq table (wrong-type-argument 'vectorp table)) + (set table-name table))) + (while definitions + (apply (function define-abbrev) table (car definitions)) + (setq definitions (cdr definitions))))) (defun define-abbrev (table name &optional expansion hook count) "Define an abbrev in TABLE named NAME, to expand to EXPANSION or call HOOK. NAME and EXPANSION are strings. Hook is a function or `nil'. To undefine an abbrev, define it with an expansion of `nil'." - (or (not expansion) - (stringp expansion) - (setq expansion (signal 'wrong-type-argument - (list 'stringp expansion)))) - (or (not count) - (integerp count) - (setq count (signal 'wrong-type-argument - (list 'fixnump count)))) - (or (vectorp table) - (setq table (signal 'wrong-type-argument - (list 'vectorp table)))) + (check-type expansion (or null string)) + (check-type count (or null integer)) + (check-type table vector) (let* ((sym (intern name table)) (oexp (and (boundp sym) (symbol-value sym))) (ohook (and (fboundp sym) (symbol-function sym)))) @@ -207,13 +199,13 @@ is not undone." -(defun insert-abbrev-table-description (name human-readable) +(defun insert-abbrev-table-description (name &optional human-readable) "Insert before point a full description of abbrev table named NAME. NAME is a symbol whose value is an abbrev table. -If optional 2nd arg HUMAN is non-nil, insert a human-readable description. -Otherwise the description is an expression, -a call to `define-abbrev-table', which would -define the abbrev table NAME exactly as it is currently defined." +If optional second argument HUMAN-READABLE is non-nil, insert a +human-readable description. Otherwise the description is an +expression, a call to `define-abbrev-table', which would define the +abbrev table NAME exactly as it is currently defined." (let ((table (symbol-value name)) (stream (current-buffer))) (message "Abbrev-table %s..." name) @@ -268,7 +260,7 @@ define the abbrev table NAME exactly as it is currently defined." (defun abbrev-mode (arg) "Toggle abbrev mode. -With argument ARG, turn abbrev mode on iff ARG is positive. +With argument ARG, enable abbrev mode if ARG is positive, else disable. In abbrev mode, inserting an abbreviation causes it to expand and be replaced by its expansion." (interactive "P") @@ -391,7 +383,7 @@ Optional second argument QUIETLY non-nil means don't print anything." (setq save-abbrevs t abbrevs-changed nil)) (defun quietly-read-abbrev-file (&optional file) - "Read abbrev definitions from file written with write-abbrev-file. + "Read abbrev definitions from file written with `write-abbrev-file'. Optional argument FILE is the name of the file to read; it defaults to the value of `abbrev-file-name'. Does not print anything." @@ -419,6 +411,17 @@ The argument FILE is the file name to write." (write-region 1 (point-max) file) (erase-buffer))) +(defun abbrev-string-to-be-defined (arg) + "Return the string for which an abbrev will be defined. +ARG is the argument to `add-global-abbrev' or `add-mode-abbrev'." + (if (and (not arg) (region-active-p)) (setq arg 0) + (setq arg (prefix-numeric-value arg))) + (and (>= arg 0) + (buffer-substring + (point) + (if (= arg 0) (mark) + (save-excursion (backward-word arg) (point)))))) + (defun add-mode-abbrev (arg) "Define mode-specific abbrev for last word(s) before point. Argument is how many words before point form the expansion; @@ -449,14 +452,15 @@ Don't use this function in a Lisp program; use `define-abbrev' instead." (add-abbrev global-abbrev-table "Global" arg)) (defun add-abbrev (table type arg) + "Add an abbreviation to abbrev table TABLE. +TYPE is a string describing in English the kind of abbrev this will be +(typically, \"global\" or \"mode-specific\"); this is used in +prompting the user. ARG is the number of words in the expansion. + +Return the symbol that internally represents the new abbrev, or nil if +the user declines to confirm redefining an existing abbrev." ;; XEmacs change: - (if (and (not arg) (region-active-p)) (setq arg 0) - (setq arg (prefix-numeric-value arg))) - (let ((exp (and (>= arg 0) - (buffer-substring - (point) - (if (= arg 0) (mark) - (save-excursion (forward-word (- arg)) (point)))))) + (let ((exp (abbrev-string-to-be-defined arg)) name) (setq name (read-string (format (if exp "%s abbrev for \"%s\": " @@ -469,6 +473,14 @@ Don't use this function in a Lisp program; use `define-abbrev' instead." name (abbrev-expansion name table)))) (define-abbrev table (downcase name) exp)))) +(defun inverse-abbrev-string-to-be-defined (arg) + "Return the string for which an inverse abbrev will be defined. +ARG is the argument to `inverse-add-global-abbrev' or +`inverse-add-mode-abbrev'." + (save-excursion + (backward-word arg) + (buffer-substring (point) (progn (forward-word 1) (point))))) + (defun inverse-add-mode-abbrev (arg) "Define last word before point as a mode-specific abbrev. With prefix argument N, defines the Nth word before point. @@ -493,7 +505,7 @@ Expands the abbreviation after defining it." (defun inverse-add-abbrev (table type arg) (let (name nameloc exp) (save-excursion - (forward-word (- arg)) + (backward-word arg) (setq name (buffer-substring (point) (progn (forward-word 1) (setq nameloc (point)))))) (set-text-properties 0 (length name) nil name) @@ -536,7 +548,7 @@ If called from a Lisp program, arguments are START END &optional NOQUERY." (if (abbrev-expansion (setq string (buffer-substring - (save-excursion (forward-word -1) (point)) + (save-excursion (backward-word) (point)) pnt))) (if (or noquery (y-or-n-p (format "Expand `%s'? " string))) (expand-abbrev)))))))