[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lisp/uniquify.el
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] Changes to emacs/lisp/uniquify.el |
Date: |
Sun, 04 May 2003 17:30:25 -0400 |
Index: emacs/lisp/uniquify.el
diff -c emacs/lisp/uniquify.el:1.41 emacs/lisp/uniquify.el:1.42
*** emacs/lisp/uniquify.el:1.41 Sat May 3 09:51:00 2003
--- emacs/lisp/uniquify.el Sun May 4 17:30:25 2003
***************
*** 84,90 ****
;;; Code:
- (provide 'uniquify)
(eval-when-compile (require 'cl))
;;; User-visible variables
--- 84,89 ----
***************
*** 170,183 ****
(file-name-nondirectory (directory-file-name file-name)))
;; uniquify-fix-list data structure
! (defsubst uniquify-ref-base (x) (aref x 0))
! (defsubst uniquify-ref-filename (x) (aref x 1))
! (defsubst uniquify-ref-buffer (x) (aref x 2))
! (defsubst uniquify-ref-proposed (x) (aref x 3))
! (defsubst uniquify-set-proposed (x p) (aset x 3 p))
;; Internal variables used free
- (defvar uniquify-non-file-buffer-names nil)
(defvar uniquify-possibly-resolvable nil)
;;; Main entry point.
--- 169,180 ----
(file-name-nondirectory (directory-file-name file-name)))
;; uniquify-fix-list data structure
! (defstruct (uniquify-item
! (:constructor nil) (:copier nil)
! (:constructor uniquify-make-item (base filename buffer proposed)))
! base filename buffer proposed)
;; Internal variables used free
(defvar uniquify-possibly-resolvable nil)
;;; Main entry point.
***************
*** 189,195 ****
Arguments NEWBUFFILE and NEWBUF cause only a subset of buffers to be renamed."
(interactive)
(let (fix-list
- uniquify-non-file-buffer-names
(newbuffile-nd (and newbuffile
(uniquify-file-name-nondirectory newbuffile))))
(dolist (buffer (buffer-list))
--- 186,191 ----
***************
*** 206,218 ****
(setq rawname (uniquify-file-name-nondirectory bfn))
(or (not newbuffile)
(equal rawname newbuffile-nd))
! (setq proposed (uniquify-get-proposed-name
! rawname bfn uniquify-min-dir-content)))
! (push (vector rawname bfn buffer proposed) fix-list)
! (push bufname uniquify-non-file-buffer-names))))
;; selects buffers whose names may need changing, and others that
;; may conflict, then bring conflicting names together
! (uniquify-rationalize-a-list fix-list uniquify-min-dir-content)))
;; uniquify's version of buffer-file-name; result never contains trailing
slash
(defun uniquify-buffer-file-name (buffer)
--- 202,212 ----
(setq rawname (uniquify-file-name-nondirectory bfn))
(or (not newbuffile)
(equal rawname newbuffile-nd))
! (setq proposed (uniquify-get-proposed-name rawname bfn)))
! (push (uniquify-make-item rawname bfn buffer proposed) fix-list))))
;; selects buffers whose names may need changing, and others that
;; may conflict, then bring conflicting names together
! (uniquify-rationalize-a-list fix-list)))
;; uniquify's version of buffer-file-name; result never contains trailing
slash
(defun uniquify-buffer-file-name (buffer)
***************
*** 235,249 ****
dired-directory)))))))))
(defun uniquify-item-greaterp (item1 item2)
! (string-lessp (uniquify-ref-proposed item2)
! (uniquify-ref-proposed item1)))
! (defun uniquify-rationalize-a-list (fix-list depth)
(let (conflicting-sublist ; all elements have the same proposed name
(old-proposed "")
proposed)
(dolist (item (sort fix-list 'uniquify-item-greaterp))
! (setq proposed (uniquify-ref-proposed item))
(unless (equal proposed old-proposed)
(uniquify-rationalize-conflicting-sublist conflicting-sublist
old-proposed depth)
--- 229,246 ----
dired-directory)))))))))
(defun uniquify-item-greaterp (item1 item2)
! (string-lessp (uniquify-item-proposed item2)
! (uniquify-item-proposed item1)))
! (defun uniquify-rationalize-a-list (fix-list &optional depth)
! (unless depth (setq depth uniquify-min-dir-content))
(let (conflicting-sublist ; all elements have the same proposed name
(old-proposed "")
proposed)
+ ;; Divide fix-list into items with same proposed names and pass them
+ ;; to uniquify-rationalize-conflicting-sublist.
(dolist (item (sort fix-list 'uniquify-item-greaterp))
! (setq proposed (uniquify-item-proposed item))
(unless (equal proposed old-proposed)
(uniquify-rationalize-conflicting-sublist conflicting-sublist
old-proposed depth)
***************
*** 253,259 ****
(uniquify-rationalize-conflicting-sublist conflicting-sublist
old-proposed depth)))
! (defun uniquify-get-proposed-name (base filename depth)
(assert (equal base (uniquify-file-name-nondirectory filename)))
(assert (equal (directory-file-name filename) filename))
--- 250,257 ----
(uniquify-rationalize-conflicting-sublist conflicting-sublist
old-proposed depth)))
! (defun uniquify-get-proposed-name (base filename &optional depth)
! (unless depth (setq depth uniquify-min-dir-content))
(assert (equal base (uniquify-file-name-nondirectory filename)))
(assert (equal (directory-file-name filename) filename))
***************
*** 315,343 ****
(defun uniquify-rationalize-conflicting-sublist (conf-list old-name depth)
(when conf-list
(if (or (cdr conf-list)
! (member old-name uniquify-non-file-buffer-names))
(when uniquify-possibly-resolvable
(setq uniquify-possibly-resolvable nil
depth (1+ depth))
(dolist (item conf-list)
! (uniquify-set-proposed item (uniquify-get-proposed-name
! (uniquify-ref-base item)
! (uniquify-ref-filename item)
! depth)))
(uniquify-rationalize-a-list conf-list depth))
(unless (string= old-name "")
(uniquify-rename-buffer (car conf-list) old-name)))))
(defun uniquify-rename-buffer (item newname)
! (let ((buffer (uniquify-ref-buffer item)))
(unless (equal newname (buffer-name buffer))
! (let ((unset (current-buffer))
! ;; avoid hooks on rename-buffer
! (uniquify-buffer-name-style nil))
! (set-buffer buffer)
! (rename-buffer newname)
! (set-buffer unset)))))
;;; Hooks from the rest of Emacs
--- 313,343 ----
(defun uniquify-rationalize-conflicting-sublist (conf-list old-name depth)
(when conf-list
(if (or (cdr conf-list)
! ;; Check that the proposed name doesn't conflict with some
! ;; existing buffer.
! (let ((buf (get-buffer old-name)))
! (and buf (not (eq buf (uniquify-item-buffer (car conf-list)))))))
(when uniquify-possibly-resolvable
(setq uniquify-possibly-resolvable nil
depth (1+ depth))
(dolist (item conf-list)
! (setf (uniquify-item-proposed item)
! (uniquify-get-proposed-name
! (uniquify-item-base item)
! (uniquify-item-filename item)
! depth)))
(uniquify-rationalize-a-list conf-list depth))
(unless (string= old-name "")
(uniquify-rename-buffer (car conf-list) old-name)))))
(defun uniquify-rename-buffer (item newname)
! (let ((buffer (uniquify-item-buffer item)))
(unless (equal newname (buffer-name buffer))
! (with-current-buffer buffer
! (let ((uniquify-buffer-name-style nil)) ;Avoid hooks on rename-buffer.
! ;; Pass the `unique' arg, just in case.
! (rename-buffer newname t))))))
;;; Hooks from the rest of Emacs
***************
*** 403,408 ****
--- 403,411 ----
(remove-hook 'post-command-hook
'uniquify-delayed-rationalize-file-buffer-names))
+ ;; Ideally we'd like to add it buffer-locally, but that doesn't work
+ ;; because kill-buffer-hook is not permanent-local :-(
(add-hook 'kill-buffer-hook 'uniquify-delay-rationalize-file-buffer-names)
+ (provide 'uniquify)
;;; uniquify.el ends here
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Richard M. Stallman, 2003/05/03
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el,
Stefan Monnier <=
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/05
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/06
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/07
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/07
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/07
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/08
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/09
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/10
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/10
- [Emacs-diffs] Changes to emacs/lisp/uniquify.el, Stefan Monnier, 2003/05/13