From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#68993: treesitter support for forward-sexp-default-function Date: Wed, 10 Apr 2024 21:03:07 +0300 Organization: LINKOV.NET Message-ID: <86seztf5to.fsf@mail.linkov.net> References: <86y1bv6jsm.fsf@mail.linkov.net> <86a5o86wl5.fsf@mail.linkov.net> <12153B04-8B7E-43D4-8EC4-8931021F1965@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19996"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 68993@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 10 20:11:21 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rucPp-000556-Np for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Apr 2024 20:11:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rucPU-0001Ql-Mj; Wed, 10 Apr 2024 14:11:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rucPR-0001Pv-9c for bug-gnu-emacs@gnu.org; Wed, 10 Apr 2024 14:10:57 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rucPR-000681-0p for bug-gnu-emacs@gnu.org; Wed, 10 Apr 2024 14:10:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rucPZ-0002vW-KN for bug-gnu-emacs@gnu.org; Wed, 10 Apr 2024 14:11:05 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Apr 2024 18:11:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68993 X-GNU-PR-Package: emacs Original-Received: via spool by 68993-submit@debbugs.gnu.org id=B68993.171277265311112 (code B ref 68993); Wed, 10 Apr 2024 18:11:05 +0000 Original-Received: (at 68993) by debbugs.gnu.org; 10 Apr 2024 18:10:53 +0000 Original-Received: from localhost ([127.0.0.1]:54349 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rucPJ-0002sT-GF for submit@debbugs.gnu.org; Wed, 10 Apr 2024 14:10:52 -0400 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:35927) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rucPG-0002rx-NI for 68993@debbugs.gnu.org; Wed, 10 Apr 2024 14:10:47 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id ACA0DC0003; Wed, 10 Apr 2024 18:10:29 +0000 (UTC) In-Reply-To: <12153B04-8B7E-43D4-8EC4-8931021F1965@gmail.com> (Yuan Fu's message of "Sun, 11 Feb 2024 17:28:03 -0800") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:283060 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit > My suggestion would be for both treesit-forward-sentence and -sexp to > use “text” for their heuristic. If someone wants more customized > behavior, they can always write a custom forward-sentence/sexp function. Thanks for the suggestion. So here is the patch that implements this: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=treesit-forward-sexp-text.patch diff --git a/lisp/treesit.el b/lisp/treesit.el index 1443162f79c..62d797513fc 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -2145,7 +2145,10 @@ treesit-forward-sexp (interactive "^p") (let ((arg (or arg 1)) (pred (or treesit-sexp-type-regexp 'sexp))) - (or (if (> arg 0) + (or (when (treesit-node-match-p (treesit-node-at (point)) 'text t) + (funcall #'forward-sexp-default-function arg) + t) + (if (> arg 0) (treesit-end-of-thing pred (abs arg) 'restricted) (treesit-beginning-of-thing pred (abs arg) 'restricted)) ;; If we couldn't move, we should signal an error and report diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index c57b1357f63..4c0f720b1a0 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -45,7 +45,12 @@ parens-require-spaces :type 'boolean :group 'lisp) -(defvar forward-sexp-function nil +(defun forward-sexp-default-function (&optional arg) + "Default function for `forward-sexp-function'." + (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) + (if (< arg 0) (backward-prefix-chars))) + +(defvar forward-sexp-function #'forward-sexp-default-function ;; FIXME: ;; - for some uses, we may want a "sexp-only" version, which only ;; jumps over a well-formed sexp, rather than some dwimish thing @@ -74,10 +79,9 @@ forward-sexp "No next sexp" "No previous sexp")))) (or arg (setq arg 1)) - (if forward-sexp-function - (funcall forward-sexp-function arg) - (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) - (if (< arg 0) (backward-prefix-chars))))) + (funcall (or forward-sexp-function + #'forward-sexp-default-function) + arg))) (defun backward-sexp (&optional arg interactive) "Move backward across one balanced expression (sexp). --=-=-=--