summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-03-23 00:34:25 -0400
committerKyle Meyer <kyle@kyleam.com>2015-03-23 00:34:25 -0400
commitf2705344bf8e95908188c8bdd5fe715761a3d8fe (patch)
treec4264326a76291bb5124cc0862e1d5144ba5d5ba
parent817d98514dede0036f9a8d5afde72805eb2b3647 (diff)
downloademacs.d-f2705344bf8e95908188c8bdd5fe715761a3d8fe.tar.gz
Add dired-copy-and-edit command
-rw-r--r--lisp/init-dired.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/lisp/init-dired.el b/lisp/init-dired.el
index 2be6a2a..481da6e 100644
--- a/lisp/init-dired.el
+++ b/lisp/init-dired.el
@@ -65,8 +65,29 @@
(interactive)
(view-file-other-window (dired-get-file-for-visit)))
+(defun km/dired-copy-and-edit ()
+ "Copy file and enter `wdired-mode' for completing rename."
+ (interactive)
+ (unless (derived-mode-p 'dired-mode)
+ (user-error "Must be in a Dired buffer"))
+ (let* ((fname (dired-get-filename))
+ (flag "---copy---")
+ (new-fname (concat fname flag)))
+ (when (file-directory-p fname)
+ (user-error "File cannot be directory"))
+ (copy-file fname new-fname)
+ (dired-revert)
+ (wdired-change-to-wdired-mode)
+ (goto-char (point-min))
+ (re-search-forward (format "%s\\(%s\\)"
+ (file-name-nondirectory fname)
+ flag))
+ (replace-match "" t nil nil 1)))
+
;; This overrides the binding for `list-directory'.
(global-set-key (kbd "C-x C-d") 'km/dired-switch-to-buffer)
+(define-key dired-mode-map "c" 'dired-do-copy)
+(define-key dired-mode-map "C" 'km/dired-copy-and-edit)
;; This overrides `dired-do-run-mail'.
(define-key dired-mode-map "V" 'km/dired-view-file-other-window)