Update file renaming, handle same new and old name

problem:
renaming a file to it's current name, results in the message:
"File 'current-name' successfully renamed to 'current-name'"

solution:
when the new and old names are the same, show a rename failed message, and call
the rename function again
This commit is contained in:
duianto 2018-10-18 14:50:48 +02:00 committed by smile13241324
parent 8fbdd61e1e
commit 4c728f041a
2 changed files with 36 additions and 0 deletions

View file

@ -1090,6 +1090,8 @@ Other:
- 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)
- Fixed =spacemacs/rename-current-buffer-file= handle same new and old name
(thanks to duianto)
*** Layer changes and fixes
**** Agda
- Fixes

View file

@ -360,6 +360,10 @@ initialized with the current directory instead of filename."
(file-renamed-p (not (string-equal new-short-name name))))
(cond ((get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name))
((string-equal new-name filename)
(spacemacs/show-hide-helm-or-ivy-prompt-msg
"Rename failed! Same new and old name" 1.5)
(spacemacs/rename-current-buffer-file))
(t
(let ((dir (file-name-directory new-name)))
(when (and (not (file-exists-p dir))
@ -418,6 +422,36 @@ initialized with the current directory instead of filename."
;; ?\a = C-g, ?\e = Esc and C-[
((memq key '(?\a ?\e)) (keyboard-quit))))))))
(defun spacemacs/show-hide-helm-or-ivy-prompt-msg (msg sec)
"Show a MSG at the helm or ivy prompt for SEC.
With Helm, remember the path, then restore it after SEC.
With Ivy, the path isn't editable, just remove the MSG after SEC."
(run-at-time
0 nil
#'(lambda (msg sec)
(let* ((prev-prompt-contents
(buffer-substring (line-beginning-position)
(line-end-position)))
(prev-prompt-contents-p
(not (string= prev-prompt-contents "")))
(helmp (fboundp 'helm-mode)))
(when prev-prompt-contents-p
(delete-region (line-beginning-position)
(line-end-position)))
(insert (propertize msg 'face 'warning))
;; stop checking for candidates
;; and update the helm prompt
(when helmp (helm-suspend-update t))
(sit-for sec)
(delete-region (line-beginning-position)
(line-end-position))
(when prev-prompt-contents-p
(insert prev-prompt-contents)
;; start checking for candidates
;; and update the helm prompt
(when helmp (helm-suspend-update nil)))))
msg sec))
(defun spacemacs/delete-file (filename &optional ask-user)
"Remove specified file or directory.