From c3d334502de89436da33b785706b87cfc4bb2773 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 20 Aug 2020 18:07:10 -0400 Subject: [PATCH] Dired improvements: Dired-X and functions that respect the current dir --- emacs/init.org | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/emacs/init.org b/emacs/init.org index 7850e39..a15fc31 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -4715,14 +4715,53 @@ Or Gnus can read RSS feeds directly: #+END_SRC * Dired +** Dired-X +#+BEGIN_SRC emacs-lisp + (defun dired-x-load-setup () + (require "dired-x")) + + (defun dired-x-setup () + (dired-omit-mode 1)) + + (add-hook 'dired-load-hook #'dired-x-load-setup) + (add-hook 'dired-mode-hook #'dired-x-setup) +#+END_SRC + +** Utility functions +#+BEGIN_SRC emacs-lisp + (defun dired-counsel-find-file (&optional initial-input) + (interactive) + (let ((default-directory (dired-current-directory))) + (counsel-find-file initial-input))) + + (defun dired-create-empty-file-in-current-dir (file) + (interactive (list (let ((default-directory (dired-current-directory))) + (read-file-name "Create empty file: ")))) + (dired-create-empty-file file)) + + (defun dired-do-rename-in-current-dir (&optional arg) + (interactive "P") + (let ((default-directory (dired-current-directory))) + (dired-do-rename arg))) +#+END_SRC + ** Keybindings #+BEGIN_SRC emacs-lisp - (general-def 'normal dired-mode-map "f" #'dired-create-empty-file) + (general-def 'normal dired-mode-map + "f" #'dired-create-empty-file-in-current-dir + [remap find-file] 'dired-counsel-find-file + [remap counsel-find-file] 'dired-counsel-find-file + [remap dired-do-rename] 'dired-do-rename-in-current-dir) #+END_SRC ** Dired subtree #+BEGIN_SRC emacs-lisp (use-package dired-subtree + :init + (defun dired-counsel-find-file (&optional initial-input) + (interactive) + (let ((default-directory (dired-current-directory))) + (counsel-find-file initial-input))) :general (normal dired-mode-map "TAB" 'dired-subtree-toggle) :config