From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Plug treesit.el into other emacs constructs Date: Sat, 24 Dec 2022 09:01:36 -0500 Message-ID: References: <87wn6whete.fsf@thornhill.no> <87r0x3gnv5.fsf@thornhill.no> <04BB786A-3ED1-4918-8583-17AA01A1E453@gmail.com> <4E3940CA-67A6-45B7-8785-4E60FDECCDFB@gmail.com> <4315EFC6-7AA8-4A48-845C-9CA8B88034D9@thornhill.no> <87bko521n0.fsf@thornhill.no> <87359h1ybt.fsf@thornhill.no> <871qp01msi.fsf@thornhill.no> <87v8mczb6b.fsf@thornhill.no> <87sfhgz9s8.fsf@thornhill.no> <87pmckz8p0.fsf@thornhill.no> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26191"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Yuan Fu , emacs-devel@gnu.org, eliz@gnu.org To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 24 15:02:25 2022 Return-path: Envelope-to: ged-emacs-devel@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 1p956X-0006dm-1W for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Dec 2022 15:02:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p955w-0001h2-8K; Sat, 24 Dec 2022 09:01:48 -0500 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 1p955u-0001gq-Gg for emacs-devel@gnu.org; Sat, 24 Dec 2022 09:01:46 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p955s-0008QI-Nv; Sat, 24 Dec 2022 09:01:46 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A01791000F4; Sat, 24 Dec 2022 09:01:42 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 2E3F51000DC; Sat, 24 Dec 2022 09:01:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1671890500; bh=v4f/3Jk4Vi47WiyTHc8gNVY2xqU/iLXdCduk1PENXLs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=ddu1HGoLrv6EatDEL2kzISOi5FfdqluHz9AjRwDM1L3p92NLKqIJTSWTsHricXy0M haC+1ix5b4k3NOTL/JHQqR3ms6BS4gaauGvYfviSPfpZB+0TnfXxtcP2ZHG+NXyyKj PytQAwPbQb6jckB4jWTqOfixhjees7DjwFc4PL/9zjQMT28muGDqFMThf6GF8Ufs+a W/jZh1j0iQa7y8Gbac9ks7D4zgDz98edB04RPTnS4Ib2Dh3apvaBVrv5lQ/9Dj4Yib 7A4+YP7oTL71Z5S16PnKnouWXYbtErlmp++cX8oKf2ppKpLt0E9Oh0+39u0c+BTHqi 7ZJNL2GxZ0ErA== Original-Received: from pastel (unknown [45.72.200.228]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A71B01209A9; Sat, 24 Dec 2022 09:01:39 -0500 (EST) In-Reply-To: <87pmckz8p0.fsf@thornhill.no> (Theodor Thornhill's message of "Thu, 15 Dec 2022 21:57:31 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:301838 Archived-At: > -(eval-when-compile (require 'cl-lib)) > +(eval-when-compile (require 'cl-lib) > + (require 'treesit)) I don't see any part of `treesit` used during compilation. Is it a left over, maybe? > @@ -8453,36 +8455,37 @@ transpose-sexps > (transpose-sexps arg nil) > (scan-error (user-error "Not between two complete sexps"))) > (transpose-subr > - (lambda (arg) > - ;; Here we should try to simulate the behavior of > - ;; (cons (progn (forward-sexp x) (point)) > - ;; (progn (forward-sexp (- x)) (point))) > - ;; Except that we don't want to rely on the second forward-sexp > - ;; putting us back to where we want to be, since forward-sexp-function > - ;; might do funny things like infix-precedence. > - (if (if (> arg 0) > - (looking-at "\\sw\\|\\s_") > - (and (not (bobp)) > - (save-excursion > - (forward-char -1) > - (looking-at "\\sw\\|\\s_")))) > - ;; Jumping over a symbol. We might be inside it, mind you. > - (progn (funcall (if (> arg 0) > - 'skip-syntax-backward 'skip-syntax-forward) > - "w_") > - (cons (save-excursion (forward-sexp arg) (point)) (point))) > - ;; Otherwise, we're between sexps. Take a step back before jumping > - ;; to make sure we'll obey the same precedence no matter which > - ;; direction we're going. > - (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-forward) > - " .") > - (cons (save-excursion (forward-sexp arg) (point)) > - (progn (while (or (forward-comment (if (> arg 0) 1 -1)) > - (not (zerop (funcall (if (> arg 0) > - 'skip-syntax-forward > - 'skip-syntax-backward) > - "."))))) > - (point))))) > + (if (treesit-parser-list) #'treesit-transpose-sexps > + (lambda (arg) > + ;; Here we should try to simulate the behavior of > + ;; (cons (progn (forward-sexp x) (point)) > + ;; (progn (forward-sexp (- x)) (point))) > + ;; Except that we don't want to rely on the second forward-sexp > + ;; putting us back to where we want to be, since forward-sexp-function > + ;; might do funny things like infix-precedence. > + (if (if (> arg 0) > + (looking-at "\\sw\\|\\s_") > + (and (not (bobp)) > + (save-excursion > + (forward-char -1) > + (looking-at "\\sw\\|\\s_")))) > + ;; Jumping over a symbol. We might be inside it, mind you. > + (progn (funcall (if (> arg 0) > + 'skip-syntax-backward 'skip-syntax-forward) > + "w_") > + (cons (save-excursion (forward-sexp arg) (point)) (point))) > + ;; Otherwise, we're between sexps. Take a step back before jumping > + ;; to make sure we'll obey the same precedence no matter which > + ;; direction we're going. > + (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-forward) > + " .") > + (cons (save-excursion (forward-sexp arg) (point)) > + (progn (while (or (forward-comment (if (> arg 0) 1 -1)) > + (not (zerop (funcall (if (> arg 0) > + 'skip-syntax-forward > + 'skip-syntax-backward) > + "."))))) > + (point)))))) > arg 'special))) Could we use a `transpose-sexp-function` variable, which `treesit` can then set, so `simple.el` doesn't need to know about `treesit` at all? > (defun transpose-lines (arg) > @@ -8521,6 +8524,9 @@ transpose-subr > (progn (funcall mover (- x)) (point)))))) > pos1 pos2) > (cond > + ((treesit-parser-list) > + (cl-multiple-value-bind (p1 p2) (funcall aux arg) > + (transpose-subr-1 p1 p2))) > ((= arg 0) > (save-excursion > (setq pos1 (funcall aux 1)) Please use `pcase-let` instead of `cl-multiple-value-bind` (especially since you use it to decompose something built with `list` rather than with `cl-values`). Also to avid re-testing `treesit-parser-list`, I'd recommend you extend the semantics of `mover` so it can either return a position (the old protocol) or directly return a pair of positions. You could even add a 3rd kind of return value to explicitly trigger the error message instead of relying on the (cons 0 1) hack. Stefan