diff options
| author | Richard M. Stallman | 1997-09-07 06:17:29 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-09-07 06:17:29 +0000 |
| commit | 4ddd2beb6733219462026b4f20a8ca427585bea3 (patch) | |
| tree | bdaa0b5cb279131d9f8969ac896020cd082e3457 | |
| parent | 6239880d207f9990beb43708e8504bd435b873cf (diff) | |
| download | emacs-4ddd2beb6733219462026b4f20a8ca427585bea3.tar.gz emacs-4ddd2beb6733219462026b4f20a8ca427585bea3.zip | |
Rename uniquify-fix-list-* to uniquify-fix-item-*.
All callers changed.
(uniquify-rationalize-file-buffer-names):
Use directory-file-name for directories (eliminate trailing slash).
Call uniquify-fix-item-unrationalized-buffer.
(uniquify-buffer-file-name): Use directory-file-name.
(uniquify-fix-item-unrationalized-buffer): New function.
(uniquify-unrationalized-buffer): Function deleted.
| -rw-r--r-- | lisp/uniquify.el | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/lisp/uniquify.el b/lisp/uniquify.el index c7aeab5b08e..8f90ce4de40 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el | |||
| @@ -69,6 +69,8 @@ | |||
| 69 | ;; Don't call expand-file-name on nil. mernst 7 Jan 96 | 69 | ;; Don't call expand-file-name on nil. mernst 7 Jan 96 |
| 70 | ;; Check whether list-buffers-directory is bound. mernst 11 Oct 96 | 70 | ;; Check whether list-buffers-directory is bound. mernst 11 Oct 96 |
| 71 | ;; Ignore non-file non-dired buffers. Colin Rafferty <craffert@ml.com> 3 Mar 97 | 71 | ;; Ignore non-file non-dired buffers. Colin Rafferty <craffert@ml.com> 3 Mar 97 |
| 72 | ;; Use last component, not "", for file name of directories. mernst 27 Jun 97 | ||
| 73 | ;; Use directory-file-name; code cleanup. mernst 6 Sep 97 | ||
| 72 | 74 | ||
| 73 | ;; Valuable feedback was provided by | 75 | ;; Valuable feedback was provided by |
| 74 | ;; Paul Smith <psmith@baynetworks.com>, | 76 | ;; Paul Smith <psmith@baynetworks.com>, |
| @@ -150,17 +152,24 @@ variable is ignored." | |||
| 150 | (defmacro uniquify-push (item list) | 152 | (defmacro uniquify-push (item list) |
| 151 | (` (setq (, list) (cons (, item) (, list))))) | 153 | (` (setq (, list) (cons (, item) (, list))))) |
| 152 | 154 | ||
| 153 | (defmacro uniquify-fix-list-base (a) | 155 | ;; For directories, return the last component, not the empty string. |
| 154 | (` (car (, a)))) | 156 | (defun uniquify-file-name-nondirectory (file-name) |
| 157 | (file-name-nondirectory (directory-file-name file-name))) | ||
| 155 | 158 | ||
| 156 | (defmacro uniquify-fix-list-filename (a) | 159 | ;; uniquify-fix-list data structure |
| 160 | (defmacro uniquify-fix-item-base (a) | ||
| 161 | (` (car (, a)))) | ||
| 162 | (defmacro uniquify-fix-item-filename (a) | ||
| 157 | (` (car (cdr (, a))))) | 163 | (` (car (cdr (, a))))) |
| 158 | 164 | (defmacro uniquify-fix-item-buffer (a) | |
| 159 | (defmacro uniquify-fix-list-buffer (a) | ||
| 160 | (` (car (cdr (cdr (, a)))))) | 165 | (` (car (cdr (cdr (, a)))))) |
| 166 | ;; Not a macro: passed to mapcar. | ||
| 167 | (defun uniquify-fix-item-unrationalized-buffer (item) | ||
| 168 | (or (car (cdr (cdr (cdr item)))) nil)) ;maybe better in the future | ||
| 161 | 169 | ||
| 162 | (defmacro uniquify-cadddr (a) | 170 | (defun uniquify-fix-item-filename-lessp (fixlist1 fixlist2) |
| 163 | (` (car (cdr (cdr (cdr (, a))))))) | 171 | (uniquify-filename-lessp (uniquify-fix-item-filename fixlist1) |
| 172 | (uniquify-fix-item-filename fixlist2))) | ||
| 164 | 173 | ||
| 165 | ;; Internal variables used free | 174 | ;; Internal variables used free |
| 166 | (defvar uniquify-non-file-buffer-names nil) | 175 | (defvar uniquify-non-file-buffer-names nil) |
| @@ -174,14 +183,16 @@ If `uniquify-min-dir-content' > 0, always pulls that many | |||
| 174 | file name elements. Arguments cause only a subset of buffers to be renamed." | 183 | file name elements. Arguments cause only a subset of buffers to be renamed." |
| 175 | (interactive) | 184 | (interactive) |
| 176 | (let (fix-list | 185 | (let (fix-list |
| 177 | uniquify-non-file-buffer-names | 186 | uniquify-non-file-buffer-names) |
| 178 | (depth uniquify-min-dir-content)) | ||
| 179 | (let ((buffers (buffer-list))) | 187 | (let ((buffers (buffer-list))) |
| 180 | (while buffers | 188 | (while buffers |
| 181 | (let* ((buffer (car buffers)) | 189 | (let* ((buffer (car buffers)) |
| 182 | (bfn (if (eq buffer newbuf) | 190 | (bfn (if (eq buffer newbuf) |
| 183 | (and newbuffile | 191 | (and newbuffile |
| 184 | (expand-file-name newbuffile)) | 192 | (expand-file-name |
| 193 | (if (file-directory-p newbuffile) | ||
| 194 | (directory-file-name newbuffile) | ||
| 195 | newbuffile))) | ||
| 185 | (uniquify-buffer-file-name buffer))) | 196 | (uniquify-buffer-file-name buffer))) |
| 186 | (rawname (and bfn (file-name-nondirectory bfn))) | 197 | (rawname (and bfn (file-name-nondirectory bfn))) |
| 187 | (deserving (and rawname | 198 | (deserving (and rawname |
| @@ -196,23 +207,23 @@ file name elements. Arguments cause only a subset of buffers to be renamed." | |||
| 196 | ;; selects buffers whose names may need changing, and others that | 207 | ;; selects buffers whose names may need changing, and others that |
| 197 | ;; may conflict. | 208 | ;; may conflict. |
| 198 | (setq fix-list | 209 | (setq fix-list |
| 199 | (sort fix-list 'uniquify-fix-list-filename-lessp)) | 210 | (sort fix-list 'uniquify-fix-item-filename-lessp)) |
| 200 | ;; bringing conflicting names together | 211 | ;; bringing conflicting names together |
| 201 | (uniquify-rationalize-a-list fix-list depth) | 212 | (uniquify-rationalize-a-list fix-list uniquify-min-dir-content) |
| 202 | (mapcar 'uniquify-unrationalized-buffer fix-list))) | 213 | (mapcar 'uniquify-fix-item-unrationalized-buffer fix-list))) |
| 203 | 214 | ||
| 204 | ;; uniquify's version of buffer-file-name | 215 | ;; uniquify's version of buffer-file-name; result never contains trailing slash |
| 205 | (defun uniquify-buffer-file-name (buffer) | 216 | (defun uniquify-buffer-file-name (buffer) |
| 206 | "Return name of file BUFFER is visiting, or nil if none. | 217 | "Return name of file BUFFER is visiting, or nil if none. |
| 207 | Works on dired buffers as well as ordinary file-visiting buffers, | 218 | Works on dired buffers and ordinary file-visiting buffers, but no others." |
| 208 | but no others." | ||
| 209 | (or (buffer-file-name buffer) | 219 | (or (buffer-file-name buffer) |
| 210 | (and (featurep 'dired) | 220 | (and (featurep 'dired) |
| 211 | (save-excursion | 221 | (save-excursion |
| 212 | (set-buffer buffer) | 222 | (set-buffer buffer) |
| 213 | (when (eq major-mode 'dired-mode) ; do nothing if not a dired buffer | 223 | (when (eq major-mode 'dired-mode) ; do nothing if not a dired buffer |
| 214 | (if (boundp 'list-buffers-directory) ; XEmacs mightn't define this | 224 | (if (boundp 'list-buffers-directory) ; XEmacs mightn't define this |
| 215 | list-buffers-directory | 225 | (and list-buffers-directory |
| 226 | (directory-file-name list-buffers-directory)) | ||
| 216 | ;; don't use default-directory if dired-directory is nil | 227 | ;; don't use default-directory if dired-directory is nil |
| 217 | (and dired-directory | 228 | (and dired-directory |
| 218 | (expand-file-name | 229 | (expand-file-name |
| @@ -221,11 +232,6 @@ but no others." | |||
| 221 | (car dired-directory) | 232 | (car dired-directory) |
| 222 | dired-directory)))))))))) | 233 | dired-directory)))))))))) |
| 223 | 234 | ||
| 224 | (defun uniquify-fix-list-filename-lessp (fixlist1 fixlist2) | ||
| 225 | (uniquify-filename-lessp | ||
| 226 | (uniquify-fix-list-filename fixlist1 | ||
| 227 | ) (uniquify-fix-list-filename fixlist2))) | ||
| 228 | |||
| 229 | ;; This examines the filename components in reverse order. | 235 | ;; This examines the filename components in reverse order. |
| 230 | (defun uniquify-filename-lessp (s1 s2) | 236 | (defun uniquify-filename-lessp (s1 s2) |
| 231 | (let ((s1f (file-name-nondirectory s1)) | 237 | (let ((s1f (file-name-nondirectory s1)) |
| @@ -241,10 +247,6 @@ but no others." | |||
| 241 | (substring s1d 0 -1) | 247 | (substring s1d 0 -1) |
| 242 | (substring s2d 0 -1)))))))))) | 248 | (substring s2d 0 -1)))))))))) |
| 243 | 249 | ||
| 244 | ;; Was named do-the-buffers-you-couldnt-rationalize | ||
| 245 | (defun uniquify-unrationalized-buffer (item) | ||
| 246 | (or (uniquify-cadddr item) nil)) ;maybe better in the future | ||
| 247 | |||
| 248 | (defun uniquify-rationalize-a-list (fix-list depth) | 250 | (defun uniquify-rationalize-a-list (fix-list depth) |
| 249 | (let (conflicting-sublist | 251 | (let (conflicting-sublist |
| 250 | (old-name "") | 252 | (old-name "") |
| @@ -267,8 +269,8 @@ but no others." | |||
| 267 | (let (index | 269 | (let (index |
| 268 | (extra-string "") | 270 | (extra-string "") |
| 269 | (n depth) | 271 | (n depth) |
| 270 | (base (uniquify-fix-list-base item)) | 272 | (base (uniquify-fix-item-base item)) |
| 271 | (fn (uniquify-fix-list-filename item))) | 273 | (fn (uniquify-fix-item-filename item))) |
| 272 | (while (and (> n 0) | 274 | (while (and (> n 0) |
| 273 | (setq index (string-match | 275 | (setq index (string-match |
| 274 | (concat "\\(^\\|/[^/]*\\)/" | 276 | (concat "\\(^\\|/[^/]*\\)/" |
| @@ -320,8 +322,8 @@ but no others." | |||
| 320 | uniquify-buffer-name-style))))) | 322 | uniquify-buffer-name-style))))) |
| 321 | 323 | ||
| 322 | 324 | ||
| 323 | ;; Deal with conflicting-sublist, which is set by uniquify-rationalize-a-list. | 325 | ;; Deal with conflicting-sublist, all of whose elements have identical |
| 324 | ;; This is only called by uniquify-rationalize-a-list. | 326 | ;; "base" components. |
| 325 | (defun uniquify-rationalize-conflicting-sublist (conflicting-sublist old-name depth) | 327 | (defun uniquify-rationalize-conflicting-sublist (conflicting-sublist old-name depth) |
| 326 | (or (null conflicting-sublist) | 328 | (or (null conflicting-sublist) |
| 327 | (and (null (cdr conflicting-sublist)) | 329 | (and (null (cdr conflicting-sublist)) |
| @@ -333,7 +335,7 @@ but no others." | |||
| 333 | (uniquify-rationalize-a-list conflicting-sublist (1+ depth))))) | 335 | (uniquify-rationalize-a-list conflicting-sublist (1+ depth))))) |
| 334 | 336 | ||
| 335 | (defun uniquify-rename-buffer (item newname) | 337 | (defun uniquify-rename-buffer (item newname) |
| 336 | (let ((buffer (uniquify-fix-list-buffer item))) | 338 | (let ((buffer (uniquify-fix-item-buffer item))) |
| 337 | (if (not (equal newname (buffer-name buffer))) | 339 | (if (not (equal newname (buffer-name buffer))) |
| 338 | (let ((unset (current-buffer)) | 340 | (let ((unset (current-buffer)) |
| 339 | ;; avoid hooks on rename-buffer | 341 | ;; avoid hooks on rename-buffer |