Mercurial > emacs
annotate lisp/cedet/semantic/symref/grep.el @ 109447:f0c7ada3b642
lisp/mail/rmail.el: Update autoload checksum.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Sat, 17 Jul 2010 01:42:11 +0200 |
parents | 1d1d5d9bd884 |
children | a5ad4f188e19 |
rev | line source |
---|---|
104482
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1 ;;; semantic/symref/grep.el --- Symref implementation using find/grep |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2 |
106815 | 3 ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
104482
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
4 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com> |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
6 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
7 ;; This file is part of GNU Emacs. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
8 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
9 ;; GNU Emacs is free software: you can redistribute it and/or modify |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
10 ;; it under the terms of the GNU General Public License as published by |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
11 ;; the Free Software Foundation, either version 3 of the License, or |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
12 ;; (at your option) any later version. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
13 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
14 ;; GNU Emacs is distributed in the hope that it will be useful, |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
17 ;; GNU General Public License for more details. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
18 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
19 ;; You should have received a copy of the GNU General Public License |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
21 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
22 ;;; Commentary: |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
23 ;; |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
24 ;; Implement the symref tool API using the external tools find/grep. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
25 ;; |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
26 ;; The symref GREP tool uses grep in a project to find symbol references. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
27 ;; This is a lowest-common-denominator tool with sucky performance that |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
28 ;; can be used in small projects to find symbol references. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
29 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
30 (require 'semantic/symref) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
31 (require 'grep) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
32 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
33 (defvar ede-minor-mode) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
34 (declare-function ede-toplevel "ede/files") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
35 (declare-function ede-project-root-directory "ede/files") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
36 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
37 ;;; Code: |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
38 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
39 ;;; GREP |
104486
1ca7a97e0322
lisp/cedet/semantic/symref.el: Revert last change.
Chong Yidong <cyd@stupidchicken.com>
parents:
104482
diff
changeset
|
40 ;;;###autoload |
104482
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
41 (defclass semantic-symref-tool-grep (semantic-symref-tool-baseclass) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
42 ( |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
43 ) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
44 "A symref tool implementation using grep. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
45 This tool uses EDE to find he root of the project, then executes |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
46 find-grep in the project. The output is parsed for hits |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
47 and those hits returned.") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
48 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 (defvar semantic-symref-filepattern-alist |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
50 '((c-mode "*.[ch]") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
51 (c++-mode "*.[chCH]" "*.[ch]pp" "*.cc" "*.hh") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
52 (html-mode "*.s?html" "*.php") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
53 ) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
54 "List of major modes and file extension pattern regexp. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
55 See find -regex man page for format.") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 (defun semantic-symref-derive-find-filepatterns (&optional mode) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
58 "Derive a list of file patterns for the current buffer. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 Looks first in `semantic-symref-filepattern-alist'. If it is not |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 there, it then looks in `auto-mode-alist', and attempts to derive something |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 from that. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 Optional argument MODE specifies the `major-mode' to test." |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
63 ;; First, try the filepattern alist. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 (let* ((mode (or mode major-mode)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 (pat (cdr (assoc mode semantic-symref-filepattern-alist)))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
66 (when (not pat) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
67 ;; No hit, try auto-mode-alist. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 (dolist (X auto-mode-alist) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 (when (eq (cdr X) mode) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
70 ;; Only take in simple patterns, so try to convert this one. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
71 (let ((Xp |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
72 (cond ((string-match "\\\\\\.\\([^\\'>]+\\)\\\\'" (car X)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
73 (concat "*." (match-string 1 (car X)))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
74 (t nil)))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
75 (when Xp |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 (setq pat (cons Xp pat)))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 ))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 ;; Convert the list into some find-flags. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 (cond ((= (length pat) 1) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
80 (concat "-name \"" (car pat) "\"")) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
81 ((consp pat) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 (concat "\\( " |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 (mapconcat (lambda (s) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 (concat "-name \"" s "\"")) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
85 pat |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
86 " -o ") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 " \\)")) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 (t |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
89 (error "Configuration for `semantic-symref-tool-grep' needed for %s" major-mode)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 ))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
92 (defvar semantic-symref-grep-expand-keywords |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
93 (condition-case nil |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
94 (let* ((kw (copy-alist grep-expand-keywords)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
95 (C (assoc "<C>" kw)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 (R (assoc "<R>" kw))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 (setcdr C 'grepflags) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
98 (setcdr R 'greppattern) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
99 kw) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 (error nil)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 "Grep expand keywords used when expanding templates for symref.") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
103 (defun semantic-symref-grep-use-template (rootdir filepattern grepflags greppattern) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 "Use the grep template expand feature to create a grep command. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 ROOTDIR is the root location to run the `find' from. |
105340 | 106 FILEPATTERN is a string representing find flags for searching file patterns. |
104482
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 GREPFLAGS are flags passed to grep, such as -n or -l. |
105340 | 108 GREPPATTERN is the pattern used by grep." |
104482
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 ;; We have grep-compute-defaults. Lets use it. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 (grep-compute-defaults) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 (let* ((grep-expand-keywords semantic-symref-grep-expand-keywords) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 (cmd (grep-expand-template grep-find-template |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 greppattern |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 filepattern |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 rootdir))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 ;; For some reason, my default has no <D> in it. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 (when (string-match "find \\(\\.\\)" cmd) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 (setq cmd (replace-match rootdir t t cmd 1))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 ;;(message "New command: %s" cmd) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 cmd)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
121 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 (defmethod semantic-symref-perform-search ((tool semantic-symref-tool-grep)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 "Perform a search with Grep." |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 ;; Grep doesn't support some types of searches. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 (let ((st (oref tool :searchtype))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 (when (not (eq st 'symbol)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 (error "Symref impl GREP does not support searchtype of %s" st)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 ) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 ;; Find the root of the project, and do a find-grep... |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 (let* (;; Find the file patterns to use. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 (pat (cdr (assoc major-mode semantic-symref-filepattern-alist))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 (rootdir (cond |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 ;; Project root via EDE. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 ((eq (oref tool :searchscope) 'project) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 (let ((rootproj (when (and (featurep 'ede) ede-minor-mode) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 (ede-toplevel)))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 (if rootproj |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
138 (ede-project-root-directory rootproj) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 default-directory))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 ;; Calculate the target files as just in |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 ;; this directory... cause I'm lazy. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 ((eq (oref tool :searchscope) 'target) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 default-directory) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 )) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 (filepattern (semantic-symref-derive-find-filepatterns)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 ;; Grep based flags. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 (grepflags (cond ((eq (oref tool :resulttype) 'file) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
148 "-l ") |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
149 (t "-n "))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
150 (greppat (cond ((eq (oref tool :searchtype) 'regexp) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 (oref tool searchfor)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 (t |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 (concat "'\\<" (oref tool searchfor) "\\>'")))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 ;; Misc |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 (b (get-buffer-create "*Semantic SymRef*")) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 (ans nil) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 ) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 |
105799
3fe6da4a95a9
* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105377
diff
changeset
|
159 (with-current-buffer b |
104482
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 (erase-buffer) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 (setq default-directory rootdir) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 (if (not (fboundp 'grep-compute-defaults)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 ;; find . -type f -print0 | xargs -0 -e grep -nH -e |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 ;; Note : I removed -e as it is not posix, nor necessary it seems. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 (let ((cmd (concat "find " default-directory " -type f " filepattern " -print0 " |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 "| xargs -0 grep -H " grepflags "-e " greppat))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 ;;(message "Old command: %s" cmd) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 (call-process "sh" nil b nil "-c" cmd) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 ) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 (let ((cmd (semantic-symref-grep-use-template rootdir filepattern grepflags greppat))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 (call-process "sh" nil b nil "-c" cmd)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 )) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 (setq ans (semantic-symref-parse-tool-output tool b)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 ;; Return the answer |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 ans)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 (defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-grep)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 "Parse one line of grep output, and return it as a match list. |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
182 Moves cursor to end of the match." |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 (cond ((eq (oref tool :resulttype) 'file) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 ;; Search for files |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 (when (re-search-forward "^\\([^\n]+\\)$" nil t) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 (match-string 1))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 (t |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 (when (re-search-forward "^\\(\\(?:[a-zA-Z]:\\)?[^:\n]+\\):\\([0-9]+\\):" nil t) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 (cons (string-to-number (match-string 2)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 (match-string 1)) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 )))) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 (provide 'semantic/symref/grep) |
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 |
104486
1ca7a97e0322
lisp/cedet/semantic/symref.el: Revert last change.
Chong Yidong <cyd@stupidchicken.com>
parents:
104482
diff
changeset
|
195 ;; Local variables: |
1ca7a97e0322
lisp/cedet/semantic/symref.el: Revert last change.
Chong Yidong <cyd@stupidchicken.com>
parents:
104482
diff
changeset
|
196 ;; generated-autoload-file: "../loaddefs.el" |
1ca7a97e0322
lisp/cedet/semantic/symref.el: Revert last change.
Chong Yidong <cyd@stupidchicken.com>
parents:
104482
diff
changeset
|
197 ;; generated-autoload-load-name: "semantic/symref/grep" |
1ca7a97e0322
lisp/cedet/semantic/symref.el: Revert last change.
Chong Yidong <cyd@stupidchicken.com>
parents:
104482
diff
changeset
|
198 ;; End: |
1ca7a97e0322
lisp/cedet/semantic/symref.el: Revert last change.
Chong Yidong <cyd@stupidchicken.com>
parents:
104482
diff
changeset
|
199 |
105377 | 200 ;; arch-tag: 43d4469d-963c-4094-ac6f-99f7490973ce |
104482
5b954f6cdc15
lisp/cedet/semantic/symref/grep.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 ;;; semantic/symref/grep.el ends here |