(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)))