diff options
| author | Stefan Monnier | 2003-05-05 16:55:38 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-05-05 16:55:38 +0000 |
| commit | 54547ff5bf0fcf0f50995c4ed6d7c5da2c990740 (patch) | |
| tree | 168c373c916324f52484a4ad514cb9007b44eebd | |
| parent | 445f98eb33691bfe7405c89049022e78b60343ed (diff) | |
| download | emacs-54547ff5bf0fcf0f50995c4ed6d7c5da2c990740.tar.gz emacs-54547ff5bf0fcf0f50995c4ed6d7c5da2c990740.zip | |
(uniquify-buffer-name-style, uniquify-after-kill-buffer-p)
(uniquify-ask-about-buffer-names-p, uniquify-ignore-buffers-re)
(uniquify-min-dir-content, uniquify-separator, uniquify-trailing-separator-p):
Remove redundant group specification.
(uniquify-file-name-nondirectory): Delete.
(uniquify-rationalize-file-buffer-names): Simplify.
Use directory names as `filename' component of uniquify-item.
(uniquify-get-proposed-name): Adjust now that `filename' does not
include `base'.
| -rw-r--r-- | lisp/uniquify.el | 74 |
1 files changed, 30 insertions, 44 deletions
diff --git a/lisp/uniquify.el b/lisp/uniquify.el index 33dfe72ae7a..f80e469feab 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el | |||
| @@ -109,22 +109,19 @@ would have the following buffer names in the various styles: | |||
| 109 | (const post-forward) | 109 | (const post-forward) |
| 110 | (const post-forward-angle-brackets) | 110 | (const post-forward-angle-brackets) |
| 111 | (const :tag "standard Emacs behavior (nil)" nil)) | 111 | (const :tag "standard Emacs behavior (nil)" nil)) |
| 112 | :require 'uniquify | 112 | :require 'uniquify) |
| 113 | :group 'uniquify) | ||
| 114 | 113 | ||
| 115 | (defcustom uniquify-after-kill-buffer-p nil | 114 | (defcustom uniquify-after-kill-buffer-p nil |
| 116 | "*If non-nil, rerationalize buffer names after a buffer has been killed. | 115 | "*If non-nil, rerationalize buffer names after a buffer has been killed. |
| 117 | This can be dangerous if Emacs Lisp code is keeping track of buffers by their | 116 | This can be dangerous if Emacs Lisp code is keeping track of buffers by their |
| 118 | names (rather than keeping pointers to the buffers themselves)." | 117 | names (rather than keeping pointers to the buffers themselves)." |
| 119 | :type 'boolean | 118 | :type 'boolean) |
| 120 | :group 'uniquify) | ||
| 121 | 119 | ||
| 122 | (defcustom uniquify-ask-about-buffer-names-p nil | 120 | (defcustom uniquify-ask-about-buffer-names-p nil |
| 123 | "*If non-nil, permit user to choose names for buffers with same base file. | 121 | "*If non-nil, permit user to choose names for buffers with same base file. |
| 124 | If the user chooses to name a buffer, uniquification is preempted and no | 122 | If the user chooses to name a buffer, uniquification is preempted and no |
| 125 | other buffer names are changed." | 123 | other buffer names are changed." |
| 126 | :type 'boolean | 124 | :type 'boolean) |
| 127 | :group 'uniquify) | ||
| 128 | 125 | ||
| 129 | ;; The default value matches certain Gnus buffers. | 126 | ;; The default value matches certain Gnus buffers. |
| 130 | (defcustom uniquify-ignore-buffers-re "^\\*\\(un\\)?sent " | 127 | (defcustom uniquify-ignore-buffers-re "^\\*\\(un\\)?sent " |
| @@ -132,13 +129,11 @@ other buffer names are changed." | |||
| 132 | For instance, set this to \"^draft-[0-9]+$\" to avoid having uniquify rename | 129 | For instance, set this to \"^draft-[0-9]+$\" to avoid having uniquify rename |
| 133 | draft buffers even if `uniquify-after-kill-buffer-p' is non-nil and the | 130 | draft buffers even if `uniquify-after-kill-buffer-p' is non-nil and the |
| 134 | visited file name isn't the same as that of the buffer." | 131 | visited file name isn't the same as that of the buffer." |
| 135 | :type '(choice (const :tag "Uniquify all buffers" nil) regexp) | 132 | :type '(choice (const :tag "Uniquify all buffers" nil) regexp)) |
| 136 | :group 'uniquify) | ||
| 137 | 133 | ||
| 138 | (defcustom uniquify-min-dir-content 0 | 134 | (defcustom uniquify-min-dir-content 0 |
| 139 | "*Minimum number of directory name components included in buffer name." | 135 | "*Minimum number of directory name components included in buffer name." |
| 140 | :type 'integer | 136 | :type 'integer) |
| 141 | :group 'uniquify) | ||
| 142 | 137 | ||
| 143 | (defcustom uniquify-separator nil | 138 | (defcustom uniquify-separator nil |
| 144 | "*String separator for buffer name components. | 139 | "*String separator for buffer name components. |
| @@ -146,16 +141,14 @@ When `uniquify-buffer-name-style' is `post-forward', separates | |||
| 146 | base file name from directory part in buffer names (default \"|\"). | 141 | base file name from directory part in buffer names (default \"|\"). |
| 147 | When `uniquify-buffer-name-style' is `reverse', separates all | 142 | When `uniquify-buffer-name-style' is `reverse', separates all |
| 148 | file name components (default \"\\\")." | 143 | file name components (default \"\\\")." |
| 149 | :type '(choice (const nil) string) | 144 | :type '(choice (const nil) string)) |
| 150 | :group 'uniquify) | ||
| 151 | 145 | ||
| 152 | (defcustom uniquify-trailing-separator-p nil | 146 | (defcustom uniquify-trailing-separator-p nil |
| 153 | "*If non-nil, add a file name separator to dired buffer names. | 147 | "*If non-nil, add a file name separator to dired buffer names. |
| 154 | If `uniquify-buffer-name-style' is `forward', add the separator at the end; | 148 | If `uniquify-buffer-name-style' is `forward', add the separator at the end; |
| 155 | if it is `reverse', add the separator at the beginning; otherwise, this | 149 | if it is `reverse', add the separator at the beginning; otherwise, this |
| 156 | variable is ignored." | 150 | variable is ignored." |
| 157 | :type 'boolean | 151 | :type 'boolean) |
| 158 | :group 'uniquify) | ||
| 159 | 152 | ||
| 160 | (defvar uniquify-list-buffers-directory-modes '(dired-mode cvs-mode) | 153 | (defvar uniquify-list-buffers-directory-modes '(dired-mode cvs-mode) |
| 161 | "List of modes for which uniquify should obey `list-buffers-directory'. | 154 | "List of modes for which uniquify should obey `list-buffers-directory'. |
| @@ -164,10 +157,6 @@ contains the name of the directory which the buffer is visiting.") | |||
| 164 | 157 | ||
| 165 | ;;; Utilities | 158 | ;;; Utilities |
| 166 | 159 | ||
| 167 | ;; For directories, return the last component, not the empty string. | ||
| 168 | (defun uniquify-file-name-nondirectory (file-name) | ||
| 169 | (file-name-nondirectory (directory-file-name file-name))) | ||
| 170 | |||
| 171 | ;; uniquify-fix-list data structure | 160 | ;; uniquify-fix-list data structure |
| 172 | (defstruct (uniquify-item | 161 | (defstruct (uniquify-item |
| 173 | (:constructor nil) (:copier nil) | 162 | (:constructor nil) (:copier nil) |
| @@ -185,25 +174,25 @@ If `uniquify-min-dir-content' > 0, always pulls that many | |||
| 185 | file name elements. | 174 | file name elements. |
| 186 | Arguments NEWBUFFILE and NEWBUF cause only a subset of buffers to be renamed." | 175 | Arguments NEWBUFFILE and NEWBUF cause only a subset of buffers to be renamed." |
| 187 | (interactive) | 176 | (interactive) |
| 188 | (let (fix-list | 177 | (when newbuffile |
| 189 | (newbuffile-nd (and newbuffile | 178 | (setq newbuffile (expand-file-name (directory-file-name newbuffile)))) |
| 190 | (uniquify-file-name-nondirectory newbuffile)))) | 179 | (let ((fix-list nil) |
| 180 | (base (and newbuffile (file-name-nondirectory newbuffile)))) | ||
| 191 | (dolist (buffer (buffer-list)) | 181 | (dolist (buffer (buffer-list)) |
| 192 | (let ((bufname (buffer-name buffer)) | 182 | (let ((bufname (buffer-name buffer)) |
| 193 | bfn rawname proposed) | 183 | bfn rawname) |
| 194 | (if (and (not (and uniquify-ignore-buffers-re | 184 | (when (and (not (and uniquify-ignore-buffers-re |
| 195 | (string-match uniquify-ignore-buffers-re | 185 | (string-match uniquify-ignore-buffers-re |
| 196 | bufname))) | 186 | bufname))) |
| 197 | (setq bfn (if (eq buffer newbuf) | 187 | (setq bfn (if (eq buffer newbuf) newbuffile |
| 198 | (when newbuffile | 188 | (uniquify-buffer-file-name buffer))) |
| 199 | (expand-file-name | 189 | (setq rawname (file-name-nondirectory bfn)) |
| 200 | (directory-file-name newbuffile))) | 190 | (or (null base) (equal rawname base))) |
| 201 | (uniquify-buffer-file-name buffer))) | 191 | (when (setq bfn (file-name-directory bfn)) ;Strip off the `base'. |
| 202 | (setq rawname (uniquify-file-name-nondirectory bfn)) | 192 | (setq bfn (directory-file-name bfn))) ;Strip trailing slash. |
| 203 | (or (not newbuffile) | 193 | (push (uniquify-make-item rawname bfn buffer |
| 204 | (equal rawname newbuffile-nd)) | 194 | (uniquify-get-proposed-name rawname bfn)) |
| 205 | (setq proposed (uniquify-get-proposed-name rawname bfn))) | 195 | fix-list)))) |
| 206 | (push (uniquify-make-item rawname bfn buffer proposed) fix-list)))) | ||
| 207 | ;; selects buffers whose names may need changing, and others that | 196 | ;; selects buffers whose names may need changing, and others that |
| 208 | ;; may conflict, then bring conflicting names together | 197 | ;; may conflict, then bring conflicting names together |
| 209 | (uniquify-rationalize-a-list fix-list))) | 198 | (uniquify-rationalize-a-list fix-list))) |
| @@ -252,12 +241,11 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." | |||
| 252 | 241 | ||
| 253 | (defun uniquify-get-proposed-name (base filename &optional depth) | 242 | (defun uniquify-get-proposed-name (base filename &optional depth) |
| 254 | (unless depth (setq depth uniquify-min-dir-content)) | 243 | (unless depth (setq depth uniquify-min-dir-content)) |
| 255 | (assert (equal base (uniquify-file-name-nondirectory filename))) | 244 | (assert (equal (directory-file-name filename) filename)) ;No trailing slash. |
| 256 | (assert (equal (directory-file-name filename) filename)) | ||
| 257 | 245 | ||
| 258 | ;; Distinguish directories by adding extra separator. | 246 | ;; Distinguish directories by adding extra separator. |
| 259 | (if (and uniquify-trailing-separator-p | 247 | (if (and uniquify-trailing-separator-p |
| 260 | (file-directory-p filename) | 248 | (file-directory-p (expand-file-name base filename)) |
| 261 | (not (string-equal base ""))) | 249 | (not (string-equal base ""))) |
| 262 | (cond ((eq uniquify-buffer-name-style 'forward) | 250 | (cond ((eq uniquify-buffer-name-style 'forward) |
| 263 | (setq base (file-name-as-directory base))) | 251 | (setq base (file-name-as-directory base))) |
| @@ -267,10 +255,10 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." | |||
| 267 | 255 | ||
| 268 | (let ((extra-string nil) | 256 | (let ((extra-string nil) |
| 269 | (n depth)) | 257 | (n depth)) |
| 270 | (while (and (> n 0) filename | 258 | (while (and (> n 0) filename) |
| 271 | (setq filename (file-name-directory filename)) | ||
| 272 | (setq filename (directory-file-name filename))) | ||
| 273 | (let ((file (file-name-nondirectory filename))) | 259 | (let ((file (file-name-nondirectory filename))) |
| 260 | (when (setq filename (file-name-directory filename)) | ||
| 261 | (setq filename (directory-file-name filename))) | ||
| 274 | (setq n (1- n)) | 262 | (setq n (1- n)) |
| 275 | (push (if (zerop (length file)) ;nil or "". | 263 | (push (if (zerop (length file)) ;nil or "". |
| 276 | (prog1 "" (setq filename nil)) ;Could be `filename' iso "". | 264 | (prog1 "" (setq filename nil)) ;Could be `filename' iso "". |
| @@ -278,9 +266,7 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil." | |||
| 278 | extra-string))) | 266 | extra-string))) |
| 279 | (when (zerop n) | 267 | (when (zerop n) |
| 280 | (if (and filename extra-string | 268 | (if (and filename extra-string |
| 281 | (setq filename (file-name-directory filename)) | 269 | (equal filename (file-name-directory filename))) |
| 282 | (equal filename | ||
| 283 | (file-name-directory (directory-file-name filename)))) | ||
| 284 | ;; We're just before the root. Let's add the leading / already. | 270 | ;; We're just before the root. Let's add the leading / already. |
| 285 | ;; With "/a/b"+"/c/d/b" this leads to "/a/b" and "d/b" but with | 271 | ;; With "/a/b"+"/c/d/b" this leads to "/a/b" and "d/b" but with |
| 286 | ;; "/a/b"+"/c/a/b" this leads to "/a/b" and "a/b". | 272 | ;; "/a/b"+"/c/a/b" this leads to "/a/b" and "a/b". |