diff --git a/config.org b/config.org index 88cb9b0..fab073a 100644 --- a/config.org +++ b/config.org @@ -1896,6 +1896,80 @@ ;; (define-key dired-mode-map (kbd "W") 'dired-browse-with-w3m) #+end_src +*** rename-follow +#+begin_src emacs-lisp + (defun my/dired-do-create-files (op-symbol file-creator operation arg + &optional marker-char op1 + how-to) + (or op1 (setq op1 operation)) + (let* ((fn-list (dired-get-marked-files nil arg)) + (rfn-list (mapcar #'dired-make-relative fn-list)) + (dired-one-file ; fluid variable inside dired-create-files + (and (consp fn-list) (null (cdr fn-list)) (car fn-list))) + (target-dir (dired-dwim-target-directory)) + (default (and dired-one-file + (not dired-dwim-target) ; Bug#25609 + (expand-file-name (file-name-nondirectory (car fn-list)) + target-dir))) + (defaults (dired-dwim-target-defaults fn-list target-dir)) + (target (expand-file-name ; fluid variable inside dired-create-files + (minibuffer-with-setup-hook + (lambda () + (set (make-local-variable 'minibuffer-default-add-function) nil) + (setq minibuffer-default defaults)) + (dired-mark-read-file-name + (concat (if dired-one-file op1 operation) " %s to: ") + target-dir op-symbol arg rfn-list default)))) + (into-dir (cond ((null how-to) + ;; Allow users to change the letter case of + ;; a directory on a case-insensitive + ;; filesystem. If we don't test these + ;; conditions up front, file-directory-p + ;; below will return t on a case-insensitive + ;; filesystem, and Emacs will try to move + ;; foo -> foo/foo, which fails. + (if (and (file-name-case-insensitive-p (car fn-list)) + (eq op-symbol 'move) + dired-one-file + (string= (downcase + (expand-file-name (car fn-list))) + (downcase + (expand-file-name target))) + (not (string= + (file-name-nondirectory (car fn-list)) + (file-name-nondirectory target)))) + nil + (file-directory-p target))) + ((eq how-to t) nil) + (t (funcall how-to target))))) + (if (and (consp into-dir) (functionp (car into-dir))) + (apply (car into-dir) operation rfn-list fn-list target (cdr into-dir)) + (if (not (or dired-one-file into-dir)) + (error "Marked %s: target must be a directory: %s" operation target)) + ;; rename-file bombs when moving directories unless we do this: + (or into-dir (setq target (directory-file-name target))) + (dired-create-files + file-creator operation fn-list + (if into-dir ; target is a directory + ;; This function uses fluid variable target when called + ;; inside dired-create-files: + (lambda (from) + (expand-file-name (file-name-nondirectory from) target)) + (lambda (_from) target)) + marker-char) + (dired target)))) + + (defun my/dired-rename-follow (orig &optional arg) + (when arg + (advice-add #'dired-do-create-files :override #'my/dired-do-create-files)) + (funcall orig nil) + (when arg + (advice-remove #'dired-do-create-files #'my/dired-do-create-files))) + + (advice-add #'dired-do-rename + :around + #'my/dired-rename-follow) +#+end_src ** Elfeed *** Setup feeds #+BEGIN_SRC emacs-lisp