Download
(require 'cl)
(autoload 'dired-omit-mode "dired-x" "Toggle omission of uninteresting files in Dired (Dired-Omit mode)." t)
(eval-when-compile
(defvar dired-garbage-files-regexp)
(defvar dired-omit-extensions)
(defvar dired-omit-files)
(defvar dired-omit-mode)
(defvar eshell-cmpl-dir-ignore)
(defvar eshell-cmpl-file-ignore)
(defvar grep-find-ignored-directories)
(defvar grep-find-ignored-files)
(defvar ido-ignore-directories)
(defvar ido-ignore-files)
(defvar nav-boring-file-regexps)
(defvar pcomplete-dir-ignore)
(defvar pcomplete-file-ignore)
(defvar shell-completion-fignore)
(defvar speedbar-directory-unshown-regexp)
(defvar speedbar-file-unshown-regexp)
(defvar comint-completion-fignore))
(defvar ignoramus-known-actions '(
all
comint
completions
dired
eshell
grep
ido
nav
pcomplete
projectile
shell
speedbar
vc
)
"All known actions for ignoring unwanted files.")
(defvar ignoramus-boring-file-regexp nil "A computed regexp matching uninteresting files.")
(defvar ignoramus-boring-dir-regexp nil "A computed regexp matching uninteresting directories.")
(defvar ignoramus-datafile-basename '(
desktop-base-file-name
".emacs.desktop.lock"
)
"List of symbols or strings holding file basenames used for persistence by Emacs packages.")
(defvar ignoramus-datafile-completepath '(
abbrev-file-name
ac-comphist-file
bm-repository-file
bmkp-bmenu-commands-file
bmkp-bmenu-state-file
bookmark-default-file
flymake-log-file-name
guess-style-override-file
ido-save-directory-list-file
minimal-session-saver-data-file
recentf-save-file
save-place-file
savehist-file
smex-save-file
tramp-persistency-file-name
woman-cache-filename
)
"List of symbols or strings holding complete paths used for persistence by Emacs packages.")
(defvar ignoramus-datafile-prefix '(
auto-save-list-file-prefix
)
"List of symbols or strings holding file prefixes used for persistence by Emacs packages.
A prefix is a leading absolute path component plus leading fragment of basename.")
(defvar ignoramus-datafile-dirprefix '(
ac-dictionary-directories
ede-simple-save-directory
eshell-directory-name
pcache-directory
semanticdb-default-save-directory
tramp-auto-save-directory
url-configuration-directory
)
"List of symbols or strings holding directory prefixes used for persistence by Emacs packages.
A directory prefix is a leading absolute path component.")
(defvar ignoramus-datafile-computed-basenames nil
"A computed value based on `ignoramus-datafile-basename'.")
(defvar ignoramus-datafile-computed-completepaths nil
"A computed value based on `ignoramus-datafile-completepath'.")
(defvar ignoramus-datafile-computed-prefixes nil
"A computed value based on `ignoramus-datafile-prefix'.")
(defvar ignoramus-datafile-computed-dirprefixes nil
"A computed value based on `ignoramus-datafile-dirprefix'.")
(progn
(define-obsolete-variable-alias 'ignoramus-file-endings 'ignoramus-file-basename-endings)
(define-obsolete-variable-alias 'ignoramus-file-beginnings 'ignoramus-file-basename-beginnings)
(define-obsolete-variable-alias 'ignoramus-file-exact-names 'ignoramus-file-basename-exact-names)
(define-obsolete-variable-alias 'ignoramus-file-regexps 'ignoramus-file-basename-regexps))
(defgroup ignoramus nil
"Ignore backups, build files, et al."
:version "0.6.8"
:link '(emacs-commentary-link :tag "Commentary" "ignoramus")
:link '(url-link :tag "Github" "http://github.com/rolandwalker/ignoramus")
:link '(url-link :tag "EmacsWiki" "http://emacswiki.org/emacs/Ignoramus")
:prefix "ignoramus-"
:group 'tools
:group 'convenience)
(defcustom ignoramus-default-actions (remq 'all ignoramus-known-actions)
"Which actions to use by default when ignoring unwanted files."
:type `(repeat ,(append '(choice)
(mapcar #'(lambda (x)
(list 'const x)) ignoramus-known-actions)))
:group 'ignoramus)
(defcustom ignoramus-use-known-datafiles t
"Whether to read variables from other packages to recognize datafiles.
When this option is set, ignoramus reads the current settings of
variables such as `tramp-auto-save-directory' or `woman-cache-filename'
to supplement its lists of regular expressions."
:type 'boolean
:group 'ignoramus)
(defcustom ignoramus-case-insensitive t
"Make string and regexp matches case-insensitive where possible.
This affects the results from `ignoramus-boring-p' and
`ignoramus-matches-datafile', but generally does not affect
the behavior of other libraries configured by ignoramus."
:type 'boolean
:group 'ignoramus)
(defgroup ignoramus-patterns nil
"File patterns to ignore."
:group 'ignoramus)
(defcustom ignoramus-file-basename-endings
'(
".386"
".a"
".acn"
".acr"
".alg"
".ap_"
".apk"
"_archive"
".asv"
"-autoloads.el"
".aux"
".bak"
".bbl"
".beam"
".bin"
".blg"
".cgo1.go"
".cgo2.c"
".chi"
".chi.h"
".class"
".com"
".cp"
".cps"
".d64fsl"
".dcu"
".dep"
".dex"
".dfsl"
".dll"
".drc"
".drv"
".dvi"
".dx32fsl"
".dx64fsl"
".dxl"
".dylib"
".ear"
".elc"
".esproj"
"-Ex.R"
".exe"
".fas"
".fasl"
".fdb_latexmk"
".fmx"
".fn"
".fns"
".fsl"
".fx32fsl"
".fx64fsl"
".gcda"
".gcno"
".gcov"
".glg"
".glo"
".gls"
".gmo"
".hi"
".identcache"
".ilg"
".ilk"
".iml"
".ind"
".ipr"
".ist"
".iws"
".jar"
".ky"
".kys"
".la"
".lai"
".launch"
".lbin"
".lib"
".lnk"
".lo"
".lock"
".lof"
".lot"
".lx32fsl"
".lx64fsl"
".maf"
".mem"
".min.js"
"-min.js"
".mmx"
".mo"
".moved-aside"
".mtc"
".mtc0"
".nav"
".nlo"
".o"
".obj"
".opensdf"
".orig"
".p64fsl"
".pdfsync"
".pfsl"
".pg"
".pgs"
".pid"
".pidb"
".plt"
".plx"
".pot"
".psess"
".Publish.xml"
".pyc"
".pyd"
".pydevproject"
".pyo"
".rbc"
".rej"
".sassc"
".scc"
".sdf"
".seed"
".sln.docstates"
".slo"
".snm"
".so"
".sparcf"
".sublime-project"
".sublime-workspace"
".suo"
".swo"
".swp"
".sx32fsl"
".sx64fsl"
".synctex.gz"
".ttc"
".tfm"
".tmproj"
".tmproject"
".toc"
".tp"
".tps"
".ufsl"
".un~"
".vr"
".vrb"
".vrs"
".vsp"
".vspscc"
".vssscc"
".vxd"
".war"
".wx32fsl"
".wx64fsl"
".x86f"
".xdy"
".zwc"
"~"
)
"List of file endings to ignore.
These are not regular expressions, but literal strings which
occur at the ends of file names to ignore."
:type '(repeat string)
:group 'ignoramus-patterns)
(defcustom ignoramus-file-basename-beginnings
'(
".#"
"core."
"._"
"_cgo_export."
)
"List of file beginnings to ignore.
These are not regular expressions, but literal strings which
occur at the beginnings of file or directory names to ignore.
The string to match comprises only the last element of a
fully-qualified pathname."
:type '(repeat string)
:group 'ignoramus-patterns)
(defcustom ignoramus-file-basename-exact-names
'(
"$RECYCLE.BIN"
".AppleDouble"
".DS_Store"
".DocumentRevisions-V100"
".LSOverride"
".Rhistory"
".Spotlight-V100"
".TemporaryItems"
".Trashes"
".actionScriptProperties"
".apt_generated"
".build"
".buildpath"
".builds"
".bzr"
".cdv"
".classpath"
".com.apple.timemachine.donotpresent"
".com.apple.timemachine.supported"
".coverage"
".cproject"
".directory"
".dropbox"
".dropbox.cache"
".emacs.desktop"
".emacs.desktop.lock"
".eunit"
".externalToolBuilders"
".flexProperties"
".fseventsd"
".git"
".hg"
".idea"
".ido.last"
".last_cover_stats"
".lein-deps-sum"
".loadpath"
".netrwhist"
".org-id-locations"
".pc"
".project"
".projectile"
".recentf"
".redcar"
".rspec"
".sass-cache"
".scala_dependencies"
".svn"
".tox"
".wmncach.el"
".yardoc"
"_MTN"
"__history"
"_build"
"_cgo_defun.c"
"_cgo_gotypes.go"
"_darcs"
"_obj"
"_sgbak"
"_site"
"_test"
"_testmain.go"
"_yardoc"
"aclocal.m4"
"auto-save-list"
"autom4te.cache"
"bin-debug"
"bin-release"
"blib"
"build"
"Build"
"Build.bat"
"COMMIT_EDITMSG"
"cmake_install.cmake"
"CMakeCache.txt"
"CMakeFiles"
"cover_db"
"cscope.csd"
"cscope.files"
"cscope.inc"
"cscope.lst"
"cscope.out"
"cscope.out.po"
"cscope.tmplist"
"CVS"
"Debug"
"debug"
"depcomp"
"DerivedData"
"Desktop.ini"
"ehthumbs.db"
"git-rebase-todo"
"gwt-unitCache"
"gwt_bree"
"install-sh"
"install_manifest.txt"
"InstalledFiles"
"Makefile.in"
"MCVS"
"META.yml"
"MERGE_MSG"
"minimal-session-saver-data.el"
"MYMETA.yml"
"nbbuild"
"nbdist"
"nosetests.xml"
"pm_to_blib"
"Profile"
"profile"
"RCS"
"Release"
"release"
"SCCS"
"Session.vim"
"slprj"
"SQUASH_MSG"
"TAGS"
"tags"
"TestResult"
"testresult"
"Thumbs.db"
"tmtags"
"xcuserdata"
"xhtml-loader.rnc"
"{arch}"
"~.dep"
"~.dot"
"~.nib"
"~.plst"
"test.out"
"test_out"
"test.output"
"test_output"
)
"List of exact filenames to ignore.
These are not regular expressions, but literal strings which
exactly match a file or directory name to ignore.
The string to match comprises only the last element of a
fully-qualified pathname."
:type '(repeat string)
:group 'ignoramus-patterns)
(defcustom ignoramus-file-basename-regexps
'(
"\\`#.*#\\'"
"\\`.*\\.mex[^.]*\\'"
"\\`Icon.?\\'"
"\\`\\..*\\.sw[a-z]\\'"
"\\`\\.yas.*\\.el\\'"
"\\`bzr_log\\.[[:alnum:]]+\\'"
"\\`hg-editor-[[:alnum:]]+\\.txt\\'"
"\\`svn-commit\\.tmp\\'"
"\\`zshecl[0-9]+\\'"
"\\`bash-fc-[0-9]+\\'"
)
"List of regexps matching filenames to ignore.
The string to match comprises only the last element of a
fully-qualified pathname."
:type '(repeat regexp)
:group 'ignoramus-patterns)
(defun ignoramus--overly-broad-path-p (str-val)
"Identify path elements which would match too broadly to be useful.
Also identify bogons."
(or (not (string-match-p "[^ ]" str-val))
(string-match-p "\\`/*\\'" str-val)
(string-match-p "\\`~/*\\'" str-val)
(string-match-p (downcase (concat "\\`" (expand-file-name "~") "/*\\'")) (downcase str-val))))
(defun ignoramus--string-or-symbol (str-or-sym)
"Return the string for STR-OR-SYM."
(cond
((null str-or-sym)
nil)
((and (symbolp str-or-sym)
(boundp str-or-sym))
(ignoramus--string-or-symbol (symbol-value str-or-sym)))
((and (stringp str-or-sym)
(ignoramus--overly-broad-path-p str-or-sym))
nil)
((stringp str-or-sym)
str-or-sym)
((consp str-or-sym)
(mapcar 'ignoramus--string-or-symbol str-or-sym))
(t
nil)))
(defun ignoramus-list-flatten (list)
"Flatten LIST which may contain other lists."
(cond
((null list)
nil)
((and (listp list)
(consp (car list)))
(append (ignoramus-list-flatten (car list)) (ignoramus-list-flatten (cdr list))))
((listp list)
(cons (car list) (ignoramus-list-flatten (cdr list))))
(t
(list list))))
(defun ignoramus--extract-strings (arg)
"Return a list of strings which may be contained in or referred to in ARG."
(remove-if-not 'stringp
(ignoramus-list-flatten
(ignoramus--string-or-symbol arg))))
(defun ignoramus--extract-pathstrings (arg)
"Return a list of path strings which may be contained in or referred to in ARG."
(mapcar 'expand-file-name
(ignoramus--extract-strings arg)))
(defun ignoramus-strip-trailing-slash (path)
"Remove any trailing slashes from directory string PATH.
On non-POSIX systems, remove the appropriate directory separator
character for that system."
(while (not (string-equal path (setq path (directory-file-name path)))) t)
path)
(defun ignoramus-ensure-trailing-slash (path)
"Ensure that directory string PATH has a trailing slash.
On non-POSIX systems, ensure the appropriate directory separator
character for that system."
(setq path (ignoramus-strip-trailing-slash path))
(file-name-as-directory path))
(defun ignoramus-compute-common-regexps ()
"Compute common regexps used by plugins."
(setq ignoramus-boring-dir-regexp ignoramus-file-basename-regexps)
(when ignoramus-file-basename-exact-names
(push (concat "\\`" (regexp-opt (append ignoramus-file-basename-exact-names
(if ignoramus-use-known-datafiles
(ignoramus--extract-strings ignoramus-datafile-basename)
nil))) "\\'")
ignoramus-boring-dir-regexp))
(when ignoramus-file-basename-beginnings
(push (concat "\\`" (regexp-opt ignoramus-file-basename-beginnings))
ignoramus-boring-dir-regexp))
(when ignoramus-boring-dir-regexp
(setq ignoramus-boring-dir-regexp (mapconcat 'identity ignoramus-boring-dir-regexp "\\|")))
(setq ignoramus-boring-file-regexp ignoramus-file-basename-regexps)
(when ignoramus-file-basename-exact-names
(push (concat "\\`" (regexp-opt (append ignoramus-file-basename-exact-names
(if ignoramus-use-known-datafiles
(ignoramus--extract-strings ignoramus-datafile-basename)
nil))) "\\'")
ignoramus-boring-file-regexp))
(when ignoramus-file-basename-endings
(push (concat (regexp-opt ignoramus-file-basename-endings) "\\'")
ignoramus-boring-file-regexp))
(when ignoramus-file-basename-beginnings
(push (concat "\\`" (regexp-opt ignoramus-file-basename-beginnings))
ignoramus-boring-file-regexp))
(when ignoramus-boring-file-regexp
(setq ignoramus-boring-file-regexp (mapconcat 'identity ignoramus-boring-file-regexp "\\|")))
(setq ignoramus-datafile-computed-basenames (ignoramus--extract-strings ignoramus-datafile-basename))
(setq ignoramus-datafile-computed-completepaths (ignoramus--extract-pathstrings ignoramus-datafile-completepath))
(setq ignoramus-datafile-computed-prefixes (ignoramus--extract-pathstrings ignoramus-datafile-prefix))
(setq ignoramus-datafile-computed-dirprefixes (mapcar 'ignoramus-ensure-trailing-slash
(ignoramus--extract-pathstrings ignoramus-datafile-dirprefix))))
(defun ignoramus-do-ignore-vc ()
"Tell `vc-mode' to ignore unwanted files."
(setq vc-directory-exclusion-list ignoramus-file-basename-exact-names))
(defun ignoramus-do-ignore-grep ()
"Tell `grep-mode' to ignore unwanted files."
(setq grep-find-ignored-files (cons ".#*" (delq nil (mapcar #'(lambda (pat)
(concat "*" pat)) ignoramus-file-basename-endings))))
(setq grep-find-ignored-directories ignoramus-file-basename-exact-names))
(defun ignoramus-do-ignore-shell ()
"Tell `shell-mode' to ignore unwanted files."
(setq shell-completion-fignore ignoramus-file-basename-endings))
(defun ignoramus-do-ignore-comint ()
"Tell `comint-mode' and derived modes to ignore unwanted files."
(setq comint-completion-fignore ignoramus-file-basename-endings))
(defun ignoramus-do-ignore-completions ()
"Tell built-in completions to ignore unwanted files."
(setq completion-ignored-extensions (append
ignoramus-file-basename-endings
(mapcar (lambda (pat)
(concat pat "/")) ignoramus-file-basename-exact-names))))
(defun ignoramus-do-ignore-nav ()
"Tell `nav-mode' to ignore unwanted files."
(setq nav-boring-file-regexps (list ignoramus-boring-file-regexp)))
(defun ignoramus-do-ignore-ido ()
"Tell `ido-mode' to ignore unwanted files."
(setq ido-ignore-directories (list "\\`\\.\\./" "\\`\\./" ignoramus-boring-dir-regexp))
(setq ido-ignore-files (list "\\`\\.\\./" "\\`\\./" ignoramus-boring-file-regexp)))
(defun ignoramus-do-ignore-eshell ()
"Tell `eshell' to ignore unwanted files."
(setq eshell-cmpl-file-ignore ignoramus-boring-file-regexp)
(setq eshell-cmpl-dir-ignore (concat "\\`"
(regexp-opt (append '("." "..") ignoramus-file-basename-exact-names))
"/\\'")))
(defun ignoramus-do-ignore-dired ()
"Tell `dired-mode' to ignore unwanted files."
(setq dired-omit-mode t)
(add-hook 'dired-mode-hook #'(lambda ()
(when (eq major-mode 'dired-mode)
(dired-omit-mode 1))))
(setq dired-garbage-files-regexp ignoramus-boring-file-regexp)
(setq dired-omit-extensions ignoramus-file-basename-endings)
(setq dired-omit-files ignoramus-boring-file-regexp))
(defun ignoramus-do-ignore-projectile ()
"Tell `projectile-mode' to ignore unwanted files."
(eval-after-load "projectile"
'(progn
(defun projectile-ignored-extension-p (file)
(let ((case-fold-search ignoramus-case-insensitive))
(string-match-p ignoramus-boring-file-regexp file))))))
(defun ignoramus-do-ignore-speedbar ()
"Tell `speedbar-mode' to ignore unwanted files."
(setq speedbar-directory-unshown-regexp ignoramus-boring-dir-regexp)
(setq speedbar-file-unshown-regexp ignoramus-boring-file-regexp))
(defun ignoramus-do-ignore-pcomplete ()
"Tell `pcomplete' to ignore unwanted files."
(setq pcomplete-dir-ignore ignoramus-boring-dir-regexp)
(setq pcomplete-file-ignore ignoramus-boring-file-regexp))
(defun ignoramus-matches-datafile (file)
"Return non-nil if FILE is used for data storage by a known Lisp library.
This function identifies specific files used for persistence by
tramp, semantic, woman, etc.
If a Lisp library is loaded after ignoramus, its files may not
be recognized, in which case `ignoramus-compute-common-regexps'
maybe called."
(when (stringp file)
(unless ignoramus-boring-file-regexp
(ignoramus-compute-common-regexps))
(setq file (expand-file-name file))
(let* ((file-basename (file-name-nondirectory file))
(case-convert (if ignoramus-case-insensitive 'downcase 'identity))
(converted-file (funcall case-convert file))
(converted-file-basename (funcall case-convert file-basename)))
(catch 'known
(dolist (basename ignoramus-datafile-computed-basenames)
(when (equal (funcall case-convert basename) converted-file-basename)
(throw 'known (list file 'basename basename file-basename))))
(dolist (completepath ignoramus-datafile-computed-completepaths)
(when (equal (funcall case-convert completepath) converted-file)
(throw 'known (list file 'completepath completepath file))))
(dolist (prefix ignoramus-datafile-computed-prefixes)
(when (string-prefix-p prefix file ignoramus-case-insensitive)
(throw 'known (list file 'prefix (expand-file-name prefix) file))))
(dolist (dirprefix ignoramus-datafile-computed-dirprefixes)
(when (string-prefix-p dirprefix file ignoramus-case-insensitive)
(throw 'known (list file 'dirprefix dirprefix file))))))))
(defun ignoramus-register-datafile (symbol-or-string type &optional unregister)
"Register a generated file used for data storage.
This generated file will be ignored by ignoramus.
SYMBOL-OR-STRING may be the name of a symbol to consult, or a
string. If a symbol, it should refer to a string or list of
strings.
TYPE may be one of 'basename, 'completepath, 'prefix, or
'dirprefix.
Optional UNREGISTER tells ignoramus to forget about
SYMBOL-OR-STRING."
(assert (memq type '(basename completepath prefix dirprefix)) nil "bad TYPE")
(let ((sym (intern (format "ignoramus-datafile-%s" type))))
(if unregister
(set sym (delete symbol-or-string (symbol-value sym)))
(push symbol-or-string (symbol-value sym))))
(ignoramus-compute-common-regexps))
(defun ignoramus-boring-p (file)
"Return non-nil if ignoramus thinks FILE is uninteresting."
(unless ignoramus-boring-file-regexp
(ignoramus-compute-common-regexps))
(let ((case-fold-search ignoramus-case-insensitive))
(or (string-match-p ignoramus-boring-file-regexp (file-name-nondirectory file))
(and ignoramus-use-known-datafiles
(ignoramus-matches-datafile file)))))
(defun ignoramus-setup (&optional actions)
"Turn on ignoring files for all members of sequence ACTIONS.
ACTIONS is optional, and defaults to the value of
`ignoramus-default-actions'.
If ACTIONS contains 'all, turn on ignoring files for all
actions in `ignoramus-known-actions'."
(callf or actions ignoramus-default-actions)
(when (symbolp actions)
(callf list actions))
(when (memq 'all actions)
(setq actions ignoramus-known-actions))
(setq actions (remq 'all actions))
(ignoramus-compute-common-regexps)
(dolist (action actions)
(let ((func (intern-soft (format "ignoramus-do-ignore-%s" action))))
(unless func
(error "No such action %s" action))
(funcall func))))
(provide 'ignoramus)