如何让Dired忽略具有特定扩展名的文件 [英] How to get Dired to ignore files with specific extensions
问题描述
我将以下内容放在我的.emacs文件中:
I put the following in my .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$"))
但是 Cx d
仍然显示我.pdf和.tex文件。在最后一行我有错误的语法吗?
But C-x d
still shows me .pdf and .tex files. Did I get the syntax wrong in that last line?
奖金问题:有没有办法让Dired隐藏隐藏的目录,如.git文件夹?
Bonus question: Is there a way to get Dired to hide hidden directories, like .git folders?
推荐答案
您的正则表达式将匹配 * - t.tex
文件,而不是 *。tex
一个。
Your regexp will match *-t.tex
files, not *.tex
ones.
使用最新版本的Emacs,将以下部分添加到〜/ .emacs
过滤你想要的东西:
With recent version of Emacs, it should be sufficient to 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$"))
更新:默认情况下, dired-omit-files regexp过滤掉特殊目录。
和。
。如果你不想要这个行为,你可以覆盖默认值(而不是用 concat 继承它们):
Update: by default, dired-omit-files regexp filters out special directories .
and ..
. If you don't want this behavior, you can just override defaults (instead of inheriting them with concat):
(setq dired-omit-files "^\\.[^.]\\|\\.pdf$\\|\\.tex$")
正则表达式 ^ \\。[^。]
将匹配任何长度为2+的字符串,起始于点,其中第二个字符是除了本身之外的任何字符。这不是完美的(不会匹配文件名,如.. foo),但大部分时间都应该可以。
The regexp ^\\.[^.]
will match any string of length 2+ starting with a dot where second character is any character except the dot itself. It's not perfect (will not match filenames like "..foo"), but should be ok most of the time.
这篇关于如何让Dired忽略具有特定扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!