UP | HOME

Dired Configuration

Table of Contents


Dired

The following customizations make emacs dired mode behave in a similar fashion to other file browsing tools such as midnight commander. While there are many great file management tools out there. I keep coming back to emacs dired because of the keyboard commands and flexibility.

(use-package dired
  :straight (:type built-in)
  :defer t
  :custom
  (dired-kill-when-opening-new-dired-buffer t)
  (dired-dwim-target t))

Close Dired Buffers When Another is Opened

When navigating through a series of Dired buffers, all of the old locations that were traversed through are still open as Dired buffers. This can create a lot of open buffers to clean up later. Luckily, there is an option (introduced in Emacs 28) to automatically kill old Dired buffers when a new buffer is opened using the option dired-kill-when-opening-new-dired-buffer

(dired-kill-when-opening-new-dired-buffer t)

Move/Rename/Copy Files to Another Pane

This will cause emacs to default to moving/copying/renaming files from the directory in one dired buffer to another in a split-window. This will allow emacs to operate more like midnight commander, total commander, double commander, etc.

(dired-dwim-target t)

Dired Hacks

Dired Hacks is a series of modifications to add features to Dired.

Dired Collapse

Dired colapse will show the full path in a dired buffer for paths that contain only a single file.

(use-package dired-collapse
  :straight t
  :after dired
  :hook
  (dired-mode . dired-collapse-mode))

Dired Open

Dired Open adds extra hooks to dired-find-file which search for alternative ways to open files in Dired.

(use-package dired-open
  :straight t
  :after dired
  :init
  (whicher "xdg-open")
  :config
  (define-key dired-mode-map (kbd "o") #'dired-open-xdg))

xdg-open

When opening files in Emacs such as media files, xdg-open can be used to open the preferred application for that particular file extension. Dired Open has a function dired-open-xdg that will open the file on the current line in Dired using xdg-open.

First, whicher can be used to see if xdg-open is installed on the system.

(whicher "xdg-open")

The following line will bind the o key to dired-open-xdg:

(define-key dired-mode-map (kbd "o") #'dired-open-xdg)

This can also be configured to work in Sunrise Commander using the sr-mode-map:

(define-key sr-mode-map (kbd "o") #'dired-open-xdg)

Disc Usage

Disc usage is a tool that can be used to determine the amount of memory a directory uses in the file system.

(use-package disk-usage
  :straight t
  :defer t)

Dired Async

(use-package async
  :straight t
  :defer t
  :init
  (autoload 'dired-async-mode "dired-async.el" nil t)
  :hook
  (dired . dired-async-mode))

Rclone Tools

Rclone tools is a package that used the Emacs completing-read function to simplify running the rclone program from within Emacs and make it simpler to create scripts using Emacs lisp.

(use-package rclone-tools
  :straight (rclone-tools :host github
                          :repo "tfree87/emacs-rclone-tools"
                          :branch "main")
  :defer t
  :init (whicher "rclone"))

The following function will execute the rclone command line tool

(defun rclone-sync (source dest &optional rclone-path rclone-config)
  "Sync DEST with SOURCE using rclone.
The path to the rlcone executable can be set with RCLONE-PATH.
The rclone configuration can be set with RCLONE-CONFIG."
  (interactive)
  (let ((rclone-path (or rclone-path "rclone"))
        (rclone-config (or rclone-config nil))
        (config-option
         (if rclone-config
             (concat " --config " rclone-config)
           (nil))))
    (eshell-command
     (concat rclone-path
             config-option
             " -vP sync "
             source
             " "
             dest))))

End

Tell Emacs what feature this file provides.

(provide 'freemacs-dired)

;;; freemacs-dired.el ends here

Date: Time-stamp: <2022-07-21 Thu 18:25>

Author: Thomas Freeman

Created: 2022-07-21 Thu 18:26

Validate