166 |
;; Internal variables used free |
;; Internal variables used free |
167 |
(defvar uniquify-possibly-resolvable nil) |
(defvar uniquify-possibly-resolvable nil) |
168 |
|
|
169 |
|
(defvar uniquify-managed nil |
170 |
|
"Non-nil if the name of this buffer is managed by uniquify.") |
171 |
|
(make-variable-buffer-local 'uniquify-managed) |
172 |
|
(put 'uniquify-managed 'permanent-local t) |
173 |
|
|
174 |
;;; Main entry point. |
;;; Main entry point. |
175 |
|
|
176 |
(defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf) |
(defun uniquify-rationalize-file-buffer-names (&optional newbuffile newbuf) |
189 |
(when (and (not (and uniquify-ignore-buffers-re |
(when (and (not (and uniquify-ignore-buffers-re |
190 |
(string-match uniquify-ignore-buffers-re |
(string-match uniquify-ignore-buffers-re |
191 |
bufname))) |
bufname))) |
192 |
|
;; Only try to rename buffers we actually manage. |
193 |
|
(or (buffer-local-value 'uniquify-managed buffer) |
194 |
|
(eq buffer newbuf)) |
195 |
(setq bfn (if (eq buffer newbuf) newbuffile |
(setq bfn (if (eq buffer newbuf) newbuffile |
196 |
(uniquify-buffer-file-name buffer))) |
(uniquify-buffer-file-name buffer))) |
197 |
(setq rawname (file-name-nondirectory bfn)) |
(setq rawname (file-name-nondirectory bfn)) |
201 |
(push (uniquify-make-item rawname bfn buffer |
(push (uniquify-make-item rawname bfn buffer |
202 |
(uniquify-get-proposed-name rawname bfn)) |
(uniquify-get-proposed-name rawname bfn)) |
203 |
fix-list)))) |
fix-list)))) |
204 |
|
;; Mark the new buffer as managed. |
205 |
|
(when newbuf |
206 |
|
(with-current-buffer newbuf |
207 |
|
(setq uniquify-managed t))) |
208 |
;; selects buffers whose names may need changing, and others that |
;; selects buffers whose names may need changing, and others that |
209 |
;; may conflict, then bring conflicting names together |
;; may conflict, then bring conflicting names together |
210 |
(uniquify-rationalize-a-list fix-list))) |
(uniquify-rationalize-a-list fix-list))) |
334 |
(unless (equal newname (buffer-name buffer)) |
(unless (equal newname (buffer-name buffer)) |
335 |
(with-current-buffer buffer |
(with-current-buffer buffer |
336 |
(let ((uniquify-buffer-name-style nil)) ;Avoid hooks on rename-buffer. |
(let ((uniquify-buffer-name-style nil)) ;Avoid hooks on rename-buffer. |
337 |
;; Pass the `unique' arg, just in case. |
;; Pass the `unique' arg, so the advice doesn't mark it as unmanaged. |
338 |
(rename-buffer newname t)))))) |
(rename-buffer newname t)))))) |
339 |
|
|
340 |
;;; Hooks from the rest of Emacs |
;;; Hooks from the rest of Emacs |
356 |
|
|
357 |
(defadvice rename-buffer (after rename-buffer-uniquify activate) |
(defadvice rename-buffer (after rename-buffer-uniquify activate) |
358 |
"Uniquify buffer names with parts of directory name." |
"Uniquify buffer names with parts of directory name." |
359 |
(if (and uniquify-buffer-name-style |
(if (null (ad-get-arg 1)) ; no UNIQUE argument. |
360 |
;; UNIQUE argument |
;; Mark this buffer so it won't be renamed by uniquify. |
361 |
(ad-get-arg 1)) |
(setq uniquify-managed nil) |
362 |
(progn |
(when uniquify-buffer-name-style |
363 |
(if uniquify-after-kill-buffer-p |
(if uniquify-after-kill-buffer-p |
364 |
;; call with no argument; rationalize vs. old name as well as new |
;; call with no argument; rationalize vs. old name as well as new |
365 |
(uniquify-rationalize-file-buffer-names) |
(progn (setq uniquify-managed t) |
366 |
;; call with argument: rationalize vs. new name only |
(uniquify-rationalize-file-buffer-names)) |
367 |
(uniquify-rationalize-file-buffer-names |
;; call with argument: rationalize vs. new name only |
368 |
(uniquify-buffer-file-name (current-buffer)) (current-buffer))) |
(uniquify-rationalize-file-buffer-names |
369 |
(setq ad-return-value (buffer-name (current-buffer)))))) |
(uniquify-buffer-file-name (current-buffer)) (current-buffer))) |
370 |
|
(setq ad-return-value (buffer-name (current-buffer)))))) |
371 |
|
|
372 |
(defadvice create-file-buffer (after create-file-buffer-uniquify activate) |
(defadvice create-file-buffer (after create-file-buffer-uniquify activate) |
373 |
"Uniquify buffer names with parts of directory name." |
"Uniquify buffer names with parts of directory name." |
388 |
(defun uniquify-delay-rationalize-file-buffer-names () |
(defun uniquify-delay-rationalize-file-buffer-names () |
389 |
"Add `delayed-uniquify-rationalize-file-buffer-names' to `post-command-hook'. |
"Add `delayed-uniquify-rationalize-file-buffer-names' to `post-command-hook'. |
390 |
For use on, eg, `kill-buffer-hook', to rationalize *after* buffer deletion." |
For use on, eg, `kill-buffer-hook', to rationalize *after* buffer deletion." |
391 |
(if (and uniquify-buffer-name-style |
(if (and uniquify-managed |
392 |
|
uniquify-buffer-name-style |
393 |
uniquify-after-kill-buffer-p |
uniquify-after-kill-buffer-p |
394 |
;; Rationalizing is costly, so don't do it for temp buffers. |
;; Rationalizing is costly, so don't do it for temp buffers. |
395 |
(uniquify-buffer-file-name (current-buffer))) |
(uniquify-buffer-file-name (current-buffer))) |