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:
parent
8fbdd61e1e
commit
4c728f041a
|
@ -1090,6 +1090,8 @@ Other:
|
||||||
- Fixed =spacemacs/layouts-ts-close-other= with =ivy= (thanks to duianto)
|
- Fixed =spacemacs/layouts-ts-close-other= with =ivy= (thanks to duianto)
|
||||||
- Fixed =spacemacs/rename-current-buffer-file=, separate messages for
|
- Fixed =spacemacs/rename-current-buffer-file=, separate messages for
|
||||||
move & rename, just move and just rename (thanks to duianto)
|
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
|
*** Layer changes and fixes
|
||||||
**** Agda
|
**** Agda
|
||||||
- Fixes
|
- Fixes
|
||||||
|
|
|
@ -360,6 +360,10 @@ initialized with the current directory instead of filename."
|
||||||
(file-renamed-p (not (string-equal new-short-name name))))
|
(file-renamed-p (not (string-equal new-short-name name))))
|
||||||
(cond ((get-buffer new-name)
|
(cond ((get-buffer new-name)
|
||||||
(error "A buffer named '%s' already exists!" 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
|
(t
|
||||||
(let ((dir (file-name-directory new-name)))
|
(let ((dir (file-name-directory new-name)))
|
||||||
(when (and (not (file-exists-p dir))
|
(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-[
|
;; ?\a = C-g, ?\e = Esc and C-[
|
||||||
((memq key '(?\a ?\e)) (keyboard-quit))))))))
|
((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)
|
(defun spacemacs/delete-file (filename &optional ask-user)
|
||||||
"Remove specified file or directory.
|
"Remove specified file or directory.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue