[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rainbow-delimiters 1305bca532 087/188: Use comment-search-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rainbow-delimiters 1305bca532 087/188: Use comment-search-forward to see if a delimiter starts a comment. |
Date: |
Sat, 1 Jan 2022 00:58:55 -0500 (EST) |
branch: elpa/rainbow-delimiters
commit 1305bca532f482f248814f0b918b0989a6c12dd4
Author: Fanael Linithien <fanael4@gmail.com>
Commit: Fanael Linithien <fanael4@gmail.com>
Use comment-search-forward to see if a delimiter starts a comment.
(looking-at comment-start-skip) is not always enough, because some
major modes set `comment-start-skip' to not exactly what we expect.
Fixes #35.
---
rainbow-delimiters.el | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el
index 940ee1bb30..0e8a08b267 100644
--- a/rainbow-delimiters.el
+++ b/rainbow-delimiters.el
@@ -96,6 +96,7 @@
;; - Intelligent support for other languages: Ruby, LaTeX tags, et al.
;;; Code:
+(require 'newcomment)
;;; Customize interface:
@@ -437,8 +438,19 @@ Returns t if char at loc meets one of the following
conditions:
(nth 4 ppss) ; inside comment?
(save-excursion ; starting a comment?
(goto-char loc)
- (let ((inhibit-changing-match-data t))
- (looking-at comment-start-skip)))
+ (and
+ ;; Fast path: if this test fails, it's not a comment, and we avoid a
+ ;; costly `comment-search-forward' call.
+ (let ((inhibit-changing-match-data t))
+ (looking-at comment-start-skip))
+ ;; Some major modes set `comment-start-skip' to not exactly what we
+ ;; expect, catching more than actual comments. Use
+ ;; `comment-search-forward' to see if it's really a comment.
+ ;; NOTE: is lookahead of five characters enough for all languages? I hope
+ ;; there's no language with 6-character comment delimiters.
+ (save-match-data
+ (let ((comment-start-pos (comment-search-forward (min (+ 5 loc)
(point-max)) t)))
+ (and comment-start-pos (= loc comment-start-pos))))))
(and rainbow-delimiters-escaped-char-predicate
(funcall rainbow-delimiters-escaped-char-predicate loc))))
@@ -531,6 +543,8 @@ Used by font-lock for dynamic highlighting."
(defun rainbow-delimiters-mode-turn-on ()
"Set up `rainbow-delimiters-mode'."
+ ;; Necessary for our use of `comment-search-forward'.
+ (comment-normalize-vars t)
;; Flush the ppss cache now in case there's something left in there.
(setq rainbow-delimiters-parse-partial-sexp-cache nil)
(add-hook 'before-change-functions
'rainbow-delimiters-syntax-ppss-flush-cache t t)
- [nongnu] elpa/rainbow-delimiters 43b02d2d20 075/188: Rename rainbow-delimiters-keywords., (continued)
- [nongnu] elpa/rainbow-delimiters 43b02d2d20 075/188: Rename rainbow-delimiters-keywords., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters a095a77dc9 066/188: Correct the prefix of the rainbow-delimiters-faces group., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters d7946fdf94 078/188: Fix a typo in a comment., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 14e0f971f6 079/188: Call font-lock-{flush, fontify-buffer} only when font-lock-mode is on., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters b3f87cfe99 072/188: Highlight delimiters even in already highlighted text., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters a37d19b415 082/188: Add a comment explaining the previous change., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 36efff58a8 081/188: Don't highlight delimiters inside comments starting with two chars., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 24f6c5767e 083/188: Release version 1.3.8., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 35eace73ca 084/188: Reuse parse-partial-sexp state in rainbow-delimiters-propertize., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters ddf7f179d3 085/188: Change defsubst -> defun., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 1305bca532 087/188: Use comment-search-forward to see if a delimiter starts a comment.,
ELPA Syncer <=
- [nongnu] elpa/rainbow-delimiters 6d488e566a 089/188: Test if comment-start-skip is non-nil before using it., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 3d425a85d3 094/188: Don't enable in Completion List Mode, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters ecacb319d3 093/188: Wrap the font-lock-fontify-buffer call with with-no-warnings., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 6cdf1f1c14 096/188: Merge pull request #38 from lunaryorn/patch-1, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters e2a67de8e7 097/188: Deprecate global-rainbow-delimiters-mode., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 29e7bfd8e4 098/188: Remove global-rainbow-delimiters-mode from installation instructions., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 4cc4d38479 099/188: Remove global-rainbow-delimiters-mode., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters d35b992378 106/188: Don't error when highlighting an unmatched closing delimiter., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters e48b7bf746 104/188: Merge pull request #41 from jlr/no-global, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters f2404ef0bf 108/188: Remove dead code., ELPA Syncer, 2022/01/01