1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-28 07:45:00 +00:00

Make prettier unique file names in eww

(eww-make-unique-file-name): Make unique file names by making
files like foo(2).jpg instead of foo(1)(2).jpg.

Backport:

(cherry picked from commit edfdd0a6cb)
This commit is contained in:
Lars Ingebrigtsen 2015-12-24 22:47:58 +01:00
parent 90f82ffa5d
commit a7143faf48

View File

@ -1438,13 +1438,14 @@ Differences in #targets are ignored."
(setq file "!"))
((string-match "\\`[.]" file)
(setq file (concat "!" file))))
(let ((count 1))
(let ((count 1)
(stem file)
(suffix ""))
(when (string-match "\\`\\(.*\\)\\([.][^.]+\\)" file)
(setq stem (match-string 1)
suffix (match-string 2)))
(while (file-exists-p (expand-file-name file directory))
(setq file
(if (string-match "\\`\\(.*\\)\\([.][^.]+\\)" file)
(format "%s(%d)%s" (match-string 1 file)
count (match-string 2 file))
(format "%s(%d)" file count)))
(setq file (format "%s(%d)%s" stem count suffix))
(setq count (1+ count)))
(expand-file-name file directory)))