diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 6295dad559e..321bc5eb94a 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -874,22 +874,24 @@ With numeric ARG, just insert that many colons. With | |||
| 874 | (python-rx line-start (* space) defun (+ space) symbol-name) | 874 | (python-rx line-start (* space) defun (+ space) symbol-name) |
| 875 | "Regular expresion matching beginning of innermost class or function.") | 875 | "Regular expresion matching beginning of innermost class or function.") |
| 876 | 876 | ||
| 877 | (defun python-nav-beginning-of-defun () | 877 | (defun python-nav-beginning-of-defun (&optional nodecorators) |
| 878 | "Move point to beginning-of-defun. | 878 | "Move point to beginning-of-defun. |
| 879 | This is the main part of`python-beginning-of-defun-function' | 879 | When NODECORATORS is non-nil decorators are not included. This |
| 880 | is the main part of`python-beginning-of-defun-function' | ||
| 880 | implementation." | 881 | implementation." |
| 881 | (let ((indent-pos (save-excursion | 882 | (let ((indent-pos (save-excursion |
| 882 | (back-to-indentation) | 883 | (back-to-indentation) |
| 883 | (point-marker))) | 884 | (point-marker))) |
| 884 | (include-decorators | 885 | (include-decorators |
| 885 | (lambda () | 886 | (lambda () |
| 886 | (when (save-excursion | 887 | (when (not nodecorators) |
| 887 | (forward-line -1) | 888 | (when (save-excursion |
| 888 | (looking-at (python-rx decorator))) | 889 | (forward-line -1) |
| 889 | (while (and (not (bobp)) | 890 | (looking-at (python-rx decorator))) |
| 890 | (forward-line -1) | 891 | (while (and (not (bobp)) |
| 891 | (looking-at (python-rx decorator)))) | 892 | (forward-line -1) |
| 892 | (when (not (bobp)) (forward-line 1)))))) | 893 | (looking-at (python-rx decorator)))) |
| 894 | (when (not (bobp)) (forward-line 1))))))) | ||
| 893 | (if (and (> (point) indent-pos) | 895 | (if (and (> (point) indent-pos) |
| 894 | (save-excursion | 896 | (save-excursion |
| 895 | (goto-char (line-beginning-position)) | 897 | (goto-char (line-beginning-position)) |
| @@ -902,20 +904,21 @@ implementation." | |||
| 902 | (goto-char (or (python-info-ppss-context 'string) (point))) | 904 | (goto-char (or (python-info-ppss-context 'string) (point))) |
| 903 | (funcall include-decorators)))) | 905 | (funcall include-decorators)))) |
| 904 | 906 | ||
| 905 | (defun python-beginning-of-defun-function (&optional arg) | 907 | (defun python-beginning-of-defun-function (&optional arg nodecorators) |
| 906 | "Move point to the beginning of def or class. | 908 | "Move point to the beginning of def or class. |
| 907 | With positive ARG move that number of functions forward. With | 909 | With positive ARG move that number of functions forward. With |
| 908 | negative do the same but backwards." | 910 | negative do the same but backwards. When NODECORATORS is non-nil |
| 911 | decorators are not included." | ||
| 909 | (when (or (null arg) (= arg 0)) (setq arg 1)) | 912 | (when (or (null arg) (= arg 0)) (setq arg 1)) |
| 910 | (if (> arg 0) | 913 | (if (> arg 0) |
| 911 | (dotimes (i arg) | 914 | (dotimes (i arg) |
| 912 | (python-nav-beginning-of-defun)) | 915 | (python-nav-beginning-of-defun nodecorators)) |
| 913 | (dotimes (i (- arg)) | 916 | (dotimes (i (- arg)) |
| 914 | (python-end-of-defun-function) | 917 | (python-end-of-defun-function) |
| 915 | (forward-comment 1) | 918 | (forward-comment 1) |
| 916 | (goto-char (line-end-position)) | 919 | (goto-char (line-end-position)) |
| 917 | (when (not (eobp)) | 920 | (when (not (eobp)) |
| 918 | (python-nav-beginning-of-defun))))) | 921 | (python-nav-beginning-of-defun nodecorators))))) |
| 919 | 922 | ||
| 920 | (defun python-end-of-defun-function () | 923 | (defun python-end-of-defun-function () |
| 921 | "Move point to the end of def or class. | 924 | "Move point to the end of def or class. |
| @@ -1934,18 +1937,21 @@ Interactively, prompt for symbol." | |||
| 1934 | This function is compatible to be used as | 1937 | This function is compatible to be used as |
| 1935 | `add-log-current-defun-function' since it returns nil if point is | 1938 | `add-log-current-defun-function' since it returns nil if point is |
| 1936 | not inside a defun." | 1939 | not inside a defun." |
| 1937 | (let ((names '())) | 1940 | (let ((names '()) |
| 1941 | (min-indent)) | ||
| 1938 | (save-restriction | 1942 | (save-restriction |
| 1939 | (widen) | 1943 | (widen) |
| 1940 | (save-excursion | 1944 | (save-excursion |
| 1941 | (beginning-of-line) | 1945 | (forward-comment -1) |
| 1942 | (when (not (>= (current-indentation) python-indent-offset)) | 1946 | (goto-char (line-end-position)) |
| 1943 | (while (and (not (eobp)) (forward-comment 1)))) | ||
| 1944 | (while (and (not (equal 0 (current-indentation))) | 1947 | (while (and (not (equal 0 (current-indentation))) |
| 1945 | (python-beginning-of-defun-function)) | 1948 | (not (python-beginning-of-defun-function 1 t))) |
| 1946 | (back-to-indentation) | 1949 | (when (or (not min-indent) |
| 1947 | (looking-at "\\(?:def\\|class\\) +\\([^(]+\\)[^:]+:\\s-*\n") | 1950 | (< (current-indentation) min-indent)) |
| 1948 | (setq names (cons (match-string-no-properties 1) names))))) | 1951 | (setq min-indent (current-indentation)) |
| 1952 | (back-to-indentation) | ||
| 1953 | (looking-at "\\(?:def\\|class\\) +\\([^(]+\\)[^:]+:\\s-*\n") | ||
| 1954 | (setq names (cons (match-string-no-properties 1) names)))))) | ||
| 1949 | (when names | 1955 | (when names |
| 1950 | (mapconcat (lambda (string) string) names ".")))) | 1956 | (mapconcat (lambda (string) string) names ".")))) |
| 1951 | 1957 | ||