2

This sample code doesn't work:

(defun toggle-hidden-in-dired ()
  (interactive)
  (setq dired-listing-switches 
        (if (equal dired-listing-switches "-l --group-directories-first")
            "-la --group-directories-first"
          "-l --group-directories-first"))
  (revert-buffer))
2
  • You probably have set up different flags for ls in dired, and this code makes assumptions about them. I can post more reliable code from my init ifle later. – user12563 Apr 4 '19 at 15:02
  • I wrote this generic higher-order function that will return functions that toggle dired flags: github.com/DoMiNeLa10/.emacs.d/blob/master/config/…. You need to put it in a file that has lexical-scoping set to t, and then you can bind it to a key like this: github.com/DoMiNeLa10/.emacs.d/blob/master/config/…. – user12563 Apr 4 '19 at 15:42
1

Try this instead:

(defun toggle-hidden-in-dired ()
  (interactive)
  (setq dired-actual-switches  (if (equal dired-actual-switches
                                          "-l --group-directories-first")
                                   "-la --group-directories-first"
                                 "-l --group-directories-first"))
  (dired-readin))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.