From: Yuan Fu Date: Thu, 17 Apr 2025 05:50:56 +0000 (-0700) Subject: Remove treesit.el dependency from prog-mode.el X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=21f7cba1e3ce6f679428954fb4ea8f25d9dee3d6;p=emacs.git Remove treesit.el dependency from prog-mode.el 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) --- diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el index 3714929ec0e..19a32080fb4 100644 --- a/lisp/progmodes/prog-mode.el +++ b/lisp/progmodes/prog-mode.el @@ -30,10 +30,7 @@ ;;; 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."