-
Notifications
You must be signed in to change notification settings - Fork 0
/
findrout.el
208 lines (193 loc) · 6.2 KB
/
findrout.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
;;; Pinched from mjn
;;; F601 chah Added default routine
;;;###autoload
(defun find-routine-or-line (dest)
"Move to the specified routine or line number."
(interactive (find-routine-interactive "Routine or line: "))
(if (string-match "^[0-9]+$" dest)
(goto-line (string-to-number dest))
(find-routine dest)))
;;;###autoload
(defun find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name
and before any parameter declarations.
Requires that function `XYZ-find-routine' is bound when the major-mode
is XYZ-mode."
(interactive (find-routine-interactive "Find routine: "))
(let* ((symname (symbol-name major-mode))
(funcname (concat (substring symname 0 -5) "-find-routine"))
(funcsym (intern funcname)))
(or (fboundp funcsym) (error "Function %s not defined" funcname))
(funcall funcsym name)))
;; Read destination with a default
(defun find-routine-interactive (prompt)
(list
(let* ((default (find-routine-default))
(spec (read-string (if default
(format "%s(default %s) " prompt default)
prompt))))
(if (equal spec "")
(or default (error "There is no default routine"))
spec))))
;; Read a default routine name from point. Copied from find-tag-default.
(defun find-routine-default ()
(save-excursion
(while (looking-at "\\sw\\|\\s_")
(forward-char 1))
(if (or (re-search-backward "\\sw\\|\\s_"
(save-excursion (beginning-of-line) (point))
t)
(re-search-forward "\\(\\sw\\|\\s_\\)+"
(save-excursion (end-of-line) (point))
t))
(progn (goto-char (match-end 0))
(buffer-substring (point)
(progn (forward-sexp -1)
(while (looking-at "\\s'")
(forward-char 1))
(point))))
nil)))
(defun fortran-find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name
and before any parameter declarations."
(interactive "sFind routine: ")
(let* ((here (point)))
(goto-char (point-min))
(if (re-search-forward
(concat "\\(function\\|subroutine\\|entry\\|block *data\\) +"
name)
(point-max) t)
(progn
(push-mark here)
(re-search-forward "[ ]*(" (save-excursion (end-of-line) (point)) t))
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun cpl-find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name
and before any parameter declarations."
(interactive "sFind routine: ")
(let* ((here (point)))
(goto-char (point-min))
(if (re-search-forward
(concat "\\(function\\|subroutine\\|program\\) +" name)
(point-max) t)
(push-mark here)
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun emacs-lisp-find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name
and before any parameter declarations."
(interactive "sFind routine: ")
(let* ((here (point)))
(goto-char (point-min))
(if (re-search-forward
(concat "^(defun[ \t]+" name)
(point-max) t)
(push-mark here)
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun c-find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name
and before any parameter declarations."
(interactive "sFind routine: ")
(let* ((here (point))
(case-fold-search t)
found)
(goto-char (point-min))
(while (and (not found)
(re-search-forward
(concat "^\\([a-z0-9_][a-z0-9_ ]*[ \t]\\**\\)?"
name "[a-z0-9_]*[ \t]?(")
(point-max) t))
(save-excursion
(backward-char)
(forward-sexp)
(skip-chars-forward " \t\n")
(if (looking-at ";")
nil
(push-mark here)
(setq found t))))
(if (not found)
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun perl-find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name."
(interactive "sFind routine: ")
(let* ((here (point))
(case-fold-search nil))
(goto-char (point-min))
(if (re-search-forward
(concat "^sub[ \t]+" name)
(point-max) t)
(push-mark here)
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun tcl-find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name."
(interactive "sFind routine: ")
(let* ((here (point))
(case-fold-search nil))
(goto-char (point-min))
(if (re-search-forward
(concat "\\bproc[ \t]+{?" (regexp-quote name))
(point-max) t)
(push-mark here)
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun sh-find-routine (name)
"Find the specified routine name in the current buffer.
If found, the point will be placed following the routine name."
(interactive "sFind routine: ")
(let* ((here (point))
(case-fold-search nil))
(goto-char (point-min))
(if (re-search-forward
(concat "^" (regexp-quote name) "\\w*()")
(point-max) t)
(progn
(skip-chars-backward "()")
(push-mark here))
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun python-find-routine (name)
"Find the specified function or class name in the current buffer.
If found, the point will be placed following the routine name."
(interactive "sFind routine: ")
(let* ((here (point))
(case-fold-search nil))
(goto-char (point-min))
(if (re-search-forward
(concat "^[ \t]*\\(def\\|class\\)[ \t]+" (regexp-quote name))
(point-max) t)
(push-mark here)
(progn
(goto-char here)
(error "Routine %s not found" name)))))
(defun mimic-find-routine (name)
"Find the specified function or class name in the current buffer.
If found, the point will be placed following the routine name."
(interactive "sFind routine: ")
(let* ((here (point))
(case-fold-search t))
(goto-char (point-min))
(if (re-search-forward
(concat "^[ \t]*sub\\(r\\(outine\\)?\\)?-beg\\(in\\)?[ \t]+" (regexp-quote name))
(point-max) t)
(push-mark here)
(progn
(goto-char here)
(error "Routine %s not found" name)))))