From 856552879434f16abb7bd8a7af0be34c6589264b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:03:22 -0300 Subject: [PATCH] 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 --- lisp/progmodes/python.el | 55 +++++++++++++++++++++++++++------------- 1 file 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." (defun python-info-continuation-line-p () "Return non-nil if current line is continuation of another." - (or (python-info-line-ends-backslash-p) - (string-match ",[[:space:]]*$" (buffer-substring - (line-beginning-position) - (line-end-position))) - (save-excursion - (let ((innermost-paren (progn - (goto-char (line-end-position)) - (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)))) + (let ((current-ppss-context-type (python-info-ppss-context-type))) + (and + (equal (save-excursion + (goto-char (line-end-position)) + (forward-comment 9999) + (python-info-ppss-context-type)) + current-ppss-context-type) + (or (python-info-line-ends-backslash-p) + (string-match ",[[:space:]]*$" (buffer-substring + (line-beginning-position) + (line-end-position))) + (save-excursion + (let ((innermost-paren (progn + (goto-char (line-end-position)) + (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 () "Return non-nil if current line is a continuation of a block." @@ -2351,7 +2358,7 @@ not inside a defun." (defun python-info-ppss-context (type &optional 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." (let ((ppss (or syntax-ppss (syntax-ppss)))) (case type @@ -2364,6 +2371,20 @@ character address of the specified TYPE." (nth 1 ppss)) (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 -- 2.39.5