Function: add-abbrev

add-abbrev is a byte-compiled function defined in abbrev.el.gz.

Signature

(add-abbrev TABLE TYPE ARG)

Documentation

Define abbrev in TABLE, whose expansion is ARG words before point.

Read the abbreviation from the minibuffer, with prompt TYPE.

ARG of zero means the entire region is the expansion.

A negative ARG means to undefine the specified abbrev.

TYPE is an arbitrary string used to prompt user for the kind of abbrev, such as "Global", "Mode". (This has no influence on the choice of the actual TABLE).

See inverse-add-abbrev for the opposite task.

Don't use this function in a Lisp program; use define-abbrev instead.

Source Code

;; Defined in /usr/src/emacs/lisp/abbrev.el.gz
(defun add-abbrev (table type arg)
  "Define abbrev in TABLE, whose expansion is ARG words before point.
Read the abbreviation from the minibuffer, with prompt TYPE.

ARG of zero means the entire region is the expansion.

A negative ARG means to undefine the specified abbrev.

TYPE is an arbitrary string used to prompt user for the kind of
abbrev, such as \"Global\", \"Mode\".  (This has no influence on the
choice of the actual TABLE).

See `inverse-add-abbrev' for the opposite task.

Don't use this function in a Lisp program; use `define-abbrev' instead."
  (let ((exp
         (cond
          ((or (and (null arg) (use-region-p))
               (zerop (prefix-numeric-value arg)))
           (buffer-substring-no-properties (region-beginning) (region-end)))
          ((> (prefix-numeric-value arg) 0)
	   (buffer-substring-no-properties
	    (point)
	    (save-excursion
              (forward-word (- (prefix-numeric-value arg)))
              (point))))))
	name)
    (setq name
	  (read-string (format (if exp "%s abbrev that expands into \"%s\": "
				 "Undefine %s abbrev: ")
			       type exp)))
    (set-text-properties 0 (length name) nil name)
    (if (or (null exp)
	    (not (abbrev-expansion name table))
	    (y-or-n-p (format "%s expands into \"%s\"; redefine? "
                              name (abbrev-expansion name table))))
	(define-abbrev table (downcase name) exp))))