Skip to content

Commit

Permalink
Make the comment test more robust by not relying on font-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuco1 authored and DamienCassou committed Jun 18, 2017
1 parent 5cf8048 commit 6c5f36b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions beginend.el
Expand Up @@ -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."
Expand Down

0 comments on commit 6c5f36b

Please sign in to comment.