From d0cd8633a1d0befe1692d023c28eaf44529a72a2 Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Sun, 18 Jun 2017 12:43:39 +0200 Subject: [PATCH] Make the comment test more robust by not relying on font-lock --- beginend.el | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/beginend.el b/beginend.el index d495373..cb34fe3 100644 --- a/beginend.el +++ b/beginend.el @@ -250,12 +250,21 @@ BEGIN-BODY and END-BODY are two `progn' expressions passed to respectively (magit-section-backward) (magit-section-backward))) -;; Copy/pasted from expand-region -(defun beginend--point-is-in-comment-p () - "Return non-nil if point is in comment." - (or (nth 4 (syntax-ppss)) - (memq (get-text-property (point) 'face) - '(font-lock-comment-face font-lock-comment-delimiter-face)))) +(defun beginend--point-is-in-comment-p (&optional p) + "Return non-nil if point is in comment. + +If optional argument P is present test at that point instead of `point'." + (setq p (or p (point))) + (ignore-errors + (save-excursion + (or (nth 4 (syntax-ppss p)) + (eq (char-syntax (char-after p)) ?<) + (let ((s (car (syntax-after p)))) + (when s + (or (and (/= 0 (logand (lsh 1 16) s)) + (nth 4 (syntax-ppss (+ p 2)))) + (and (/= 0 (logand (lsh 1 17) s)) + (nth 4 (syntax-ppss (+ p 1))))))))))) (defun beginend--prog-mode-code-position-p () "Return non-nil if point, at beginning of line, is inside code."