aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el35
1 files changed, 21 insertions, 14 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 0b9d99cbbee..5abfe91809b 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -878,10 +878,12 @@ With numeric ARG, just insert that many colons. With
878 "Move point to `beginning-of-defun'. 878 "Move point to `beginning-of-defun'.
879When NODECORATORS is non-nil decorators are not included. This 879When NODECORATORS is non-nil decorators are not included. This
880is the main part of`python-beginning-of-defun-function' 880is the main part of`python-beginning-of-defun-function'
881implementation." 881implementation. Return non-nil if point is moved to the
882beginning-of-defun."
882 (let ((indent-pos (save-excursion 883 (let ((indent-pos (save-excursion
883 (back-to-indentation) 884 (back-to-indentation)
884 (point-marker))) 885 (point-marker)))
886 (found)
885 (include-decorators 887 (include-decorators
886 (lambda () 888 (lambda ()
887 (when (not nodecorators) 889 (when (not nodecorators)
@@ -898,27 +900,32 @@ implementation."
898 (looking-at python-nav-beginning-of-defun-regexp))) 900 (looking-at python-nav-beginning-of-defun-regexp)))
899 (progn 901 (progn
900 (goto-char (line-beginning-position)) 902 (goto-char (line-beginning-position))
901 (funcall include-decorators)) 903 (funcall include-decorators)
904 (setq found t))
902 (goto-char (line-beginning-position)) 905 (goto-char (line-beginning-position))
903 (re-search-backward python-nav-beginning-of-defun-regexp nil t) 906 (when (re-search-backward python-nav-beginning-of-defun-regexp nil t)
907 (setq found t))
904 (goto-char (or (python-info-ppss-context 'string) (point))) 908 (goto-char (or (python-info-ppss-context 'string) (point)))
905 (funcall include-decorators)))) 909 (funcall include-decorators))
910 found))
906 911
907(defun python-beginning-of-defun-function (&optional arg nodecorators) 912(defun python-beginning-of-defun-function (&optional arg nodecorators)
908 "Move point to the beginning of def or class. 913 "Move point to the beginning of def or class.
909With positive ARG move that number of functions forward. With 914With positive ARG move that number of functions forward. With
910negative do the same but backwards. When NODECORATORS is non-nil 915negative do the same but backwards. When NODECORATORS is non-nil
911decorators are not included." 916decorators are not included. Return non-nil if point is moved to the
917beginning-of-defun."
912 (when (or (null arg) (= arg 0)) (setq arg 1)) 918 (when (or (null arg) (= arg 0)) (setq arg 1))
913 (if (> arg 0) 919 (if (> arg 0)
914 (dotimes (i arg) 920 (dotimes (i arg (python-nav-beginning-of-defun nodecorators)))
915 (python-nav-beginning-of-defun nodecorators)) 921 (let ((found))
916 (dotimes (i (- arg)) 922 (dotimes (i (- arg) found)
917 (python-end-of-defun-function) 923 (python-end-of-defun-function)
918 (forward-comment 1) 924 (forward-comment 1)
919 (goto-char (line-end-position)) 925 (goto-char (line-end-position))
920 (when (not (eobp)) 926 (when (not (eobp))
921 (python-nav-beginning-of-defun nodecorators))))) 927 (setq found
928 (python-nav-beginning-of-defun nodecorators)))))))
922 929
923(defun python-end-of-defun-function () 930(defun python-end-of-defun-function ()
924 "Move point to the end of def or class. 931 "Move point to the end of def or class.
@@ -1949,7 +1956,7 @@ not inside a defun."
1949 (goto-char (line-end-position)) 1956 (goto-char (line-end-position))
1950 (forward-comment -1) 1957 (forward-comment -1)
1951 (while (and (not (equal 0 (current-indentation))) 1958 (while (and (not (equal 0 (current-indentation)))
1952 (not (python-beginning-of-defun-function 1 t))) 1959 (python-beginning-of-defun-function 1 t))
1953 (when (or (not min-indent) 1960 (when (or (not min-indent)
1954 (< (current-indentation) min-indent)) 1961 (< (current-indentation) min-indent))
1955 (setq min-indent (current-indentation)) 1962 (setq min-indent (current-indentation))