From 8fbdd61e1e56d7cca6761642895c87495472b43a Mon Sep 17 00:00:00 2001 From: duianto Date: Thu, 18 Oct 2018 16:18:21 +0200 Subject: [PATCH] Update renaming, move and/or rename messages problem: the rename command shows the same message: "File 'old-file-name' successfully renamed to 'new-file-name'" (without the directory path) for all three file operations: move, rename and both move & rename solution: show messages that fit the rename operation, and align the from and to path/file names, to make it easier to see what changed. And use the same message format when renaming a buffer. --- CHANGELOG.develop | 2 ++ layers/+spacemacs/spacemacs-defaults/funcs.el | 25 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index 2e1157266..1b630f719 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -1088,6 +1088,8 @@ Other: (thanks to Dominik Schrempf) - Switch recreated messages buffer to =evil-normal-state= (thanks to duianto) - Fixed =spacemacs/layouts-ts-close-other= with =ivy= (thanks to duianto) + - Fixed =spacemacs/rename-current-buffer-file=, separate messages for + move & rename, just move and just rename (thanks to duianto) *** Layer changes and fixes **** Agda - Fixes diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index 9066a0926..e6cf8dcd4 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -353,7 +353,11 @@ initialized with the current directory instead of filename." (if (and filename (file-exists-p filename)) ;; the buffer is visiting a file (let* ((dir (file-name-directory filename)) - (new-name (read-file-name "New name: " (if arg dir filename)))) + (new-name (read-file-name "New name: " (if arg dir filename))) + (new-dir (file-name-directory new-name)) + (new-short-name (file-name-nondirectory new-name)) + (file-moved-p (not (string-equal new-dir dir))) + (file-renamed-p (not (string-equal new-short-name name)))) (cond ((get-buffer new-name) (error "A buffer named '%s' already exists!" new-name)) (t @@ -372,8 +376,18 @@ initialized with the current directory instead of filename." (when (and (configuration-layer/package-used-p 'projectile) (projectile-project-p)) (call-interactively #'projectile-invalidate-cache)) - (message "File '%s' successfully renamed to '%s'" - name (file-name-nondirectory new-name))))) + (message (cond ((and file-moved-p file-renamed-p) + (concat "File Moved & Renamed\n" + "From: " filename "\n" + "To: " new-name)) + (file-moved-p + (concat "File Moved\n" + "From: " filename "\n" + "To: " new-name)) + (file-renamed-p + (concat "File Renamed\n" + "From: " name "\n" + "To: " new-short-name))))))) ;; the buffer is not visiting a file (let ((key)) (while (not (memq key '(?s ?r))) @@ -398,8 +412,9 @@ initialized with the current directory instead of filename." (setq new-name (read-string "New buffer name: ")) (keyboard-quit))) (rename-buffer new-name) - (message "Buffer '%s' successfully renamed to '%s'" - name new-name))) + (message (concat "Buffer Renamed\n" + "From: " name "\n" + "To: " new-name)))) ;; ?\a = C-g, ?\e = Esc and C-[ ((memq key '(?\a ?\e)) (keyboard-quit))))))))