]> git.eshelyaron.com Git - emacs.git/commitdiff
Remove treesit.el dependency from prog-mode.el
authorYuan Fu <casouri@gmail.com>
Thu, 17 Apr 2025 05:50:56 +0000 (22:50 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 17 Apr 2025 07:19:46 +0000 (09:19 +0200)
prog-mode.el doens't need treesit.el dependency.  And it
shouldn't depend on it.  In principle, treesit.el should
integrate into various parts of Emacs through standard hooks and
variables.

* lisp/progmodes/prog-mode.el:
(prog-fill-reindent-defun): Remove treesit.el functions.  Use
generic functions to check whether the current line has
comments, and make the test more comprehensive.

(cherry picked from commit 79814379d646e507c1af8ab26e300ac43d036664)

lisp/progmodes/prog-mode.el

index 3714929ec0eb5f7e1fdfc15e18664f22e9804256..19a32080fb44151b1c4473b43b72c87943f0ced5 100644 (file)
 ;;; Code:
 
 (eval-when-compile (require 'cl-lib)
-                   (require 'subr-x)
-                   (require 'treesit))
-
-(treesit-declare-unavailable-functions)
+                   (require 'subr-x))
 
 (defgroup prog-mode nil
   "Generic programming mode, from which others derive."
@@ -146,8 +143,6 @@ instead."
          (end (progn (forward-sexp 1) (point))))
       (indent-region start end nil))))
 
-(declare-function treesit-node-at "treesit.c")
-
 (defun prog-fill-reindent-defun (&optional argument)
   "Refill or reindent the paragraph or defun that contains point.
 
@@ -158,19 +153,33 @@ Otherwise, reindent the function definition that contains point
 or follows point."
   (interactive "P")
   (save-excursion
-    (let ((treesit-text-node
-           (and (treesit-available-p)
-                (treesit-parser-list)
-                (treesit-node-match-p
-                 (treesit-node-at (point)) 'text t))))
-      (if (or treesit-text-node
-              (nth 8 (syntax-ppss))
-              (re-search-forward "\\s-*\\s<" (line-end-position) t))
-          (fill-paragraph argument (region-active-p))
-        (beginning-of-defun)
-        (let ((start (point)))
-          (end-of-defun)
-          (indent-region start (point) nil))))))
+    ;; FIXME: For some reason, the comment-start syntax regexp doesn't
+    ;; work for me.  But I kept it around to be safe, and in the hope
+    ;; that if can cover cases where comment-start-skip is unset.
+    (if (or (nth 4 (syntax-ppss))
+            ;; If point is at the beginning of a comment delimiter,
+            ;; syntax-ppss doesn't consider point as being inside a
+            ;; comment.
+            (save-excursion
+              (beginning-of-line)
+              (and comment-start-skip
+                   ;; FIXME: This doesn't work for the case where there
+                   ;; are two matches of comment-start-skip, and the
+                   ;; first one is, say, inside a string.  We need to
+                   ;; call re-search-forward repeatedly until either
+                   ;; reached EOL or (nth 4 (syntax-ppss)) returns
+                   ;; non-nil.
+                   (re-search-forward comment-start-skip (pos-eol) t)
+                   (nth 4 (syntax-ppss))))
+            (save-excursion
+              (beginning-of-line)
+              (and (re-search-forward "\\s-*\\s<" (line-end-position) t)
+                   (nth 4 (syntax-ppss)))))
+        (fill-paragraph argument (region-active-p))
+      (beginning-of-defun)
+      (let ((start (point)))
+        (end-of-defun)
+        (indent-region start (point) nil)))))
 
 (defun prog-first-column ()
   "Return the indentation column normally used for top-level constructs."