Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
e5c144d6
Commit
e5c144d6
authored
Sep 02, 2013
by
Fabián Ezequiel Gallina
Browse files
* progmodes/python.el (python-nav-if-name-main): New command.
parent
cd16c5f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
6 deletions
+30
-6
lisp/ChangeLog
lisp/ChangeLog
+1
-0
lisp/progmodes/python.el
lisp/progmodes/python.el
+29
-6
No files found.
lisp/ChangeLog
View file @
e5c144d6
...
...
@@ -2,6 +2,7 @@
* progmodes/python.el (python-shell-completion-get-completions):
Drop use of deleted `comint-last-prompt-overlay'.
(python-nav-if-name-main): New command.
2013-09-01 Glenn Morris <rgm@gnu.org>
...
...
lisp/progmodes/python.el
View file @
e5c144d6
...
...
@@ -52,12 +52,12 @@
;; Extra functions `python-nav-forward-statement',
;; `python-nav-backward-statement',
;; `python-nav-beginning-of-statement', `python-nav-end-of-statement',
;; `python-nav-beginning-of-block'
and
`python-nav-end-of-block' a
re
;; included but no bound to any key. At
last but not least the
;; specialized `python-nav-forward-sexp' allows
easy navigation
;; between code blocks. If you prefer `cc-mode'-like
`forward-sexp'
;; movement, setting `forward-sexp-function' to nil is
enough, You can
;; do that using the `python-mode-hook':
;; `python-nav-beginning-of-block'
,
`python-nav-end-of-block' a
nd
;;
`python-nav-if-name-main' are
included but no bound to any key. At
;;
last but not least the
specialized `python-nav-forward-sexp' allows
;;
easy navigation
between code blocks. If you prefer `cc-mode'-like
;;
`forward-sexp'
movement, setting `forward-sexp-function' to nil is
;;
enough, You can
do that using the `python-mode-hook':
;; (add-hook 'python-mode-hook
;; (lambda () (setq forward-sexp-function nil)))
...
...
@@ -1583,6 +1583,29 @@ This command assumes point is not in a string or comment."
(
or
arg
(
setq
arg
1
))
(
python-nav-up-list
(
-
arg
)))
(
defun
python-nav-if-name-main
()
"Move point at the beginning the __main__ block.
When \"if __name__ == '__main__':\" is found returns its
position, else returns nil."
(
interactive
)
(
let
((
point
(
point
))
(
found
(
catch
'found
(
goto-char
(
point-min
))
(
while
(
re-search-forward
(
python-rx
line-start
"if"
(
+
space
)
"__name__"
(
+
space
)
"=="
(
+
space
)
(
group-n
1
(
or
?\"
?\'
))
"__main__"
(
backref
1
)
(
*
space
)
":"
)
nil
t
)
(
when
(
not
(
python-syntax-context-type
))
(
beginning-of-line
)
(
throw
'found
t
))))))
(
if
found
(
point
)
(
ignore
(
goto-char
point
)))))
;;; Shell integration
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment