Commit 85655287 authored by Fabián Ezequiel Gallina's avatar Fabián Ezequiel Gallina Committed by Fabián Ezequiel Gallina
Browse files

Make python-info-continuation-line-p to check context type matches

In order for a line to be continuation of another, they must be on the
same context.

New Function:
    * python-info-ppss-context-type
parent 64348c32
...@@ -2302,22 +2302,29 @@ not inside a defun." ...@@ -2302,22 +2302,29 @@ not inside a defun."
(defun python-info-continuation-line-p () (defun python-info-continuation-line-p ()
"Return non-nil if current line is continuation of another." "Return non-nil if current line is continuation of another."
(or (python-info-line-ends-backslash-p) (let ((current-ppss-context-type (python-info-ppss-context-type)))
(string-match ",[[:space:]]*$" (buffer-substring (and
(line-beginning-position) (equal (save-excursion
(line-end-position))) (goto-char (line-end-position))
(save-excursion (forward-comment 9999)
(let ((innermost-paren (progn (python-info-ppss-context-type))
(goto-char (line-end-position)) current-ppss-context-type)
(python-info-ppss-context 'paren)))) (or (python-info-line-ends-backslash-p)
(when (and innermost-paren (string-match ",[[:space:]]*$" (buffer-substring
(and (<= (line-beginning-position) innermost-paren) (line-beginning-position)
(>= (line-end-position) innermost-paren))) (line-end-position)))
(goto-char innermost-paren) (save-excursion
(looking-at (python-rx open-paren (* space) line-end))))) (let ((innermost-paren (progn
(save-excursion (goto-char (line-end-position))
(back-to-indentation) (python-info-ppss-context 'paren))))
(python-info-ppss-context 'paren)))) (when (and innermost-paren
(and (<= (line-beginning-position) innermost-paren)
(>= (line-end-position) innermost-paren)))
(goto-char innermost-paren)
(looking-at (python-rx open-paren (* space) line-end)))))
(save-excursion
(back-to-indentation)
(python-info-ppss-context 'paren))))))
(defun python-info-block-continuation-line-p () (defun python-info-block-continuation-line-p ()
"Return non-nil if current line is a continuation of a block." "Return non-nil if current line is a continuation of a block."
...@@ -2351,7 +2358,7 @@ not inside a defun." ...@@ -2351,7 +2358,7 @@ not inside a defun."
(defun python-info-ppss-context (type &optional syntax-ppss) (defun python-info-ppss-context (type &optional syntax-ppss)
"Return non-nil if point is on TYPE using SYNTAX-PPSS. "Return non-nil if point is on TYPE using SYNTAX-PPSS.
TYPE can be 'comment, 'string or 'parent. It returns the start TYPE can be 'comment, 'string or 'paren. It returns the start
character address of the specified TYPE." character address of the specified TYPE."
(let ((ppss (or syntax-ppss (syntax-ppss)))) (let ((ppss (or syntax-ppss (syntax-ppss))))
(case type (case type
...@@ -2364,6 +2371,20 @@ character address of the specified TYPE." ...@@ -2364,6 +2371,20 @@ character address of the specified TYPE."
(nth 1 ppss)) (nth 1 ppss))
(t nil)))) (t nil))))
(defun python-info-ppss-context-type (&optional syntax-ppss)
"Return the context type using SYNTAX-PPSS.
The type returned can be 'comment, 'string or 'paren."
(let ((ppss (or syntax-ppss (syntax-ppss))))
(cond
((and (nth 4 ppss)
(nth 8 ppss))
'comment)
((nth 8 ppss)
'string)
((nth 1 ppss)
'paren)
(t nil))))
;;; Utility functions ;;; Utility functions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment