Function: python-nav-end-of-statement

python-nav-end-of-statement is an interactive and byte-compiled function defined in python.el.gz.

Signature

(python-nav-end-of-statement &optional NOEND)

Documentation

Move to end of current statement.

Optional argument NOEND is internal and makes the logic to not jump to the end of line when moving forward searching for the end of the statement.

Probably introduced at or before Emacs version 27.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-nav-end-of-statement (&optional noend)
  "Move to end of current statement.
Optional argument NOEND is internal and makes the logic to not
jump to the end of line when moving forward searching for the end
of the statement."
  (interactive "^")
  (let (string-start bs-pos (last-string-end 0))
    (while (and (or noend (goto-char (line-end-position)))
                (not (eobp))
                (cond ((setq string-start (python-syntax-context 'string))
                       ;; The condition can be nil if syntax table
                       ;; text properties and the `syntax-ppss' cache
                       ;; are somehow out of whack.  This has been
                       ;; observed when using `syntax-ppss' during
                       ;; narrowing.
                       (when (>= string-start last-string-end)
                         (goto-char string-start)
                         (if (python-syntax-context 'paren)
                             ;; Ended up inside a paren, roll again.
                             (python-nav-end-of-statement t)
                           ;; This is not inside a paren, move to the
                           ;; end of this string.
                           (goto-char (+ (point)
                                         (python-syntax-count-quotes
                                          (char-after (point)) (point))))
                           (setq
                            last-string-end
                            (or (if (eq t (nth 3 (syntax-ppss)))
                                    (cl-loop
                                     while (re-search-forward
                                            (rx (or "\"\"\"" "'''")) nil t)
                                     unless (python-syntax-context 'string)
                                     return (point))
                                  (ignore-error scan-error
                                    (goto-char string-start)
                                    (python-nav--lisp-forward-sexp)
                                    (point)))
                                (goto-char (point-max)))))))
                      ((python-syntax-context 'paren)
                       ;; The statement won't end before we've escaped
                       ;; at least one level of parenthesis.
                       (condition-case err
                           (goto-char (scan-lists (point) 1 -1))
                         (scan-error (goto-char (nth 3 err)))))
                      ((setq bs-pos (python-info-line-ends-backslash-p))
                       (goto-char bs-pos)
                       (forward-line 1))))))
  (point-marker))