aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2015-07-12 17:18:09 +0300
committerDmitry Gutov2015-07-12 17:19:08 +0300
commit62d5d46551c2adca780d5da1e58ea7f37d6fb933 (patch)
tree156727f3c45ff8c7e3fd7ec3d5a1a80b35ab39b2
parent714f7313f7e2043cd128bf6730c5bb2e5263b3ec (diff)
downloademacs-62d5d46551c2adca780d5da1e58ea7f37d6fb933.tar.gz
emacs-62d5d46551c2adca780d5da1e58ea7f37d6fb933.zip
Add `project-ignores'
* lisp/progmodes/project.el (project-ignores): New generic function, and an implementation for the VC project type. * lisp/progmodes/xref.el (xref--rgrep-command): Split, as a variant of rgrep-default-command that handles a generic list of ignores. (xref-collect-matches): Use it, and pass through to it the value of the newly added argument. (xref-find-regexp): Handle ignored paths within the project. Remove outdated comment. * lisp/vc/vc.el (vc-default-ignore-completion-table): Skip the comments and the empty lines.
-rw-r--r--lisp/progmodes/elisp-mode.el1
-rw-r--r--lisp/progmodes/project.el25
-rw-r--r--lisp/progmodes/xref.el55
-rw-r--r--lisp/vc/vc.el8
4 files changed, 75 insertions, 14 deletions
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index aa02b040083..a7e0bb47a1f 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -584,7 +584,6 @@ It can be quoted, or be inside a quoted form."
584 584
585(declare-function xref-make-bogus-location "xref" (message)) 585(declare-function xref-make-bogus-location "xref" (message))
586(declare-function xref-make "xref" (description location)) 586(declare-function xref-make "xref" (description location))
587(declare-function xref-collect-matches "xref" (symbol dir))
588(declare-function xref-collect-references "xref" (symbol dir)) 587(declare-function xref-collect-references "xref" (symbol dir))
589 588
590(defun elisp-xref-find (action id) 589(defun elisp-xref-find (action id)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 26b32b4b750..437c865dc08 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -84,6 +84,19 @@ of any currently open related projects, if they're meant to be
84edited together. The directory names should be absolute." 84edited together. The directory names should be absolute."
85 (list (project-root project))) 85 (list (project-root project)))
86 86
87(cl-defgeneric project-ignores (_project)
88 "Return the list of glob patterns that match ignored files.
89To root an entry, start it with `./'. To match directories only,
90end it with `/'."
91 (require 'grep)
92 (defvar grep-find-ignored-files)
93 (nconc
94 (mapcar
95 (lambda (dir)
96 (concat dir "/"))
97 vc-directory-exclusion-list)
98 grep-find-ignored-files))
99
87(defun project-try-vc (dir) 100(defun project-try-vc (dir)
88 (let* ((backend (ignore-errors (vc-responsible-backend dir))) 101 (let* ((backend (ignore-errors (vc-responsible-backend dir)))
89 (root (and backend (ignore-errors 102 (root (and backend (ignore-errors
@@ -93,6 +106,18 @@ edited together. The directory names should be absolute."
93(cl-defmethod project-root ((project (head vc))) 106(cl-defmethod project-root ((project (head vc)))
94 (cdr project)) 107 (cdr project))
95 108
109(cl-defmethod project-ignores ((project (head vc)))
110 (nconc
111 (cl-call-next-method)
112 (let* ((dir (cdr project))
113 (backend (vc-responsible-backend dir)))
114 (mapcar
115 (lambda (entry)
116 (if (string-match "\\`/" entry)
117 (replace-match "./" t t entry)
118 entry))
119 (vc-call-backend backend 'ignore-completion-table dir)))))
120
96(defun project-ask-user (dir) 121(defun project-ask-user (dir)
97 (cons 'user (read-directory-name "Project root: " dir nil t))) 122 (cons 'user (read-directory-name "Project root: " dir nil t)))
98 123
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 32d1215f157..cc475e6e7e4 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -662,20 +662,19 @@ With prefix argument, prompt for the identifier."
662 "Find all matches for REGEXP. 662 "Find all matches for REGEXP.
663With \\[universal-argument] prefix, you can specify the directory 663With \\[universal-argument] prefix, you can specify the directory
664to search in." 664to search in."
665 ;; FIXME: Prompt for directory.
666 (interactive (list (xref--read-identifier "Find regexp: "))) 665 (interactive (list (xref--read-identifier "Find regexp: ")))
667 (let* ((dirs (if current-prefix-arg 666 (let* ((proj (project-current))
667 (dirs (if current-prefix-arg
668 (list (read-directory-name "In directory: ")) 668 (list (read-directory-name "In directory: "))
669 (let ((proj (project-current))) 669 (project--prune-directories
670 (project--prune-directories 670 (nconc
671 (nconc 671 (project-directories proj)
672 (project-directories proj) 672 (project-search-path proj)))))
673 (project-search-path proj))))))
674 (xref-find-function 673 (xref-find-function
675 (lambda (_kind regexp) 674 (lambda (_kind regexp)
676 (cl-mapcan 675 (cl-mapcan
677 (lambda (dir) 676 (lambda (dir)
678 (xref-collect-matches regexp dir)) 677 (xref-collect-matches regexp dir (project-ignores proj)))
679 dirs)))) 678 dirs))))
680 (xref--show-xrefs regexp 'matches regexp nil))) 679 (xref--show-xrefs regexp 'matches regexp nil)))
681 680
@@ -756,7 +755,7 @@ tools are used, and when."
756 (mapc #'kill-buffer 755 (mapc #'kill-buffer
757 (cl-set-difference (buffer-list) orig-buffers))))) 756 (cl-set-difference (buffer-list) orig-buffers)))))
758 757
759(defun xref-collect-matches (regexp dir) 758(defun xref-collect-matches (regexp dir ignores)
760 "Collect matches for REGEXP inside DIR using rgrep." 759 "Collect matches for REGEXP inside DIR using rgrep."
761 (cl-assert (directory-name-p dir)) 760 (cl-assert (directory-name-p dir))
762 (require 'semantic/fw) 761 (require 'semantic/fw)
@@ -766,8 +765,8 @@ tools are used, and when."
766 (let* ((grep-find-template (replace-regexp-in-string "-e " "-E " 765 (let* ((grep-find-template (replace-regexp-in-string "-e " "-E "
767 grep-find-template t t)) 766 grep-find-template t t))
768 (grep-highlight-matches nil) 767 (grep-highlight-matches nil)
769 (command (rgrep-default-command (xref--regexp-to-extended regexp) 768 (command (xref--rgrep-command (xref--regexp-to-extended regexp)
770 "*.*" dir)) 769 "*.*" dir ignores))
771 (orig-buffers (buffer-list)) 770 (orig-buffers (buffer-list))
772 (buf (get-buffer-create " *xref-grep*")) 771 (buf (get-buffer-create " *xref-grep*"))
773 (grep-re (caar grep-regexp-alist)) 772 (grep-re (caar grep-regexp-alist))
@@ -787,6 +786,40 @@ tools are used, and when."
787 (mapc #'kill-buffer 786 (mapc #'kill-buffer
788 (cl-set-difference (buffer-list) orig-buffers))))) 787 (cl-set-difference (buffer-list) orig-buffers)))))
789 788
789(defun xref--rgrep-command (regexp files dir ignores)
790 (require 'find-dired) ; for `find-name-arg'
791 (defvar grep-find-template)
792 (defvar find-name-arg)
793 (grep-expand-template
794 grep-find-template
795 regexp
796 (concat (shell-quote-argument "(")
797 " " find-name-arg " "
798 (mapconcat
799 #'shell-quote-argument
800 (split-string files)
801 (concat " -o " find-name-arg " "))
802 " "
803 (shell-quote-argument ")"))
804 dir
805 (concat
806 (shell-quote-argument "(")
807 " -path "
808 (mapconcat
809 (lambda (ignore)
810 (when (string-match "\\(\\.\\)/" ignore)
811 (setq ignore (replace-match dir t t ignore 1)))
812 (when (string-match-p "/\\'" ignore)
813 (setq ignore (concat ignore "*")))
814 (unless (string-prefix-p "*" ignore)
815 (setq ignore (concat "*/" ignore)))
816 (shell-quote-argument ignore))
817 ignores
818 " -o -path ")
819 " "
820 (shell-quote-argument ")")
821 " -prune -o ")))
822
790(defun xref--regexp-to-extended (str) 823(defun xref--regexp-to-extended (str)
791 (replace-regexp-in-string 824 (replace-regexp-in-string
792 ;; FIXME: Add tests. Move to subr.el, make a public function. 825 ;; FIXME: Add tests. Move to subr.el, make a public function.
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 1bd04e13430..3b9e788b7ab 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1423,8 +1423,12 @@ Argument BACKEND is the backend you are using."
1423 1423
1424(defun vc-default-ignore-completion-table (backend file) 1424(defun vc-default-ignore-completion-table (backend file)
1425 "Return the list of ignored files under BACKEND." 1425 "Return the list of ignored files under BACKEND."
1426 (vc--read-lines 1426 (cl-delete-if
1427 (vc-call-backend backend 'find-ignore-file file))) 1427 (lambda (str)
1428 ;; Commented or empty lines.
1429 (string-match-p "\\`\\(?:#\\|[ \t\r\n]*\\'\\)" str))
1430 (vc--read-lines
1431 (vc-call-backend backend 'find-ignore-file file))))
1428 1432
1429(defun vc--read-lines (file) 1433(defun vc--read-lines (file)
1430 "Return a list of lines of FILE." 1434 "Return a list of lines of FILE."