How to make Dired ignore files with specific extensions

I put the following in a .emacs file:

(require 'dired-x) (add-hook 'dired-load-hook '(lambda () (require 'dired-x))) (setq dired-omit-files-p t) (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$\\|-t\\.tex$\\|-t\\.pdf$")) 

But Cx d still shows me the .pdf and .tex files. Did I misunderstand the syntax in this last line?

Bonus question: is there a way to get Dired to hide hidden directories, such as .git folders?

+8
emacs dired
source share
2 answers

Your regular expression will match *-t.tex files, not *.tex .

In the latest version of Emacs, just add the following section to ~/.emacs to filter what you want:

 (require 'dired-x) (setq-default dired-omit-files-p t) ; this is buffer-local variable (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$\\|\\.pdf$\\|\\.tex$")) 

Update: by default, dired-omit-files regexp filters special directories . and .. If you don't want this behavior, you can simply override the default values ​​(instead of inheriting them from concat):

 (setq dired-omit-files "^\\.[^.]\\|\\.pdf$\\|\\.tex$") 

The regular expression ^\\.[^.] Will match any string of length 2+, starting at the point where the second character is any character except the dot itself. This is not ideal (it will not match file names, for example "..foo"), but should be fine in most cases.

+12
source share

A simple and very general solution that does not rely on any additional functions is to make Cu s to change ls flags and update immediately (i.e. Cu s also takes care of updating, so there is very little text input). Usually you need to remove -a to hide dotfiles. But you can do everything that you can already do in the console, which is much more than a simple switching mode (due to some additional taps). And there is a history of the previous flags available, so the "switch" is also pretty fast.

+15
source share

All Articles