1 ;;; semantic/symref/list.el --- Symref Output List UI.
3 ;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; Provide a simple user facing API to finding symbol references.
26 ;; This UI is the base of some refactoring tools. For any refactor,
27 ;; the user will execture [FIXME what?] `semantic-symref' in a tag.
28 ;; Once that data is collected, the output will be listed in a buffer.
29 ;; In the output buffer, the user can then initiate different
30 ;; refactoring operations.
32 ;; NOTE: Need to add some refactoring tools.
34 (require 'semantic
/symref
)
35 (require 'semantic
/complete
)
41 (defun semantic-symref ()
42 "Find references to the current tag.
43 This command uses the currently configured references tool within the
44 current project to find references to the current tag. The
45 references are the organized by file and the name of the function
47 Display the references in`semantic-symref-results-mode'."
50 (let ((ct (semantic-current-tag))
54 (when (not ct
) (error "Place cursor inside tag to be searched for"))
56 (when (not (y-or-n-p (format "Find references for %s? " (semantic-tag-name ct
))))
58 ;; Gather results and tags
59 (message "Gathering References...")
60 (setq res
(semantic-symref-find-references-by-name (semantic-tag-name ct
)))
61 (semantic-symref-produce-list-on-results res
(semantic-tag-name ct
))))
64 (defun semantic-symref-symbol (sym)
65 "Find references to the symbol SYM.
66 This command uses the currently configured references tool within the
67 current project to find references to the input SYM. The
68 references are the organized by file and the name of the function
70 Display the references in`semantic-symref-results-mode'."
71 (interactive (list (semantic-tag-name (semantic-complete-read-tag-buffer-deep
76 ;; Gather results and tags
77 (message "Gathering References...")
78 (setq res
(semantic-symref-find-references-by-name sym
))
79 (semantic-symref-produce-list-on-results res sym
)))
82 (defun semantic-symref-produce-list-on-results (res str
)
83 "Produce a symref list mode buffer on the results RES."
84 (when (not res
) (error "No references found"))
85 (semantic-symref-result-get-tags res t
)
86 (message "Gathering References...done")
87 ;; Build a refrences buffer.
88 (let ((buff (get-buffer-create
89 (format "*Symref %s" str
)))
91 (switch-to-buffer-other-window buff
)
93 (semantic-symref-results-mode res
))
98 (defgroup semantic-symref-results-mode nil
99 "Symref Results group."
102 (defvar semantic-symref-results-mode-map
103 (let ((km (make-sparse-keymap)))
104 (define-key km
"\C-i" 'forward-button
)
105 (define-key km
"\M-C-i" 'backward-button
)
106 (define-key km
" " 'push-button
)
107 (define-key km
"-" 'semantic-symref-list-toggle-showing
)
108 (define-key km
"=" 'semantic-symref-list-toggle-showing
)
109 (define-key km
"+" 'semantic-symref-list-toggle-showing
)
110 (define-key km
"n" 'semantic-symref-list-next-line
)
111 (define-key km
"p" 'semantic-symref-list-prev-line
)
112 (define-key km
"q" 'semantic-symref-hide-buffer
)
114 "Keymap used in `semantic-symref-results-mode'.")
116 (defcustom semantic-symref-results-mode-hook nil
117 "*Hook run when `semantic-symref-results-mode' starts."
118 :group
'semantic-symref
121 (defvar semantic-symref-current-results nil
122 "The current results in a results mode buffer.")
124 (defun semantic-symref-results-mode (results)
125 "Major-mode for displaying Semantic Symbol Reference RESULTS.
126 RESULTS is an object of class `semantic-symref-results'."
128 (kill-all-local-variables)
129 (setq major-mode
'semantic-symref-results-mode
132 (use-local-map semantic-symref-results-mode-map
)
133 (set (make-local-variable 'semantic-symref-current-results
)
135 (semantic-symref-results-dump results
)
136 (goto-char (point-min))
137 (buffer-disable-undo)
138 (set (make-local-variable 'font-lock-global-modes
) nil
)
140 (run-hooks 'semantic-symref-results-mode-hook
)
143 (defun semantic-symref-hide-buffer ()
144 "Hide buffer with semantic-symref results."
148 (defcustom semantic-symref-results-summary-function
'semantic-format-tag-prototype
149 "*Function to use when creating items in Imenu.
150 Some useful functions are found in `semantic-format-tag-functions'."
151 :group
'semantic-symref
152 :type semantic-format-tag-custom-list
)
154 (defun semantic-symref-results-dump (results)
155 "Dump the RESULTS into the current buffer."
156 ;; Get ready for the insert.
157 (toggle-read-only -
1)
160 ;; Insert the contents.
163 (dolist (T (oref results
:hit-tags
))
165 (when (not (equal lastfile
(semantic-tag-file-name T
)))
166 (setq lastfile
(semantic-tag-file-name T
))
167 (insert-button lastfile
168 'mouse-face
'custom-button-pressed-face
169 'action
'semantic-symref-rb-goto-file
176 'mouse-face
'highlight
178 'action
'semantic-symref-rb-toggle-expand-tag
182 (insert-button (funcall semantic-symref-results-summary-function
184 'mouse-face
'custom-button-pressed-face
186 'action
'semantic-symref-rb-goto-tag
194 (set-buffer-modified-p nil
)
197 ;;; Commands for semantic-symref-results
199 (defun semantic-symref-list-toggle-showing ()
200 "Toggle showing the contents below the current line."
203 (when (re-search-forward "\\[[-+]\\]" (point-at-eol) t
)
207 (defun semantic-symref-rb-toggle-expand-tag (&optional button
)
208 "Go to the file specified in the symref results buffer.
209 BUTTON is the button that was clicked."
211 (let* ((tag (button-get button
'tag
))
212 (buff (semantic-tag-buffer tag
))
213 (hits (semantic--tag-get-property tag
:hit
))
214 (state (button-get button
'state
))
219 (toggle-read-only -
1)
220 (with-current-buffer buff
222 (goto-char (point-min))
223 (forward-line (1- H
))
225 (back-to-indentation)
226 (setq text
(cons (buffer-substring (point) (point-at-eol)) text
)))
227 (setq text
(nreverse text
))
229 (goto-char (button-start button
))
233 (button-put button
'state
'open
)
239 (insert-button (car text
)
240 'mouse-face
'highlight
242 'action
'semantic-symref-rb-goto-match
245 (setq text
(cdr text
)
250 (toggle-read-only -
1)
251 (button-put button
'state
'closed
)
252 ;; Delete the various bits.
253 (goto-char (button-start button
))
260 (delete-region (point)
263 (forward-line (length hits
))
270 (defun semantic-symref-rb-goto-file (&optional button
)
271 "Go to the file specified in the symref results buffer.
272 BUTTON is the button that was clicked."
273 (let* ((tag (button-get button
'tag
))
274 (buff (semantic-tag-buffer tag
))
275 (win (selected-window))
277 (switch-to-buffer-other-window buff
)
278 (pulse-momentary-highlight-one-line (point))
279 (when (eq last-command-event ?\s
) (select-window win
))
283 (defun semantic-symref-rb-goto-tag (&optional button
)
284 "Go to the file specified in the symref results buffer.
285 BUTTON is the button that was clicked."
287 (let* ((tag (button-get button
'tag
))
288 (buff (semantic-tag-buffer tag
))
289 (win (selected-window))
291 (switch-to-buffer-other-window buff
)
292 (semantic-go-to-tag tag
)
293 (pulse-momentary-highlight-one-line (point))
294 (when (eq last-command-event ?\s
) (select-window win
))
298 (defun semantic-symref-rb-goto-match (&optional button
)
299 "Go to the file specified in the symref results buffer.
300 BUTTON is the button that was clicked."
302 (let* ((tag (button-get button
'tag
))
303 (line (button-get button
'line
))
304 (buff (semantic-tag-buffer tag
))
305 (win (selected-window))
307 (switch-to-buffer-other-window buff
)
308 (with-no-warnings (goto-line line
))
309 (pulse-momentary-highlight-one-line (point))
310 (when (eq last-command-event ?\s
) (select-window win
))
314 (defun semantic-symref-list-next-line ()
315 "Next line in `semantic-symref-results-mode'."
318 (back-to-indentation))
320 (defun semantic-symref-list-prev-line ()
321 "Next line in `semantic-symref-results-mode'."
324 (back-to-indentation))
326 (provide 'semantic
/symref
/list
)
329 ;; generated-autoload-file: "../loaddefs.el"
330 ;; generated-autoload-feature: semantic/loaddefs
331 ;; generated-autoload-load-name: "semantic/symref/list"
334 ;; arch-tag: e355d9c6-26e0-42d1-9bf1-f4801a54fffa
335 ;;; semantic/symref/list.el ends here