Function: python-nav-if-name-main
python-nav-if-name-main is an interactive and byte-compiled function
defined in python.el.gz.
Signature
(python-nav-if-name-main)
Documentation
Move point at the beginning the __main__ block.
When "if __name__ == \\='__main__\\=':" is found returns its position, else returns nil.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(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)))))