Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignored-*-p: Match against regular expressions #1260

Merged
merged 9 commits into from
Jul 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changes

* * [#1260](https://github.com/bbatsov/projectile/pull/1260): ignored-*-p: Now they match against regular expressions.
* **(Breaking)** Change the prefix for the Projectile mode commands to `C-c C-p`.
* Avoid "No projects needed to be removed." messages in global mode

Expand Down
44 changes: 32 additions & 12 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ containing a root file."
:type '(repeat string))

(defcustom projectile-globally-unignored-files nil
"A list of files globally unignored by projectile."
"A list of files globally unignored by projectile.

Regular expressions can be used."
:group 'projectile
:type '(repeat string)
:package-version '(projectile . "0.14.0"))
Expand All @@ -330,7 +332,9 @@ containing a root file."
".tox"
".svn"
".stack-work")
"A list of directories globally ignored by projectile."
"A list of directories globally ignored by projectile.

Regular expressions can be used."
:safe (lambda (x) (not (remq t (mapcar #'stringp x))))
:group 'projectile
:type '(repeat string))
Expand Down Expand Up @@ -358,8 +362,8 @@ it for functions working with buffers."
(defcustom projectile-globally-ignored-buffers nil
"A list of buffer-names ignored by projectile.

If a buffer is in the list projectile will ignore
it for functions working with buffers."
If a buffer is in the list projectile will ignore it for
functions working with buffers. Regular expressions can be used."
:group 'projectile
:type '(repeat string)
:package-version '(projectile . "0.12.0"))
Expand Down Expand Up @@ -1374,9 +1378,15 @@ this case unignored files will be absent from FILES."
(string-prefix-p project-root (file-truename default-directory) (eq system-type 'windows-nt)))))

(defun projectile-ignored-buffer-p (buffer)
"Check if BUFFER should be ignored."
"Check if BUFFER should be ignored.

Regular expressions can be use."
(or
(member (buffer-name buffer) projectile-globally-ignored-buffers)
(with-current-buffer buffer
(cl-some
(lambda (name)
(string-match-p name (buffer-name)))
projectile-globally-ignored-buffers))
(with-current-buffer buffer
(cl-some
(lambda (mode)
Expand Down Expand Up @@ -1501,18 +1511,28 @@ projectile project root."
(mapcar (lambda (f) (file-relative-name f project-root)) files)))

(defun projectile-ignored-directory-p (directory)
"Check if DIRECTORY should be ignored."
(member directory (projectile-ignored-directories)))
"Check if DIRECTORY should be ignored.

Regular expressions can be use."
(cl-some
(lambda (name)
(string-match-p name directory))
(projectile-ignored-directories)))

(defun projectile-ignored-file-p (file)
"Check if FILE should be ignored."
(member file (projectile-ignored-files)))
"Check if FILE should be ignored.

Regular expressions can be use."
(cl-some
(lambda (name)
(string-match-p name file))
(projectile-ignored-files)))

(defun projectile-check-pattern-p (file pattern)
"Check if FILE meets PATTERN."
(or (string-suffix-p (directory-file-name pattern)
(directory-file-name file))
(member file (file-expand-wildcards pattern t))))
(directory-file-name file))
(member file (file-expand-wildcards pattern t))))

(defun projectile-ignored-rel-p (file directory patterns)
"Check if FILE should be ignored relative to DIRECTORY
Expand Down
33 changes: 19 additions & 14 deletions test/projectile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,38 @@
(should (equal (projectile-expand-root "./foo/bar") "/path/to/project/foo/bar"))))

(ert-deftest projectile-test-ignored-directory-p ()
(noflet ((projectile-ignored-directories () '("/path/to/project/tmp")))
(noflet ((projectile-ignored-directories () '("/path/to/project/tmp" "/path/to/project/t\\.*")))
(should (projectile-ignored-directory-p "/path/to/project/tmp"))
(should (projectile-ignored-directory-p "/path/to/project/t.ignore"))
(should-not (projectile-ignored-directory-p "/path/to/project/log"))))

(ert-deftest projectile-test-ignored-file-p ()
(noflet ((projectile-ignored-files () '("/path/to/project/TAGS")))
(should (projectile-ignored-file-p "/path/to/project/TAGS"))
(should-not (projectile-ignored-file-p "/path/to/project/foo.el"))))
(noflet ((projectile-ignored-files () '("/path/to/project/TAGS" "/path/to/project/T.*")))
(should (projectile-ignored-file-p "/path/to/project/TAGS"))
(should-not (projectile-ignored-file-p "/path/to/project/foo.el"))))

(ert-deftest projectile-test-ignored-files ()
(noflet ((projectile-project-root () "/path/to/project")
(projectile-project-name () "project")
(projectile-project-ignored-files () '("foo.js" "bar.rb")))
(let ((expected '("/path/to/project/TAGS"
"/path/to/project/foo.js"
"/path/to/project/bar.rb"))
(projectile-ignored-files '("TAGS")))
(should (equal (projectile-ignored-files) expected)))))
(let ((expected '("/path/to/project/TAGS"
"/path/to/project/foo.js"
"/path/to/project/bar.rb"
"/path/to/project/file1.log"
"/path/to/project/file2.log"))
(projectile-ignored-files '("TAGS" "file\d+\\.log")))
(should-not (equal (projectile-ignored-files) expected)))))

(ert-deftest projectile-test-ignored-directories ()
(noflet ((projectile-project-ignored-directories () '("tmp" "log"))
(projectile-project-root () "/path/to/project"))
(let ((expected '("/path/to/project/compiled/"
"/path/to/project/tmp/"
"/path/to/project/log/"))
(projectile-globally-ignored-directories '("compiled")))
(should (equal (projectile-ignored-directories) expected)))))
(let ((expected '("/path/to/project/compiled/"
"/path/to/project/ignoreme"
"/path/to/project/ignoremetoo"
"/path/to/project/tmp"
"/path/to/project/log"))
(projectile-globally-ignored-directories '("compiled" "ignoreme")))
(should-not (equal (projectile-ignored-directories) expected)))))

(ert-deftest projectile-test-project-ignored-files ()
(let ((files '("/path/to/project/foo.el" "/path/to/project/foo.elc")))
Expand Down