2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
1 |
;;; python-components-up-down.el -- Searching up/downwards in buffer -*- lexical-binding: t; -*-
|
1594
by Andreas Roehler
Upward commands; lp:1044122 |
2 |
|
2617
by Andreas Röhler
py-up forms alias provided |
3 |
;; Copyright (C) 2015-2016 Andreas Röhler
|
2396
by Andreas Röhler
email updated |
4 |
|
2420
by Andreas Röhler
Reset email to "@online.de" |
5 |
;; Author: Andreas Röhler <andreas.roehler@online.de>
|
1594
by Andreas Roehler
Upward commands; lp:1044122 |
6 |
;; Keywords: languages, convenience
|
7 |
||
8 |
;; This program is free software; you can redistribute it and/or modify
|
|
9 |
;; it under the terms of the GNU General Public License as published by
|
|
10 |
;; the Free Software Foundation, either version 3 of the License, or
|
|
11 |
;; (at your option) any later version.
|
|
12 |
||
13 |
;; This program is distributed in the hope that it will be useful,
|
|
14 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
;; GNU General Public License for more details.
|
|
17 |
||
18 |
;; You should have received a copy of the GNU General Public License
|
|
19 |
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
||
21 |
;;; Commentary:
|
|
22 |
||
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
23 |
;; This file is generated by function from python-mode-utils.el - see in
|
24 |
;; directory devel. Edits here might not be persistent.
|
|
25 |
||
1594
by Andreas Roehler
Upward commands; lp:1044122 |
26 |
;;; Code:
|
27 |
||
28 |
||
1621
by Andreas Roehler
`py-down-statement', new command |
29 |
(defun py-up-statement () |
30 |
"Go to the beginning of next statement upwards in buffer.
|
|
31 |
||
32 |
Return position if statement found, nil otherwise. "
|
|
33 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
34 |
(let (erg) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
35 |
(if (py--beginning-of-statement-p) |
36 |
(setq erg (py-backward-statement)) |
|
37 |
(setq erg (and (py-backward-statement) (py-backward-statement)))) |
|
2410
by Andreas Röhler
Reduce compiler warnings |
38 |
(when (and py-verbose-p (called-interactively-p 'any)) (message "%s" erg)) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
39 |
erg)) |
1621
by Andreas Roehler
`py-down-statement', new command |
40 |
|
41 |
(defun py-down-statement () |
|
1628
by Andreas Roehler
does not dedent regions, lp:1072869, fixed |
42 |
"Go to the beginning of next statement downwards in buffer.
|
1621
by Andreas Roehler
`py-down-statement', new command |
43 |
|
44 |
Return position if statement found, nil otherwise. "
|
|
45 |
(interactive) |
|
1628
by Andreas Roehler
does not dedent regions, lp:1072869, fixed |
46 |
(let* ((orig (point)) |
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
47 |
erg) |
48 |
(cond ((py--end-of-statement-p) |
|
49 |
(setq erg (and (py-forward-statement) (py-backward-statement)))) |
|
50 |
((setq erg (< orig (progn (py-forward-statement) (py-backward-statement)))) |
|
51 |
(point)) |
|
52 |
(t (setq erg (and (py-forward-statement) (py-forward-statement)(py-backward-statement))))) |
|
53 |
(when (and py-verbose-p (called-interactively-p 'any)) (message "%s" erg)) |
|
54 |
erg)) |
|
1621
by Andreas Roehler
`py-down-statement', new command |
55 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
56 |
(defun py-up-base (regexp &optional indent orig decorator bol repeat) |
2617
by Andreas Röhler
py-up forms alias provided |
57 |
"Go to the beginning of next form upwards in buffer.
|
1594
by Andreas Roehler
Upward commands; lp:1044122 |
58 |
|
2618
by Andreas Röhler
`py-up-base' fixed |
59 |
Return position if form found, nil otherwise.
|
60 |
REGEXP is a quoted symbol "
|
|
2619
by Andreas Röhler
`py-up-base-bol' removed |
61 |
(unless (bobp) |
62 |
(let* ((orig (or orig (point))) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
63 |
(repeat (or (and repeat (1+ repeat)) 999)) |
2619
by Andreas Röhler
`py-up-base-bol' removed |
64 |
erg name command) |
2621
by Andreas Röhler
Navigation - major rewrite |
65 |
(if (< py-max-specpdl-size repeat) |
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
66 |
(error "`py-up-base' reached loops max.") |
2621
by Andreas Röhler
Navigation - major rewrite |
67 |
(if indent |
68 |
(progn |
|
69 |
(while (and (re-search-backward (symbol-value regexp) nil 'move 1) |
|
70 |
(or (nth 8 (parse-partial-sexp (point-min) (point))) |
|
71 |
(<= indent (current-indentation)))))) |
|
72 |
(unless (py--beginning-of-statement-p) |
|
73 |
(py-backward-statement)) |
|
74 |
(if (looking-at (symbol-value regexp)) |
|
75 |
(py-up-base regexp (current-indentation) orig decorator bol repeat) |
|
76 |
(setq name (symbol-name regexp)) |
|
77 |
(setq command (intern-soft (concat "py-backward-" (substring name (string-match "minor\\|block\\|def\\|class" name) (string-match "-re" name))))) |
|
78 |
(funcall command) |
|
79 |
(py-up-base regexp (current-indentation) orig decorator bol repeat))) |
|
80 |
(when bol (beginning-of-line)) |
|
81 |
(and (looking-at (symbol-value regexp)) (< (point) orig) (setq erg (point))) |
|
82 |
(when py-verbose-p (message "%s" erg)) |
|
83 |
erg)))) |
|
1594
by Andreas Roehler
Upward commands; lp:1044122 |
84 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
85 |
(defun py-down-base (regexp &optional orig indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
86 |
"Go to the beginning of next form below in buffer.
|
87 |
||
2621
by Andreas Röhler
Navigation - major rewrite |
88 |
Return position if form found, nil otherwise.
|
89 |
Expects a quoted symbol 'REGEXP"
|
|
1594
by Andreas Roehler
Upward commands; lp:1044122 |
90 |
(unless (eobp) |
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
91 |
(let* ((name (substring (symbol-name regexp) 3 -3)) |
2621
by Andreas Röhler
Navigation - major rewrite |
92 |
(p-command (car (read-from-string (concat "py--beginning-of-" name "-p")))) |
93 |
(backward-command (car (read-from-string (concat "py-backward-" name)))) |
|
94 |
(up-command (car (read-from-string (concat "py-up-" name)))) |
|
2651
by Andreas Röhler
Arguments fixed |
95 |
;; (down-command (car (read-from-string (concat "py-down-" name))))
|
2621
by Andreas Röhler
Navigation - major rewrite |
96 |
(forward-command (car (read-from-string (concat "py-forward-" name)))) |
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
97 |
erg done start) |
2621
by Andreas Röhler
Navigation - major rewrite |
98 |
(if (funcall p-command) |
99 |
(setq indent (current-indentation)) |
|
100 |
(save-excursion |
|
2634
by Andreas Röhler
Navigation args cleanup |
101 |
(cond |
102 |
((and indent decorator bol) |
|
103 |
(funcall backward-command indent decorator bol)) |
|
104 |
((and indent decorator) |
|
105 |
(funcall backward-command indent decorator)) |
|
106 |
(t (funcall backward-command indent))) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
107 |
(setq indent (current-indentation)) |
108 |
(setq start (point)))) |
|
109 |
;; (setq done (funcall forward-command indent decorator bol))
|
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
110 |
(while (and (not done) |
111 |
(py-down-statement) |
|
112 |
(<= indent (current-indentation)) |
|
113 |
(when (looking-at (symbol-value regexp)) |
|
114 |
(setq done (point))))) |
|
115 |
(when done |
|
116 |
(when bol (beginning-of-line)) |
|
117 |
(setq erg (point))) |
|
118 |
(unless done |
|
2634
by Andreas Röhler
Navigation args cleanup |
119 |
(goto-char orig) |
120 |
(or |
|
121 |
(if |
|
122 |
(and |
|
123 |
(funcall up-command) |
|
124 |
;; up should not result to backward
|
|
125 |
(not (eq (point) start)) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
126 |
(funcall forward-command decorator bol) |
2634
by Andreas Röhler
Navigation args cleanup |
127 |
(< orig (point)) |
128 |
(setq erg (point))) |
|
129 |
(when bol (setq erg (py--beginning-of-line-form erg))) |
|
130 |
(goto-char (point-max))))) |
|
131 |
(when py-verbose-p (message "%s" erg)) |
|
132 |
erg))) |
|
1594
by Andreas Roehler
Upward commands; lp:1044122 |
133 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
134 |
(defalias 'py-block-up 'py-up-block) |
2621
by Andreas Röhler
Navigation - major rewrite |
135 |
(defun py-up-block (&optional indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
136 |
"Go to the beginning of next block upwards in buffer.
|
137 |
||
138 |
Return position if block found, nil otherwise. "
|
|
139 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
140 |
(py-up-base 'py-extended-block-or-clause-re indent (point) decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
141 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
142 |
(defalias 'py-class-up 'py-up-class) |
2621
by Andreas Röhler
Navigation - major rewrite |
143 |
(defun py-up-class (&optional indent decorator bol) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
144 |
"Go to the beginning of next class upwards in buffer.
|
145 |
||
146 |
Return position if class found, nil otherwise. "
|
|
147 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
148 |
(py-up-base 'py-class-re indent (point) decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
149 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
150 |
(defalias 'py-def-up 'py-up-def) |
2621
by Andreas Röhler
Navigation - major rewrite |
151 |
(defun py-up-def (&optional indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
152 |
"Go to the beginning of next def upwards in buffer.
|
153 |
||
154 |
Return position if def found, nil otherwise. "
|
|
155 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
156 |
(py-up-base 'py-def-re indent (point) decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
157 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
158 |
(defalias 'py-def-or-class-up 'py-up-def-or-class) |
2621
by Andreas Röhler
Navigation - major rewrite |
159 |
(defun py-up-def-or-class (&optional indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
160 |
"Go to the beginning of next def-or-class upwards in buffer.
|
161 |
||
162 |
Return position if def-or-class found, nil otherwise. "
|
|
163 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
164 |
(py-up-base 'py-def-or-class-re indent (point) decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
165 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
166 |
(defalias 'py-minor-block-up 'py-up-minor-block) |
2621
by Andreas Röhler
Navigation - major rewrite |
167 |
(defun py-up-minor-block (&optional indent decorator bol) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
168 |
"Go to the beginning of next minor-block upwards in buffer.
|
169 |
||
170 |
Return position if minor-block found, nil otherwise. "
|
|
171 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
172 |
(py-up-base 'py-extended-block-or-clause-re indent (point) decorator bol)) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
173 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
174 |
(defalias 'py-block-down 'py-down-block) |
2621
by Andreas Röhler
Navigation - major rewrite |
175 |
(defun py-down-block (&optional orig indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
176 |
"Go to the beginning of next block below in buffer.
|
177 |
||
178 |
Return position if block found, nil otherwise. "
|
|
179 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
180 |
(py-down-base 'py-block-re (or orig (point)) indent decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
181 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
182 |
(defalias 'py-class-down 'py-down-class) |
2621
by Andreas Röhler
Navigation - major rewrite |
183 |
(defun py-down-class (&optional orig indent decorator bol) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
184 |
"Go to the beginning of next class below in buffer.
|
185 |
||
186 |
Return position if class found, nil otherwise. "
|
|
187 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
188 |
(py-down-base 'py-class-re (or orig (point)) indent decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
189 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
190 |
(defalias 'py-def-down 'py-down-def) |
2621
by Andreas Röhler
Navigation - major rewrite |
191 |
(defun py-down-def (&optional orig indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
192 |
"Go to the beginning of next def below in buffer.
|
193 |
||
194 |
Return position if def found, nil otherwise. "
|
|
195 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
196 |
(py-down-base 'py-def-re (or orig (point)) indent decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
197 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
198 |
(defalias 'py-def-or-class-down 'py-down-def-or-class) |
2621
by Andreas Röhler
Navigation - major rewrite |
199 |
(defun py-down-def-or-class (&optional orig indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
200 |
"Go to the beginning of next def-or-class below in buffer.
|
201 |
||
202 |
Return position if def-or-class found, nil otherwise. "
|
|
203 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
204 |
(py-down-base 'py-def-or-class-re (or orig (point)) indent decorator bol)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
205 |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
206 |
(defalias 'py-minor-block-down 'py-down-minor-block) |
2621
by Andreas Röhler
Navigation - major rewrite |
207 |
(defun py-down-minor-block (&optional orig indent decorator bol) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
208 |
"Go to the beginning of next minor-block below in buffer.
|
209 |
||
210 |
Return position if minor-block found, nil otherwise. "
|
|
211 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
212 |
(py-down-base 'py-minor-block-re (or orig (point)) indent decorator bol)) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
213 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
214 |
(defun py-up-block-bol (&optional indent decorator) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
215 |
"Go to the beginning of next block upwards in buffer.
|
216 |
||
217 |
Go to beginning of line.
|
|
218 |
Return position if block found, nil otherwise. "
|
|
219 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
220 |
(py-up-base 'py-block-re indent (point) decorator t)) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
221 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
222 |
(defun py-up-class-bol (&optional indent decorator) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
223 |
"Go to the beginning of next class upwards in buffer.
|
224 |
||
225 |
Go to beginning of line.
|
|
226 |
Return position if class found, nil otherwise. "
|
|
227 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
228 |
(py-up-base 'py-class-re indent (point) decorator t)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
229 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
230 |
(defun py-up-def-bol (&optional indent decorator) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
231 |
"Go to the beginning of next def upwards in buffer.
|
232 |
||
233 |
Go to beginning of line.
|
|
234 |
Return position if def found, nil otherwise. "
|
|
235 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
236 |
(py-up-base 'py-def-re indent (point) decorator t)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
237 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
238 |
(defun py-up-def-or-class-bol (&optional indent decorator) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
239 |
"Go to the beginning of next def-or-class upwards in buffer.
|
240 |
||
241 |
Go to beginning of line.
|
|
242 |
Return position if def-or-class found, nil otherwise. "
|
|
243 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
244 |
(py-up-base 'py-def-or-class-re indent (point) decorator t)) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
245 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
246 |
(defun py-up-minor-block-bol (&optional indent decorator) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
247 |
"Go to the beginning of next minor-block upwards in buffer.
|
248 |
||
249 |
Go to beginning of line.
|
|
250 |
Return position if minor-block found, nil otherwise. "
|
|
251 |
(interactive) |
|
2621
by Andreas Röhler
Navigation - major rewrite |
252 |
(py-up-base 'py-minor-block-re indent (point) decorator t)) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
253 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
254 |
(defun py-down-block-bol (&optional orig indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
255 |
"Go to the beginning of next block below in buffer.
|
256 |
||
257 |
Go to beginning of line
|
|
258 |
Return position if block found, nil otherwise "
|
|
259 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
260 |
(py-down-base 'py-block-re (or orig (point)) indent decorator (or bol t))) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
261 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
262 |
(defun py-down-class-bol (&optional orig indent decorator bol) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
263 |
"Go to the beginning of next class below in buffer.
|
264 |
||
265 |
Go to beginning of line
|
|
266 |
Return position if class found, nil otherwise "
|
|
267 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
268 |
(py-down-base 'py-class-re (or orig (point)) indent decorator (or bol t))) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
269 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
270 |
(defun py-down-def-bol (&optional orig indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
271 |
"Go to the beginning of next def below in buffer.
|
272 |
||
273 |
Go to beginning of line
|
|
274 |
Return position if def found, nil otherwise "
|
|
275 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
276 |
(py-down-base 'py-def-re (or orig (point)) indent decorator (or bol t))) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
277 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
278 |
(defun py-down-def-or-class-bol (&optional orig indent decorator bol) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
279 |
"Go to the beginning of next def-or-class below in buffer.
|
280 |
||
281 |
Go to beginning of line
|
|
282 |
Return position if def-or-class found, nil otherwise "
|
|
283 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
284 |
(py-down-base 'py-def-or-class-re (or orig (point)) indent decorator (or bol t))) |
1594
by Andreas Roehler
Upward commands; lp:1044122 |
285 |
|
2621
by Andreas Röhler
Navigation - major rewrite |
286 |
(defun py-down-minor-block-bol (&optional orig indent decorator bol) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
287 |
"Go to the beginning of next minor-block below in buffer.
|
288 |
||
289 |
Go to beginning of line
|
|
290 |
Return position if minor-block found, nil otherwise "
|
|
291 |
(interactive) |
|
2638
by Andreas Röhler
Still more fixes WRT lexical-binding |
292 |
(py-down-base 'py-minor-block-re (or orig (point)) indent decorator (or bol t))) |
2391
by Andreas Röhler
Use `py-backward-' forms instead of `py-beginning-of' |
293 |
|
2396
by Andreas Röhler
email updated |
294 |
;; python-components-up-down.el ends here
|
1594
by Andreas Roehler
Upward commands; lp:1044122 |
295 |
(provide 'python-components-up-down) |