[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode df5d2c5 122/385: better whitespace gap de
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode df5d2c5 122/385: better whitespace gap detection |
Date: |
Tue, 5 Oct 2021 23:59:14 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit df5d2c5e0b6e1767efb93fe75b68ea4643fe40c5
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
better whitespace gap detection
---
haskell-tng-syntax.el | 53 ++++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 26 deletions(-)
diff --git a/haskell-tng-syntax.el b/haskell-tng-syntax.el
index 22f3635..d28d9bf 100644
--- a/haskell-tng-syntax.el
+++ b/haskell-tng-syntax.el
@@ -116,40 +116,41 @@ string or char as the 2nd parameter and no whitespace."
(rx "\\" (syntax string-quote))
end t)
(let* ((escape (match-beginning 0))
- (before (haskell-tng:syntax:count-escapes escape)))
- (when (and
- (cl-evenp before) ;; makes sure it's a real escape
- (not (looking-back ;; and not a whitespace gap terminal
- (rx "\\" (+ (| space ?\n)) "\\" (syntax string-quote))
- (point-min))))
+ (before (haskell-tng:syntax:count-escapes escape t)))
+ (when (cl-evenp before) ;; makes sure it's a real escape
(put-text-property escape (1+ escape) 'syntax-table '(9))))))
-(defun haskell-tng:syntax:count-escapes (pos)
- "Count the number of escapes before point.
-Even means the next char is not escaped."
- (if (or (= 1 pos) (/= ?\\ (char-before pos)))
- 0
- (1+ (haskell-tng:syntax:count-escapes (1- pos)))))
+(defun haskell-tng:syntax:count-escapes (pos &optional skip-whitespace)
+ "Count the number of escapes before POS.
+Even means the next char is not escaped.
+
+SKIP-WHITESPACE can be used to ignore whitespace gaps."
+ (if (= (point-min) pos) 0
+ (let ((c (char-before pos)))
+ (if (and skip-whitespace (or (= ?\n c) (= 32 (char-syntax c))))
+ (haskell-tng:syntax:count-escapes (1- pos) t)
+ (if (= c ?\\)
+ (1+ (haskell-tng:syntax:count-escapes (1- pos)))
+ 0)))))
(defun haskell-tng:syntax:escapes (start end)
"Backslash inside String is an escape character \n."
;; TODO does this pull its weight? (slow, requires a ppss)
(goto-char start)
(while (re-search-forward (rx "\\") end t)
- (unless
- ;; \...whitespace...\ is not escaped
- ;; it is tempting to skip ahead here, but it can go beyond `end'
- (or
- (looking-at (rx (+ (| space ?\n)) "\\"))
- (looking-back (rx "\\" (+ (| space ?\n)) "\\") (point-min)))
- (let ((escape (match-beginning 0)))
- (when (/= 9 (car (syntax-after escape))) ;; already calculated
- (let ((before (haskell-tng:syntax:count-escapes escape)))
- (when (and (cl-evenp before) (nth 3 (syntax-ppss)))
- (put-text-property escape (1+ escape) 'syntax-table '(9)))))
- (when (= 9 (car (syntax-after escape)))
- ;; next char is escaped, so no need to check it
- (forward-char 1))))))
+ (let ((escape (match-beginning 0)))
+ (if (= 9 (car (syntax-after escape))) ;; already calculated
+ (forward-char 1)
+ (unless (looking-at (rx (+ (| space ?\n)) "\\"))
+ (let ((before (haskell-tng:syntax:count-escapes escape t)))
+ (unless (and (cl-oddp before)
+ (looking-back (rx (| space ?\n)) (1- escape)))
+ (when (and (cl-evenp before)
+ (nth 3 (syntax-ppss)))
+ (put-text-property escape (1+ escape) 'syntax-table '(9)))
+ (when (= 9 (car (syntax-after escape)))
+ ;; next char is escaped, so no need to check it
+ (forward-char 1)))))))))
(provide 'haskell-tng-syntax)
;;; haskell-tng-syntax.el ends here
- [nongnu] elpa/haskell-tng-mode f085f16 097/385: indentation regression tests, (continued)
- [nongnu] elpa/haskell-tng-mode f085f16 097/385: indentation regression tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 01ea0b8 103/385: heuristic alternative indentation levels, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c20ea4f 096/385: infix varid as symid, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode bfe859a 095/385: notes about lexers, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0506391 109/385: module ... where indents to 0, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d9bbcdd 111/385: next steps, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6cf67bf 105/385: indentation can't handle mismatched parens, don't test for it, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 25b15eb 102/385: indentation alternatives wiring, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode e023657 107/385: SMIE wishlist, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 497214b 119/385: syntax tests and bugfixes, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode df5d2c5 122/385: better whitespace gap detection,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 3b7cd02 123/385: some todos, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fc4d3e3 127/385: compilation mode supports multiline error spans, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 88bad65 128/385: visually distinguish compile errors and warnings, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9dc0abc 129/385: alt indentation levels should be ordered, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 879fc34 130/385: thots, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1009082 140/385: append indentation test, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 88b17d4 137/385: started indentation rules, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode cf22f3a 138/385: simplify indentation testing, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a0f777e 166/385: Revert "duplicate ; tokens to be used as terminators", ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 2320b89 167/385: alternative to smie-rules-* in :elem and :list-intro, ELPA Syncer, 2021/10/06