How to adjust dired-omit-mode

[Origin]: https://emacs.stackexchange.com/questions/19558/how-to-adjust-dired-omit-mode

Goal:

  • When dired is opened by default hidden files should be hidden.
  • When the user clicks “M-q” hidden files must be shown except for “.” and “..”

I tried the following:

;don't show hidden files
(setq dired-omit-files "^\\..*$")
(defun swap-omit-files ()
  "Show/hide hidden files except . and .."
  (interactive)
  (if (string= dired-omit-files "^\\..*$")
      (setq dired-omit-files "^\\.\\.?$")
    (setq dired-omit-files "^\\..*$")
    )
  )

(add-hook 'dired-mode-hook
          (lambda ()
            (setq dired-omit-mode t)
            (define-key dired-mode-map (kbd "M-q") 'swap-omit-files)
            ))
Hidden file are indeed hidden by default, but something is wrong with swap-omit-files --- the hidden files are not shown.

How to fix?

shareimprove this question

 

This worked. We needed to revert-buffer after changing dired-omit-files:

(defun swap-omit-files ()
  "Show/hide hidden files except . and .."
  (interactive)
  (if (string= dired-omit-files "^\\..*$")
      (setq dired-omit-files "^\\.\\.?$")
    (setq dired-omit-files "^\\..*$")
    )
  (revert-buffer)
  )
shareimprove this answer
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s