Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 130 lines (106 sloc) 5.124 kB
6012642 @thierryvolpiatto * helm-call-tree.el: new
thierryvolpiatto authored
1 ;;; helm-call-tree.el --- Helm interface of `simple-call-tree.el'.
2
3 ;; Copyright (C) 2012 Thierry Volpiatto <thierry.volpiatto@gmail.com>
4
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
9
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
19
20 ;;; Code:
21
22 (eval-when-compile (require 'cl))
23 (require 'helm)
24
7d8197a @thierryvolpiatto Fix warnings at compilation.
thierryvolpiatto authored
25 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
26
6012642 @thierryvolpiatto * helm-call-tree.el: new
thierryvolpiatto authored
27 ;; Function is called by
28 (defvar helm-c-source-simple-call-tree-functions-callers
29 '((name . "Function is called by")
30 (init . helm-c-simple-call-tree-functions-callers-init)
31 (multiline)
32 (candidates . helm-c-simple-call-tree-candidates)
33 (persistent-action . helm-c-simple-call-tree-persistent-action)
34 (persistent-help . "Show function definitions by rotation")
35 (action ("Find definition selected by persistent-action" .
36 helm-c-simple-call-tree-find-definition)))
37 "Needs simple-call-tree.el.
38 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
39
40 (defvar helm-c-simple-call-tree-tick nil)
41 (make-variable-buffer-local 'helm-c-simple-call-tree-tick)
42 (defun helm-c-simple-call-tree-analyze-maybe ()
43 (unless (eq (buffer-chars-modified-tick) helm-c-simple-call-tree-tick)
44 (simple-call-tree-analyze)
45 (setq helm-c-simple-call-tree-tick (buffer-chars-modified-tick))))
46
47 (defun helm-c-simple-call-tree-init-base (function message)
48 (require 'simple-call-tree)
49 (with-no-warnings
50 (when (helm-current-buffer-is-modified)
51 (helm-c-simple-call-tree-analyze-maybe)
52 (let ((list (funcall function simple-call-tree-alist)))
53 (with-current-buffer (helm-candidate-buffer 'local)
54 (dolist (entry list)
55 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
56 (insert (car entry) message
57 (if (string= funcs " ")
58 " no functions."
59 funcs)
60 "\n\n"))))))))
61
62 (defun helm-c-simple-call-tree-functions-callers-init ()
63 (helm-c-simple-call-tree-init-base 'simple-call-tree-invert
64 " is called by\n"))
65
66 (defun helm-c-simple-call-tree-candidates ()
67 (with-current-buffer (helm-candidate-buffer)
68 (split-string (buffer-string) "\n\n")))
69
70 (defvar helm-c-simple-call-tree-related-functions nil)
71 (defvar helm-c-simple-call-tree-function-index 0)
72 (defun helm-c-simple-call-tree-persistent-action (candidate)
73 (unless (eq last-command 'helm-execute-persistent-action)
74 (setq helm-c-simple-call-tree-related-functions
75 (delete "no functions."
76 (split-string
77 (replace-regexp-in-string " \\| is called by\\| calls "
78 "" candidate)
79 "\n")))
80 (setq helm-c-simple-call-tree-function-index -1))
81 (incf helm-c-simple-call-tree-function-index)
82 (helm-c-simple-call-tree-find-definition candidate))
83
84 (defun helm-c-simple-call-tree-find-definition (candidate)
85 (find-function
86 (intern
87 (nth (mod helm-c-simple-call-tree-function-index
88 (length helm-c-simple-call-tree-related-functions))
89 helm-c-simple-call-tree-related-functions))))
90
91
92 ;;; Function calls
93 (defvar helm-c-source-simple-call-tree-callers-functions
94 '((name . "Function calls")
95 (init . helm-c-simple-call-tree-callers-functions-init)
96 (multiline)
97 (candidates . helm-c-simple-call-tree-candidates)
98 (persistent-action . helm-c-simple-call-tree-persistent-action)
99 (persistent-help . "Show function definitions by rotation")
100 (action ("Find definition selected by persistent-action" .
101 helm-c-simple-call-tree-find-definition)))
102 "Needs simple-call-tree.el.
103 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
104
105 (defun helm-c-simple-call-tree-callers-functions-init ()
106 (helm-c-simple-call-tree-init-base 'identity " calls \n"))
107
108 ;;;###autoload
109 (defun helm-simple-call-tree ()
110 "Preconfigured `helm' for simple-call-tree. List function relationships.
111
112 Needs simple-call-tree.el.
113 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
114 (interactive)
115 (helm-other-buffer
116 '(helm-c-source-simple-call-tree-functions-callers
117 helm-c-source-simple-call-tree-callers-functions)
118 "*helm simple-call-tree*"))
119
120 (provide 'helm-call-tree)
121
37b4201 @thierryvolpiatto Fix dependencies and autoloads. Reorder.
thierryvolpiatto authored
122 ;; Local Variables:
a7ee65b @thierryvolpiatto Disable compile warnings and add new keyword to helm.
thierryvolpiatto authored
123 ;; byte-compile-warnings: (not cl-functions obsolete)
37b4201 @thierryvolpiatto Fix dependencies and autoloads. Reorder.
thierryvolpiatto authored
124 ;; coding: utf-8
125 ;; indent-tabs-mode: nil
126 ;; byte-compile-dynamic: t
127 ;; End:
128
6012642 @thierryvolpiatto * helm-call-tree.el: new
thierryvolpiatto authored
129 ;;; helm-call-tree.el ends here
Something went wrong with that request. Please try again.