blob: 40f2a5d0a0c2c52197d7af0392a53e721f9da9f6 (
plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
;; geiser-xref.el -- utilities for cross-referencing
;; Copyright (C) 2009 Jose Antonio Ortega Ruiz
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Start date: Thu Mar 05, 2009 23:03
;; This file 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 3 of the License, or
;; (at your option) any later version.
;; This file 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, see <http://www.gnu.org/licenses/>.
;;; Comentary:
;; Obtaining cross-reference information (generic's methods, callers, etc.)
;;; Code:
(require' geiser-edit)
(require 'geiser-eval)
(require 'geiser-popup)
(require 'geiser-custom)
(require 'geiser-base)
(require 'button)
;;; Customization:
(defgroup geiser-xref nil
"Options for cross-referencing commands."
:group 'geiser)
(geiser-edit--define-custom-visit
geiser-xref-follow-link-method geiser-xref
"How to visit buffers when following xrefs.")
(geiser-custom--defface xref-link
'link geiser-xref "links in cross-reference buffers")
(geiser-custom--defface xref-header
'bold geiser-xref "headers in cross-reference buffers")
;;; Ref button:
(define-button-type 'geiser-xref--button
'action 'geiser-xref--button-action
'face 'geiser-font-lock-xref-link
'follow-link t)
(defun geiser-xref--button-action (button)
(let ((location (button-get button 'location))
(name (button-get button 'name)))
(when location
(geiser-edit--try-edit-location name location geiser-xref-follow-link-method))))
(defun geiser-xref--insert-button (xref)
(let* ((location (cdr (assoc 'location xref)))
(file (geiser-edit--location-file location))
(signature (cdr (assoc 'signature xref)))
(module (cdr (assoc 'module xref))))
(when signature
(insert "\t")
(if (stringp file)
(insert-text-button (format "%s" signature)
:type 'geiser-xref--button
'location location
'name (car signature)
'help-echo (format "%s in %s" (car signature) file))
(insert (format "%s" signature)))
(when (and (not (null module)) (not (eq '\#f module)))
(insert (format " in module %s" module)))
(newline))))
(defun geiser-xref--display-xrefs (header xrefs)
(geiser-xref--with-buffer
(erase-buffer)
(geiser--insert-with-face header 'geiser-font-lock-xref-header)
(newline 2)
(mapc 'geiser-xref--insert-button xrefs))
(geiser-xref--pop-to-buffer))
(defun geiser-xref--read-name (ask prompt)
(let ((name (or (and (not prompt) (symbol-at-point))
(read-string prompt nil nil (symbol-at-point)))))
(and name (format "%s" name))))
(defun geiser-xref--fetch-xrefs (ask kind rkind proc)
(let* ((name (geiser-xref--read-name (format "%s: " (capitalize kind)) ask))
(res (and name (geiser-eval--send/result
`(:eval ((:ge ,proc) (quote (:scm ,name))))))))
(if (or (not res) (not (listp res)))
(message "No %ss found for '%s'" rkind name)
(geiser-xref--display-xrefs (format "%ss for %s" rkind name) res))))
;;; Buffer and mode:
(geiser-popup--define xref "*Geiser xref*" geiser-xref-mode)
(defvar geiser-xref-mode-map
(let ((map (make-sparse-keymap)))
(suppress-keymap map)
(set-keymap-parent map button-buffer-map)
map))
(defun geiser-xref-mode ()
"Major mode for displaying cross-references.
\\{geiser-xref-mode-map}"
(interactive)
(kill-all-local-variables)
(buffer-disable-undo)
(use-local-map geiser-xref-mode-map)
(set-syntax-table scheme-mode-syntax-table)
(setq mode-name "Geiser Xref")
(setq major-mode 'geiser-xref-mode)
(setq buffer-read-only t))
;;; Commands:
(defun geiser-xref-generic-methods (&optional arg)
"Display information about known methods of a given generic.
With prefix, ask for the name of the generic."
(interactive "P")
(geiser-xref--fetch-xrefs arg "generic" "method" 'generic-methods))
(defun geiser-xref-callers (&optional arg)
"Display list of callers for procedure at point.
With prefix, ask for the procedure."
(interactive "P")
(geiser-xref--fetch-xrefs arg "procedure" "caller" 'callers))
(defun geiser-xref-callees (&optional arg)
"Display list of callees for procedure at point.
With prefix, ask for the procedure."
(interactive "P")
(geiser-xref--fetch-xrefs arg "procedure" "callee" 'callees))
(provide 'geiser-xref)
;;; geiser-xref.el ends here
|