branch: externals/lisp-ts-mode
commit 628bd1a23375a2a6971149c46d298c6015f5004c
Author: Zach Shaftel <[email protected]>
Commit: Zach Shaftel <[email protected]>

    Extend font-lock region to whole comments
---
 lisp-ts-mode.el | 79 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 39 insertions(+), 40 deletions(-)

diff --git a/lisp-ts-mode.el b/lisp-ts-mode.el
index 59d177d2a6d..94fc84ecf77 100644
--- a/lisp-ts-mode.el
+++ b/lisp-ts-mode.el
@@ -715,7 +715,7 @@ format_string node which contains point. Return the column 
to indent to."
        ;; whole string
        (goto-char (ts-node-start parent))
        (+ (current-column) lisp-ts-mode-format-string-indent-offset))
-      (t (back-to-indentation))         ;non exit clause
+      (t (back-to-indentation))
       ((/= (ts-node-start ender) (point))
        ;; not indenting the closing directive so indent relative to
        ;; the opener
@@ -814,7 +814,7 @@ for at point with `lisp-ts-mode--find-parser-at'."
 `indent-sexp' is remapped to this command in `lisp-ts-mode' so that it
 triggers FORMAT string indentation. ENDPOS, if supplied, is the position
 where indentation stops, defaulting to the end of the sexp."
-  (interactive)
+  (interactive () lisp-ts-mode)
   (let ((inhibit-message t))           ;indent-region is loud, indent-sexp 
isn't
     (indent-region (save-excursion (backward-prefix-chars) (point))
                    (or endpos (save-excursion (forward-sexp) (point))))))
@@ -828,29 +828,27 @@ where indentation stops, defaulting to the end of the 
sexp."
 
 (defun lisp-ts-mode-up-list (arg escape-strings no-syntax-crossing)
   "Used as `up-list-function' in `lisp-ts-mode'."
-  (cond
-    ((not no-syntax-crossing)
-     ;; FIXME handle format directives!
-     (up-list-default-function arg escape-strings no-syntax-crossing))
-    (t (let* ((pred '(or "\\`string\\'" list))
-              (node (lisp-ts-mode--thing-node-at-pos pred))
-              (backwards-p (minusp arg))
-              (arg (truncate (abs arg)))
-              (parent nil))
-         (unless (or (= (ts-node-start node) (point))
-                     (= (ts-node-end node) (point)))
-           (and (equal (ts-node-type node) "string")
-                (not escape-strings)
-                (plusp arg)
-                (error "At top level"))
-           (decf arg))
-         (while (and (plusp arg)
-                     (setq parent (ts-parent-until node 'list)))
-           (decf arg)
-           (setq node parent))
-         (goto-char (if backwards-p
-                        (ts-node-start node)
-                      (ts-node-end node)))))))
+  (if (not no-syntax-crossing)
+      (up-list-default-function arg escape-strings no-syntax-crossing)
+    (let* ((pred '(or "\\`string\\'" list))
+           (node (lisp-ts-mode--thing-node-at-pos pred))
+           (backwards-p (minusp arg))
+           (arg (truncate (abs arg)))
+           (parent nil))
+      (unless (or (= (ts-node-start node) (point))
+                  (= (ts-node-end node) (point)))
+        (and (equal (ts-node-type node) "string")
+             (not escape-strings)
+             (plusp arg)
+             (error "At top level"))
+        (decf arg))
+      (while (and (plusp arg)
+                  (setq parent (ts-parent-until node 'list)))
+        (decf arg)
+        (setq node parent))
+      (goto-char (if backwards-p
+                     (ts-node-start node)
+                   (ts-node-end node))))))
 
 (defun lisp-ts-mode--extend-fl-region ()
   "Added to `font-lock-extend-region-functions' in `lisp-ts-mode'.
@@ -859,24 +857,25 @@ Prevents the font-lock region from starting or ending in 
the middle of
 an expression."
   (defvar font-lock-beg)
   (defvar font-lock-end)
-  (let* ((beg-sexp (lisp-ts-mode--sexp-node-at-pos font-lock-beg t))
-         (change-beg (and beg-sexp
-                          (< (ts-node-start beg-sexp)
-                             font-lock-beg
-                             (ts-node-end beg-sexp)))))
+  (let* ((thing '(or sexp "block_comment" "line_comment"))
+         (beg-node (lisp-ts-mode--thing-node-at-pos thing font-lock-beg t))
+         (change-beg (and beg-node (< (ts-node-start beg-node)
+                                      font-lock-beg
+                                      (ts-node-end beg-node)))))
     (when change-beg
-      (setq font-lock-beg (ts-node-start beg-sexp)))
+      (setq font-lock-beg (ts-node-start beg-node)))
     (or (cond*
-          ((and beg-sexp (< (ts-node-start beg-sexp)
+          ((and beg-node (< (ts-node-start beg-node)
                             font-lock-end
-                            (ts-node-end beg-sexp)))
-           (setq font-lock-end (ts-node-end beg-sexp)))
-          ((eq (ts-node-end beg-sexp) font-lock-end) nil)
-          ((bind* (end-sexp (lisp-ts-mode--sexp-node-at-pos (1- font-lock-end) 
t))))
-          ((and end-sexp (< (ts-node-start end-sexp)
-                            font-lock-end
-                            (ts-node-end end-sexp)))
-           (setq font-lock-end (ts-node-end end-sexp))))
+                            (ts-node-end beg-node)))
+           (setq font-lock-end (ts-node-end beg-node)))
+          ((eq (ts-node-end beg-node) font-lock-end) nil)
+          ((bind-and*
+            (end-node (lisp-ts-mode--thing-node-at-pos thing (1- 
font-lock-end) t))
+            (_ (< (ts-node-start end-node)
+                  font-lock-end
+                  (ts-node-end end-node))))
+           (setq font-lock-end (ts-node-end end-node))))
         change-beg)))
 
 (defconst lisp-ts-mode--syntax-propertize-query

Reply via email to