emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dired, toggle ls flags? [elisp]


From: Emanuel Berg
Subject: dired, toggle ls flags? [elisp]
Date: Sun, 28 Apr 2024 06:06:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

How can I hit a key, say h, to toggle the -h flag for ls
in dired?

Answer, like this!

But question, is there already a better way to do it?

Or, if you can improve what I wrote?

If there isn't such a way in core Emacs, I think such
a feature should be added to Emacs since it is really handy.

(defun dired-ls-toggle (opt)
  (let ((opt-re (format "\\(^\\|[[:blank:]]\\)%s\\([[:blank:]]\\|\\b\\)" opt)))
    (if (string-match-p opt-re dired-listing-switches)
        (setq dired-listing-switches
          (replace-regexp-in-string opt-re " " dired-listing-switches) )
      (setq dired-listing-switches (format "%s %s" dired-listing-switches opt)))
    (setq dired-listing-switches (string-clean-whitespace 
dired-listing-switches))
    (dired-sort-other dired-listing-switches) ))

(defun dired-toggle-human ()
  (interactive)
  (dired-ls-toggle "-h") )

(defun dired-toggle-modification-sort ()
  (interactive)
  (dired-ls-toggle "-t") )

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]