all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* dired, toggle ls flags? [elisp]
@ 2024-04-28  4:06 Emanuel Berg
  2024-04-28  7:05 ` Emanuel Berg
  2024-04-28  9:16 ` Michael Heerdegen via Emacs development discussions.
  0 siblings, 2 replies; 6+ messages in thread
From: Emanuel Berg @ 2024-04-28  4:06 UTC (permalink / raw)
  To: emacs-devel

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




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-29 11:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-28  4:06 dired, toggle ls flags? [elisp] Emanuel Berg
2024-04-28  7:05 ` Emanuel Berg
2024-04-28  9:16 ` Michael Heerdegen via Emacs development discussions.
2024-04-28 23:25   ` Emanuel Berg
2024-04-29  6:17     ` Yuri Khan
2024-04-29 11:27       ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.