mirror of
https://codeberg.org/scip/dot-emacs.git
synced 2025-12-17 04:20:57 +01:00
made 'move-file git aware
This commit is contained in:
@@ -157,6 +157,9 @@ files marked, always operate on current line in dired-mode"
|
|||||||
;; same topic. From: https://zck.org/emacs-move-file. I modified it
|
;; same topic. From: https://zck.org/emacs-move-file. I modified it
|
||||||
;; to accept a directory as target so I don't have to manually enter a
|
;; to accept a directory as target so I don't have to manually enter a
|
||||||
;; new file name if I'd like to keep the old one.
|
;; new file name if I'd like to keep the old one.
|
||||||
|
;;
|
||||||
|
;; I also incorporated git awareness into the function from:
|
||||||
|
;; https://emacsredux.com/blog/2013/05/04/rename-file-and-buffer/
|
||||||
(defun move-file (new-location)
|
(defun move-file (new-location)
|
||||||
"Write this file to NEW-LOCATION, and delete the old one."
|
"Write this file to NEW-LOCATION, and delete the old one."
|
||||||
(interactive (list (expand-file-name
|
(interactive (list (expand-file-name
|
||||||
@@ -173,11 +176,15 @@ files marked, always operate on current line in dired-mode"
|
|||||||
(message "start")
|
(message "start")
|
||||||
(let ((old-location (expand-file-name (buffer-file-name))))
|
(let ((old-location (expand-file-name (buffer-file-name))))
|
||||||
(message (format "old: %s => new: %s" old-location new-location))
|
(message (format "old: %s => new: %s" old-location new-location))
|
||||||
|
(cond
|
||||||
|
((vc-backend old-location)
|
||||||
|
(vc-rename-file old-location new-location))
|
||||||
|
(t
|
||||||
(write-file new-location t)
|
(write-file new-location t)
|
||||||
(when (and old-location
|
(when (and old-location
|
||||||
(file-exists-p new-location)
|
(file-exists-p new-location)
|
||||||
(not (string-equal old-location new-location)))
|
(not (string-equal old-location new-location)))
|
||||||
(delete-file old-location))))
|
(delete-file old-location))))))
|
||||||
|
|
||||||
;; **** dired config and key bindings
|
;; **** dired config and key bindings
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user