emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/wfnames b900a3835d 44/98: Merge branch 'devel' into main


From: ELPA Syncer
Subject: [nongnu] elpa/wfnames b900a3835d 44/98: Merge branch 'devel' into main
Date: Tue, 8 Aug 2023 04:01:22 -0400 (EDT)

branch: elpa/wfnames
commit b900a3835ddc0ee12dba3c119a82511ff4198880
Merge: 750c1370c6 f510d716b6
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>

    Merge branch 'devel' into main
---
 wfnames.el | 61 ++++++++++++++++++++++++++-----------------------------------
 1 file changed, 26 insertions(+), 35 deletions(-)

diff --git a/wfnames.el b/wfnames.el
index 94a01671ed..80176450ed 100644
--- a/wfnames.el
+++ b/wfnames.el
@@ -42,11 +42,11 @@
   "A mode to edit filenames."
   :group 'wfnames)
 
-(defcustom wfnames-create-parent-directories nil
+(defcustom wfnames-create-parent-directories t
   "Create parent directories when non nil."
   :type 'boolean)
 
-(defcustom wfnames-interactive-rename nil
+(defcustom wfnames-interactive-rename t
   "Ask confirmation when overwriting."
   :type 'boolean)
 
@@ -119,6 +119,12 @@ Special commands:
     (set (make-local-variable 'wfnames-old-files) files)
     (funcall display-fn wfnames-buffer)))
 
+(defun wfnames-ask-for-overwrite (file)
+  (or (null wfnames-interactive-rename)
+      (y-or-n-p
+       (format "File `%s' exists, overwrite? "
+               file))))
+
 (defun wfnames-commit-buffer ()
   (interactive)
   (let ((renamed 0) (skipped 0) delayed)
@@ -129,39 +135,17 @@ Special commands:
                       (let* ((beg (point-at-bol))
                              (end (point-at-eol))
                              (old (get-text-property (point) 'old-name))
-                             (new (buffer-substring-no-properties beg end)))
+                             (new (buffer-substring-no-properties beg end))
+                             ow)
                         (unless (string= old new) ; not modified, skip.
-                          (cond (;; New file exists and is one of the
-                                 ;; next files to rename, make a temp
-                                 ;; file of OLD and assign this temp
-                                 ;; file to OLD, then delay renaming
-                                 ;; to next turn.
+                          (cond (;; New file exists, rename it to a
+                                 ;; temp file to put it out of the way
+                                 ;; and delay real rename to next turn.
                                  (and (file-exists-p new)
                                       (member new wfnames-old-files)
                                       (not (assoc new delayed)))
-                                 ;; Maybe ask
-                                 (if (or (null wfnames-interactive-rename)
-                                         (y-or-n-p
-                                          (format "File `%s' exists, 
overwrite? "
-                                                  new)))
-                                     (let ((tmpfile (make-temp-name old)))
-                                       (push (cons new tmpfile) delayed)
-                                       (rename-file new tmpfile))
-                                   ;; Answer is no, skip.
-                                   (add-text-properties
-                                    beg end `(old-name ,new))
-                                   (cl-incf skipped)))
-                                (;; New file exists but is not part of
-                                 ;; the next files to rename, make a
-                                 ;; temp file of NEW and delay renaming
-                                 ;; to next turn.
-                                 (and (file-exists-p new)
-                                      (not (assoc new delayed)))
                                  ;; Maybe ask.
-                                 (if (or (null wfnames-interactive-rename)
-                                         (y-or-n-p
-                                          (format "File `%s' exists, 
overwrite? "
-                                                  new)))
+                                 (if (wfnames-ask-for-overwrite new)
                                      (let ((tmpfile (make-temp-name new)))
                                        (push (cons new tmpfile) delayed)
                                        (rename-file new tmpfile))
@@ -169,17 +153,24 @@ Special commands:
                                    (add-text-properties
                                     beg end `(old-name ,new))
                                    (cl-incf skipped)))
-                                (t ; Now really rename files.
+                                ;; Now really rename files.
+                                (t
+                                 (when (and (file-exists-p new)
+                                            (not (assoc new delayed)))
+                                   (setq ow t))
                                  (when wfnames-create-parent-directories
                                    ;; Check if base directory of new exists.
                                    (let ((basedir (file-name-directory
                                                    (directory-file-name  
new))))
                                      (unless (file-directory-p basedir)
                                        (mkdir basedir 'parents))))
-                                 (rename-file
-                                  old (if (file-directory-p new)
-                                          (file-name-as-directory new)
-                                        new))
+                                 (let ((target (if (file-directory-p new)
+                                                   (file-name-as-directory new)
+                                                 new)))
+                                   (if (and ow (wfnames-ask-for-overwrite new))
+                                       (rename-file old target ow)
+                                     (and ow (cl-incf skipped))
+                                     (and (null ow) (rename-file old target))))
                                  (add-text-properties beg end `(old-name ,new))
                                  (let* ((assoc (assoc new delayed))
                                         (tmp   (cdr assoc)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]