- (or (buffer-local-value 'uniquify-managed buffer)
- (eq buffer newbuf))
- (setq bfn (if (eq buffer newbuf) newbuffile
- (uniquify-buffer-file-name buffer)))
- (equal (file-name-nondirectory bfn) base))
- (when (setq bfn (file-name-directory bfn)) ;Strip off the `base'.
- (setq bfn (directory-file-name bfn))) ;Strip trailing slash.
- (push (uniquify-make-item base bfn buffer
- (uniquify-get-proposed-name base bfn))
- fix-list))))
- ;; selects buffers whose names may need changing, and others that
- ;; may conflict, then bring conflicting names together
- (uniquify-rationalize fix-list)))
+ (setq items (buffer-local-value 'uniquify-managed buffer))
+ (equal base (uniquify-item-base (car items)))
+ ;; Don't re-add stuff we already have. Actually this
+ ;; whole `and' test should only match at most once.
+ (not (memq (car items) fix-list)))
+ (unless (cdr items)
+ ;; If there was no conflict, the buffer-name is equal to the
+ ;; base-name and we may have missed a rename-buffer because
+ ;; of code like in set-visited-file-name:
+ ;; (or (string= new-name (buffer-name)) (rename-buffer new-name t))
+ ;; So we need to refresh the dirname of the uniquify-item.
+ (setf (uniquify-item-dirname (car items))
+ (uniquify-buffer-file-name
+ (uniquify-item-buffer (car items))))
+ ;; This shouldn't happen, but maybe there's no dirname any more.
+ (unless (uniquify-item-dirname (car items))
+ (with-current-buffer (uniquify-item-buffer (car items))
+ (setq uniquify-managed nil))
+ (setq items nil)))
+ (setq fix-list (append fix-list items))))
+ ;; selects buffers whose names may need changing, and others that
+ ;; may conflict, then bring conflicting names together
+ (uniquify-rationalize fix-list))))