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.el55
1 files changed, 38 insertions, 17 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 7284e7a1ed9..cdf8419f288 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2302,22 +2302,29 @@ not inside a defun."
2302 2302
2303(defun python-info-continuation-line-p () 2303(defun python-info-continuation-line-p ()
2304 "Return non-nil if current line is continuation of another." 2304 "Return non-nil if current line is continuation of another."
2305 (or (python-info-line-ends-backslash-p) 2305 (let ((current-ppss-context-type (python-info-ppss-context-type)))
2306 (string-match ",[[:space:]]*$" (buffer-substring 2306 (and
2307 (line-beginning-position) 2307 (equal (save-excursion
2308 (line-end-position))) 2308 (goto-char (line-end-position))
2309 (save-excursion 2309 (forward-comment 9999)
2310 (let ((innermost-paren (progn 2310 (python-info-ppss-context-type))
2311 (goto-char (line-end-position)) 2311 current-ppss-context-type)
2312 (python-info-ppss-context 'paren)))) 2312 (or (python-info-line-ends-backslash-p)
2313 (when (and innermost-paren 2313 (string-match ",[[:space:]]*$" (buffer-substring
2314 (and (<= (line-beginning-position) innermost-paren) 2314 (line-beginning-position)
2315 (>= (line-end-position) innermost-paren))) 2315 (line-end-position)))
2316 (goto-char innermost-paren) 2316 (save-excursion
2317 (looking-at (python-rx open-paren (* space) line-end))))) 2317 (let ((innermost-paren (progn
2318 (save-excursion 2318 (goto-char (line-end-position))
2319 (back-to-indentation) 2319 (python-info-ppss-context 'paren))))
2320 (python-info-ppss-context 'paren)))) 2320 (when (and innermost-paren
2321 (and (<= (line-beginning-position) innermost-paren)
2322 (>= (line-end-position) innermost-paren)))
2323 (goto-char innermost-paren)
2324 (looking-at (python-rx open-paren (* space) line-end)))))
2325 (save-excursion
2326 (back-to-indentation)
2327 (python-info-ppss-context 'paren))))))
2321 2328
2322(defun python-info-block-continuation-line-p () 2329(defun python-info-block-continuation-line-p ()
2323 "Return non-nil if current line is a continuation of a block." 2330 "Return non-nil if current line is a continuation of a block."
@@ -2351,7 +2358,7 @@ not inside a defun."
2351 2358
2352(defun python-info-ppss-context (type &optional syntax-ppss) 2359(defun python-info-ppss-context (type &optional syntax-ppss)
2353 "Return non-nil if point is on TYPE using SYNTAX-PPSS. 2360 "Return non-nil if point is on TYPE using SYNTAX-PPSS.
2354TYPE can be 'comment, 'string or 'parent. It returns the start 2361TYPE can be 'comment, 'string or 'paren. It returns the start
2355character address of the specified TYPE." 2362character address of the specified TYPE."
2356 (let ((ppss (or syntax-ppss (syntax-ppss)))) 2363 (let ((ppss (or syntax-ppss (syntax-ppss))))
2357 (case type 2364 (case type
@@ -2364,6 +2371,20 @@ character address of the specified TYPE."
2364 (nth 1 ppss)) 2371 (nth 1 ppss))
2365 (t nil)))) 2372 (t nil))))
2366 2373
2374(defun python-info-ppss-context-type (&optional syntax-ppss)
2375 "Return the context type using SYNTAX-PPSS.
2376The type returned can be 'comment, 'string or 'paren."
2377 (let ((ppss (or syntax-ppss (syntax-ppss))))
2378 (cond
2379 ((and (nth 4 ppss)
2380 (nth 8 ppss))
2381 'comment)
2382 ((nth 8 ppss)
2383 'string)
2384 ((nth 1 ppss)
2385 'paren)
2386 (t nil))))
2387
2367 2388
2368;;; Utility functions 2389;;; Utility functions
2369 2390