]> code.delx.au - gnu-emacs/blobdiff - lisp/uniquify.el
(remove, remq): New functions.
[gnu-emacs] / lisp / uniquify.el
index 5a8c31ca624a6ebcff7af800e5bc6a0ba36d48f2..aa5faf0498c52ad8cce143ae007a37e78462af0a 100644 (file)
@@ -70,6 +70,8 @@
 ;; Ignore non-file non-dired buffers. Colin Rafferty <craffert@ml.com> 3 Mar 97
 ;; Use last component, not "", for file name of directories.  mernst 27 Jun 97
 ;; Use directory-file-name; code cleanup.  mernst 6 Sep 97
+;; Add uniquify-ignore-buffers-re.
+;;  Andre Srinivasan <andre@visigenic.com> 9 Sep 97
 
 ;; Valuable feedback was provided by
 ;; Paul Smith <psmith@baynetworks.com>,
@@ -83,6 +85,7 @@
 ;;; Code:
 
 (provide 'uniquify)
+(eval-when-compile (require 'cl))
 
 ;;; User-visible variables
 
@@ -124,6 +127,14 @@ other buffer names are changed."
   :type 'boolean
   :group 'uniquify)
 
+(defcustom uniquify-ignore-buffers-re nil
+  "*Regular expression matching buffer names that should not be uniquified.
+For instance, set this to \"^draft-[0-9]+$\" to avoid having uniquify rename
+draft buffers even if `uniquify-after-kill-buffer-p' is non-nil and the
+visited file name isn't the same as that of the buffer."
+  :type '(choice (const :tag "Uniquify all buffers" nil) regexp)
+  :group 'uniquify)
+
 (defcustom uniquify-min-dir-content 0
   "*Minimum number of directory name components included in buffer name."
   :type 'integer
@@ -149,20 +160,17 @@ variable is ignored."
 
 ;;; Utilities
 
-(defmacro uniquify-push (item list)
-  (` (setq (, list) (cons (, item) (, list)))))
-
 ;; For directories, return the last component, not the empty string.
 (defun uniquify-file-name-nondirectory (file-name)
   (file-name-nondirectory (directory-file-name file-name)))
 
 ;; uniquify-fix-list data structure
 (defmacro uniquify-fix-item-base (a)
-  (` (car (, a))))
+  `(car ,a))
 (defmacro uniquify-fix-item-filename (a)
-  (` (car (cdr (, a)))))
+  `(car (cdr ,a)))
 (defmacro uniquify-fix-item-buffer (a)
-  (` (car (cdr (cdr (, a))))))
+  `(car (cdr (cdr ,a))))
 ;; Not a macro: passed to mapcar.
 (defun uniquify-fix-item-unrationalized-buffer (item)
   (or (car (cdr (cdr (cdr item)))) nil))       ;maybe better in the future
@@ -196,13 +204,16 @@ file name elements.  Arguments cause only a subset of buffers to be renamed."
                      (uniquify-buffer-file-name buffer)))
               (rawname (and bfn (uniquify-file-name-nondirectory bfn)))
               (deserving (and rawname
+                              (not (and uniquify-ignore-buffers-re
+                                        (string-match uniquify-ignore-buffers-re
+                                                      (buffer-name buffer))))
                               (or (not newbuffile)
                                   (equal rawname
                                          (uniquify-file-name-nondirectory newbuffile))))))
          (if deserving
-             (uniquify-push (list rawname bfn buffer nil) fix-list)
-           (uniquify-push (list (buffer-name buffer))
-                          uniquify-non-file-buffer-names)))
+             (push (list rawname bfn buffer nil) fix-list)
+           (push (list (buffer-name buffer))
+                 uniquify-non-file-buffer-names)))
        (setq buffers (cdr buffers))))
     ;; selects buffers whose names may need changing, and others that
     ;; may conflict.
@@ -260,7 +271,7 @@ Works on dired buffers and ordinary file-visiting buffers, but no others."
              (uniquify-rationalize-conflicting-sublist
               conflicting-sublist old-name depth)
              (setq conflicting-sublist nil)))
-       (uniquify-push item conflicting-sublist)
+       (push item conflicting-sublist)
        (setq old-name proposed-name))
       (setq fix-list (cdr fix-list)))
     (uniquify-rationalize-conflicting-sublist