]> git.eshelyaron.com Git - emacs.git/commitdiff
Make prettier unique file names in eww
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 24 Dec 2015 21:47:58 +0000 (22:47 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 25 Dec 2015 16:02:48 +0000 (17:02 +0100)
(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 edfdd0a6cbdfa9e5e4bd0553e2b489401ca39266)

lisp/net/eww.el

index 90ddd05b845262d3b51cc3292c4535d896d169c2..a22664bfbb542d7b103a60f712b583d3c4875d01 100644 (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)))