Function: python-info-docstring-p
python-info-docstring-p is a byte-compiled function defined in
python.el.gz.
Signature
(python-info-docstring-p &optional SYNTAX-PPSS)
Documentation
Return non-nil if point is in a docstring.
When optional argument SYNTAX-PPSS is given, use that instead of
point's current syntax-ppss.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-info-docstring-p (&optional syntax-ppss)
"Return non-nil if point is in a docstring.
When optional argument SYNTAX-PPSS is given, use that instead of
point's current `syntax-ppss'."
;;; https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring
(save-excursion
(when (and syntax-ppss (python-syntax-context 'string syntax-ppss))
(goto-char (nth 8 syntax-ppss)))
(python-nav-beginning-of-statement)
(let ((counter 1)
(indentation (current-indentation))
(backward-sexp-point)
(re "[uU]?[rR]?[\"']"))
(when (and
(not (python-info-assignment-statement-p))
(looking-at-p re)
;; Allow up to two consecutive docstrings only.
(>=
2
(let (last-backward-sexp-point)
(while (and (<= counter 2)
(save-excursion
(python-nav-backward-sexp)
(setq backward-sexp-point (point))
(and (= indentation (current-indentation))
;; Make sure we're always moving point.
;; If we get stuck in the same position
;; on consecutive loop iterations,
;; bail out.
(prog1 (not (eql last-backward-sexp-point
backward-sexp-point))
(setq last-backward-sexp-point
backward-sexp-point))
(looking-at-p re))))
;; Previous sexp was a string, restore point.
(goto-char backward-sexp-point)
(cl-incf counter))
counter)))
(python-util-forward-comment -1)
(python-nav-beginning-of-statement)
(cond ((and (bobp) (save-excursion
(python-util-forward-comment)
(looking-at-p re))))
((python-info-assignment-statement-p) t)
((python-info-looking-at-beginning-of-defun))
(t nil))))))