+ (let ((buf (uniquify-item-buffer item)))
+ (unless (or (eq buf (current-buffer)) (not (buffer-live-p buf)))
+ (push item new-fix-list))))
+ (when new-fix-list
+ (uniquify-rationalize new-fix-list))))
+
+(defun uniquify-rationalize (fix-list)
+ ;; Set up uniquify to re-rationalize after killing/renaming
+ ;; if there is a conflict.
+ (dolist (item fix-list)
+ (with-current-buffer (uniquify-item-buffer item)
+ ;; Refresh the dirnames and proposed names.
+ (setf (uniquify-item-proposed item)
+ (uniquify-get-proposed-name (uniquify-item-base item)
+ (uniquify-item-dirname item)))
+ (setq uniquify-managed fix-list)))
+ ;; Strip any shared last directory names of the dirname.
+ (when (and (cdr fix-list) uniquify-strip-common-suffix)
+ (let ((strip t))
+ (while (let* ((base (file-name-nondirectory
+ (uniquify-item-dirname (car fix-list))))
+ (items fix-list))
+ (when (> (length base) 0)
+ (while (and strip items)
+ (unless (equal base (file-name-nondirectory
+ (uniquify-item-dirname (pop items))))
+ (setq strip nil)))
+ strip))
+ ;; It's all the same => strip.
+ (dolist (item (prog1 fix-list (setq fix-list nil)))
+ ;; Create new items because the old ones are kept (with the true
+ ;; `dirname') for later rerationalizing.
+ (push (uniquify-make-item (uniquify-item-base item)
+ (let ((f (file-name-directory
+ (uniquify-item-dirname item))))
+ (and f (directory-file-name f)))
+ (uniquify-item-buffer item)
+ (uniquify-item-proposed item))
+ fix-list)))))
+ ;; If uniquify-min-dir-content is 0, this will end up just
+ ;; passing fix-list to uniquify-rationalize-conflicting-sublist.
+ (uniquify-rationalize-a-list fix-list))
+
+(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)