(vc-cvs-checkout): Fix bug that broke C-x v ~-style checkouts.
[bpt/emacs.git] / lisp / abbrev.el
index 83d4a86..5cb4cc9 100644 (file)
@@ -35,7 +35,7 @@ define global abbrevs instead."
   :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
@@ -86,23 +86,37 @@ Mark is set after the inserted text."
        (setq tables (cdr tables))))
     (point))))
 
-(defun list-abbrevs ()
-  "Display a list of all defined abbrevs."
-  (interactive)
-  (display-buffer (prepare-abbrev-list-buffer)))
-
-(defun prepare-abbrev-list-buffer ()
+(defun list-abbrevs (&optional local)
+  "Display a list of defined abbrevs.
+If LOCAL is non-nil, interactively when invoked with a
+prefix arg, display only local, i.e. mode-specific, abbrevs.
+Otherwise display all abbrevs."
+  (interactive "P")
+  (display-buffer (prepare-abbrev-list-buffer local)))
+
+(defun abbrev-table-name (table)
+  "Value is the name of abbrev table TABLE."
+  (let ((tables abbrev-table-name-list)
+       found)
+    (while (and (not found) tables)
+      (when (eq (symbol-value (car tables)) table)
+       (setq found (car tables)))
+      (setq tables (cdr tables)))
+    found))
+    
+(defun prepare-abbrev-list-buffer (&optional local)
   (save-excursion
     (set-buffer (get-buffer-create "*Abbrevs*"))
     (erase-buffer)
-    (let ((tables abbrev-table-name-list))
-      (while tables
-       (insert-abbrev-table-description (car tables) t)
-       (setq tables (cdr tables))))
+    (if local
+       (insert-abbrev-table-description (abbrev-table-name
+                                         local-abbrev-table) t)
+      (dolist (table abbrev-table-name-list)
+       (insert-abbrev-table-description table t)))
     (goto-char (point-min))
     (set-buffer-modified-p nil)
-    (edit-abbrevs-mode))
-  (get-buffer-create "*Abbrevs*"))
+    (edit-abbrevs-mode)
+    (current-buffer)))
 
 (defun edit-abbrevs-mode ()
   "Major mode for editing the list of abbrev definitions.
@@ -263,22 +277,23 @@ Expands the abbreviation after defining it."
   (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-no-properties
-                (point) (progn (forward-word 1) (setq nameloc (point))))))
-    (set-text-properties 0 (length name) nil name)
-    (setq exp (read-string (format "%s expansion for \"%s\": "
-                                  type name) nil nil nil t))
-    (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.