-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblg-cc.el
130 lines (105 loc) · 3.46 KB
/
blg-cc.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;;; blg-cc.el --- cc grep -*-emacs-lisp-*-
;; Copyright (C) 2005 Masayuki Ataka <[email protected]>
;; Author: Masayuki Ataka <[email protected]>
;; Keywords: tools, convenience
;; This file is a part of blgrep.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
;;; Commentary:
;; [Overview]
;;
;; blg-cc.el is a part of blgrep package.
;;
;; blg-cc collects all functions, variables, macros, etc... which contains a
;; match for REGEXP from source file of C, C++, and Java.
;;
;; * Frontends of blg-cc
;;
;; - blg-cc
;; List defun matching regexp.
;;
;; [.emacs]
;;
;; Put this in your .emacs
;;
;; (autoload 'blg-cc "blg-cc" "C/C++/Java grep." t)
;;
;;; Code:
(require 'blgrep)
;;
;; System Variables
;;
;;
;; Blg-cc
;;
;;;###autoload
(defun blg-cc (query rev)
"C/C++/Java grep."
(interactive (list (read-string (format "%s grep: " mode-name))
prefix-arg))
(let ((blgrep-beg-of-block #'blg-cc-beginning-of-block)
(blgrep-end-of-block #'blg-cc-end-of-block))
(blgrep query rev #'blg-cc-mode "blg-cc" 'block 1)))
(defvar blg-cc-type nil)
(defun blg-cc-beginning-of-block ()
(re-search-backward "^\\(\\s(\\|[a-zA-Z#]\\)" nil 'move)
(cond
((bobp) (setq blg-cc-type nil))
((looking-at "^#\\c *define") (setq blg-cc-type 'macro))
((looking-at "^[a-zA-Z]") (setq blg-cc-type 'function))
((looking-at "^{") (setq blg-cc-type 'function)
(re-search-backward "^[a-zA-Z]"))
(t (error "No type specified"))))
(defun blg-cc-end-of-block ()
(cond
((eq blg-cc-type 'function)
(end-of-line)
(skip-chars-backward " \t")
(if (eq (char-before) ?\;)
(forward-line)
(end-of-defun)))
((eq blg-cc-type 'macro)
(end-of-line)
(while (eq (char-before) ?\\)
(end-of-line 2))
(forward-line))
(t (forward-line 1))))
;;
;; blg-cc mode
;;
(defvar blg-cc-mode-map (copy-keymap blgrep-mode-map))
(let ((old-map blgrep-mode-map)
(new-map blg-cc-mode-map))
(substitute-key-definition 'blgrep-dummy 'blg-cc new-map old-map)
(substitute-key-definition 'blgrep-next 'forward-sexp new-map old-map)
(substitute-key-definition 'blgrep-previous 'backward-sexp new-map old-map)
(substitute-key-definition 'blgrep-forward 'blg-cc-forward-defun new-map old-map)
(substitute-key-definition 'blgrep-backward 'blg-cc-backward-defun new-map old-map))
(define-derived-mode blg-cc-mode c-mode "blg-cc"
"Major mode for blg-cc."
(run-hooks 'blgrep-mode-hook))
(defun blg-cc-forward-defun (&optional arg)
(interactive "p")
(end-of-defun (1+ arg))
(beginning-of-defun)
(forward-line -1))
(defun blg-cc-backward-defun (&optional arg)
(interactive "p")
(beginning-of-defun arg)
(forward-line -1))
;;;
(provide 'blg-cc)
;; blg-cc.el ends here
;; Local Variables:
;; fill-column: 72
;; End: