;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
-;; Keywords: abbrev
+;; Keywords: abbrev convenience
;; This file is part of GNU Emacs.
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;; Code:
-(defconst only-global-abbrevs nil "\
-*t means user plans to use global abbrevs only.
-Makes the commands to define mode-specific abbrevs define global ones instead.")
+(defcustom only-global-abbrevs nil
+ "*t means user plans to use global abbrevs only.
+This makes the commands that normally define mode-specific abbrevs
+define global abbrevs instead."
+ :type 'boolean
+ :group 'abbrev-mode
+ :group 'convenience)
-(defun abbrev-mode (arg)
+(defun abbrev-mode (&optional arg)
"Toggle abbrev mode.
With argument ARG, turn abbrev mode on iff ARG is positive.
In abbrev mode, inserting an abbreviation causes it to expand
(setq abbrev-mode
(if (null arg) (not abbrev-mode)
(> (prefix-numeric-value arg) 0)))
- (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line.
+ (force-mode-line-update))
+
+(defcustom abbrev-mode nil
+ "Toggle abbrev mode.
+Non-nil means automatically expand abbrevs as they are inserted.
+
+This variable automatically becomes buffer-local when set in any fashion.
+Changing it with \\[customize] sets the default value.
+Use the command `abbrev-mode' to enable or disable Abbrev mode in the current
+buffer."
+ :type 'boolean
+ :group 'abbrev-mode)
+
\f
(defvar edit-abbrevs-map nil
"Keymap used in edit-abbrevs.")
(defun add-abbrev (table type arg)
(let ((exp (and (>= arg 0)
- (buffer-substring
+ (buffer-substring-no-properties
(point)
(if (= arg 0) (mark)
(save-excursion (forward-word (- arg)) (point))))))
(read-string (format (if exp "%s abbrev for \"%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 to \"%s\"; redefine? "
(inverse-add-abbrev global-abbrev-table "Global" arg))
(defun inverse-add-abbrev (table type arg)
- (let (name nameloc exp)
+ (let (name exp start end)
(save-excursion
- (forward-word (- arg))
- (setq name (buffer-substring (point) (progn (forward-word 1)
- (setq nameloc (point))))))
- (setq exp (read-string (format "%s expansion for \"%s\": "
- type name)))
- (if (or (not (abbrev-expansion name table))
- (y-or-n-p (format "%s expands to \"%s\"; redefine? "
- name (abbrev-expansion name table))))
- (progn
- (define-abbrev table (downcase name) exp)
- (save-excursion
- (goto-char nameloc)
- (expand-abbrev))))))
+ (forward-word (1+ (- arg)))
+ (setq end (point))
+ (backward-word 1)
+ (setq start (point)
+ name (buffer-substring-no-properties start end)))
+
+ (setq exp (read-string (format "%s expansion for \"%s\": " type name)
+ nil nil nil t))
+ (when (or (not (abbrev-expansion name table))
+ (y-or-n-p (format "%s expands to \"%s\"; redefine? "
+ name (abbrev-expansion name table))))
+ (define-abbrev table (downcase name) exp)
+ (save-excursion
+ (goto-char end)
+ (expand-abbrev)))))
(defun abbrev-prefix-mark (&optional arg)
"Mark current point as the beginning of an abbrev.
(<= (setq pnt (point)) (- (point-max) lim))))
(if (abbrev-expansion
(setq string
- (buffer-substring
+ (buffer-substring-no-properties
(save-excursion (forward-word -1) (point))
pnt)))
(if (or noquery (y-or-n-p (format "Expand `%s'? " string)))