;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/dired-my.el (require 'dired) (require 'super) (require 'scroll) (require 'files-my) (require 'w3m-my) (setq dired-auto-revert-buffer #'dired-directory-changed-p) ;; delete (setq dired-recursive-deletes 'always) (setq dired-deletion-confirmer '(lambda (x) t)) ; no confirm ;; dired ls (defvar dired-ls-human nil) (defvar dired-base-ls-options "-AGlX --group-directories-first") (setq dired-listing-switches dired-base-ls-options) (defun dired-toggle-human () (interactive) (if (setq dired-ls-human (not dired-ls-human)) (dired-sort-other (format "%s -h" dired-base-ls-options)) (dired-sort-other dired-base-ls-options) )) (setq completion-ignored-extensions (nconc completion-ignored-extensions (list ".bcf" ".run.xml")) ) (defun dired-toggle-mark () (interactive) (beginning-of-line) (if (= dired-marker-char (char-after)) (dired-unmark 1) (dired-mark 1) )) (defun dired-kill-path () "Kill the current file's path." (interactive) (kill-new (abbreviate-file-name (dired-get-filename))) ) (defun dired-kill-dir-path () "Kill the current directory's path" (interactive) (kill-new (dired-current-directory) )) (defun dired-do-rename-suggest () "Rename a file; use its current name as the default suggestion." (interactive) (let*((file (dired-get-filename)) (old-name (dired-get-filename 'no-dir)) (new-name (read-from-minibuffer "rename to: " old-name)) ) (dired-rename-file file new-name nil) ; (NOT) OK-IF-ALREADY-EXISTS (revert-buffer) )) (defun replace-regexp-in-marked (regexp to-string) (interactive "sRegexp: \nsTo: ") (save-window-excursion (let ((the-regexp regexp) (the-to-string to-string) (case-fold-search t) ) (dolist (f (dired-get-marked-files)) (find-file f) (while (re-search-forward the-regexp nil t) ; BOUND NOERROR (replace-match to-string nil nil)) ; FIXEDCASE LITERAL (save-buffer) ))) (dired-unmark-all-marks) ) (defun dired-invoke-touch (filename) "Invoke touch \(the shell command\) in the dired directory,\ without considering the currently selected file." (interactive "s touch: ") (shell-command (format "touch %s/%s" dired-directory filename)) (revert-buffer) ) (defun dired-find-file-chase-symlink () "Find the dired selected file; chase it if it is a symlink." (interactive) (find-whatever-file (file-truename (dired-get-file-for-visit))) ) (defun dired-first-file () (interactive) (goto-char (point-min)) (dired-next-line 2) ) (defun dired-last-file () (interactive) (goto-char (point-max)) (dired-previous-line 1) ) (defun dired-init-keys () (let ((the-map dired-mode-map)) (disable-super-global-keys the-map) ;; new file/directory (define-key the-map "t" #'dired-invoke-touch) (define-key the-map "m" #'dired-create-directory) ;; do with file (define-key the-map "s" #'dired-kill-path) (define-key the-map "u" #'dired-toggle-mark) (define-key the-map "D" #'dired-do-delete) (define-key the-map "c" #'dired-do-copy) (define-key the-map "r" #'dired-do-rename-suggest) (define-key the-map "\r" #'dired-find-file-chase-symlink) (define-key the-map "a" #'dired-view-in-w3m) ;; navigate (define-key the-map "\C-oi" #'dired-first-file) ; first/last file (define-key the-map "\C-ok" #'dired-last-file) (define-key the-map "i" #'dired-previous-line) ; prev/next line (define-key the-map "k" #'dired-next-line) (define-key the-map "w" #'dired-up-directory) ; directory (define-key the-map "b" #'dired-up-directory) ;; scroll (define-key the-map "I" #'scroll-up-other-window) (define-key the-map "K" #'scroll-down-other-window) ;; misc (define-key the-map "h" #'dired-toggle-human) ) ) (dired-init-keys) (add-hook 'dired-mode-hook #'dired-init-keys) (provide 'dired-my)