From 0a60bc107123321438fc1320ab34fcf588ec7128 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Tue, 17 Jul 2012 17:27:49 -0300 Subject: [PATCH] New utility functions + python-info-ppss-context fix. * progmodes/python.el (python-info-beginning-of-block-statement-p) (python-info-ppss-comment-or-string-p): New functions. (python-info-ppss-context): Small fix for string check. Fixes: debbugs:11910 --- lisp/ChangeLog | 7 +++++++ lisp/progmodes/python.el | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cbc233079a7..6a6093583ab 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-07-17 Fabián Ezequiel Gallina + + New utility functions + python-info-ppss-context fix (Bug#11910). + * progmodes/python.el (python-info-beginning-of-block-statement-p) + (python-info-ppss-comment-or-string-p): New functions. + (python-info-ppss-context): Small fix for string check. + 2012-07-17 Juri Linkov * dired-aux.el (dired-do-async-shell-command): Doc fix. diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e9b5770dc87..54486ba5a52 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2584,6 +2584,12 @@ not inside a defun." (when names (mapconcat (lambda (string) string) names ".")))) +(defsubst python-info-beginning-of-block-statement-p () + "Return non-nil if current statement opens a block." + (save-excursion + (python-nav-beginning-of-statement) + (looking-at (python-rx block-start)))) + (defun python-info-closing-block () "Return the point of the block the current line closes." (let ((closing-word (save-excursion @@ -2736,7 +2742,8 @@ character address of the specified TYPE." (and (nth 4 ppss) (nth 8 ppss))) ('string - (nth 8 ppss)) + (and (not (nth 4 ppss)) + (nth 8 ppss))) ('paren (nth 1 ppss)) (t nil)))) @@ -2755,6 +2762,10 @@ The type returned can be 'comment, 'string or 'paren." 'paren) (t nil)))) +(defsubst python-info-ppss-comment-or-string-p () + "Return non-nil if point is inside 'comment or 'string." + (car (member (python-info-ppss-context-type) '(string comment)))) + (defun python-info-looking-at-beginning-of-defun (&optional syntax-ppss) "Check if point is at `beginning-of-defun' using SYNTAX-PPSS." (and (not (python-info-ppss-context-type (or syntax-ppss (syntax-ppss)))) -- 2.39.2