\f
(defun add-mode-abbrev (arg)
"Define a mode-specific abbrev whose expansion is the last word before point.
+If there's an active region, use that as the expansion.
+
Prefix argument ARG says how many words before point to use for the expansion;
zero means the entire region is the expansion.
+
A negative ARG means to undefine the specified abbrev.
This command reads the abbreviation from the minibuffer.
a mode-specific abbrev by specifying its expansion in the minibuffer.
Don't use this function in a Lisp program; use `define-abbrev' instead."
- (interactive "p")
+ (interactive "P")
(add-abbrev
(if only-global-abbrevs
global-abbrev-table
(defun add-global-abbrev (arg)
"Define a global (all modes) abbrev whose expansion is last word before point.
+If there's an active region, use that as the expansion.
+
Prefix argument ARG says how many words before point to use for the expansion;
zero means the entire region is the expansion.
+
A negative ARG means to undefine the specified abbrev.
This command reads the abbreviation from the minibuffer.
a global abbrev by specifying its expansion in the minibuffer.
Don't use this function in a Lisp program; use `define-abbrev' instead."
- (interactive "p")
+ (interactive "P")
(add-abbrev global-abbrev-table "Global" arg))
(defun add-abbrev (table type arg)
- (let ((exp (and (>= arg 0)
- (buffer-substring-no-properties
- (point)
- (if (= arg 0) (mark)
- (save-excursion (forward-word (- arg)) (point))))))
+ (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\": "