From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Plug treesit.el into other emacs constructs Date: Sat, 24 Dec 2022 15:15:40 +0100 Message-ID: <5DF07C4E-2CCD-4561-AFFB-D5D81D67BFE0@thornhill.no> 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; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12759"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , emacs-devel@gnu.org, eliz@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 24 15:16:31 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 1p95KA-000395-QS for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Dec 2022 15:16:31 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p95JZ-0005Cg-6K; Sat, 24 Dec 2022 09:15:53 -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 1p95JV-0005C7-Pa for emacs-devel@gnu.org; Sat, 24 Dec 2022 09:15:50 -0500 Original-Received: from out2.migadu.com ([2001:41d0:2:aacc::]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p95JS-0003DR-Ni; Sat, 24 Dec 2022 09:15:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1671891343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I8Ou9Lq1dhPd11HaB/0fnylKhlybsnGD+Ji5GLTV888=; b=ob4xNuBJENMf02U09BtglAw0eLa41897ZXkMs5eEDCBQa5x949rCl581hfoJ+OLmBtYfyf 7yeIb2WAjXhUyl+p8a2HipUq0NffeiRCRCX0h5wVxWK5hzD8eCOcXn036I4/vJfs7zS7P1 vTVXZKk7AAcGW5Cj1kMGkqoM+o0UfC1N5Va8Mms90xrQPlDrdQAfuDYaTXtOVwCCrc2r3Z RUBj3UVOFy2/jf5pD4ljU5We+hreJsH7h6p1zElx9Z4QmoAoHnhEazV3A2qsB3q+eNBomK a0G2mLB+GVCFpW3liyIhq5BTd2C+j7vJmsIlEOqwtvbaK8gP5swP4HwQYD0Kbw== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-Reply-To: X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:2:aacc::; envelope-from=theo@thornhill.no; helo=out2.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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:301840 Archived-At: On 24 December 2022 15:01:36 CET, Stefan Monnier wrote: >> -(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=2E >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-f= unction >> - ;; might do funny things like infix-precedence=2E >> - (if (if (> arg 0) >> - (looking-at "\\sw\\|\\s_") >> - (and (not (bobp)) >> - (save-excursion >> - (forward-char -1) >> - (looking-at "\\sw\\|\\s_")))) >> - ;; Jumping over a symbol=2E We might be inside it, mind you=2E >> - (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=2E Take a step back before= jumping >> - ;; to make sure we'll obey the same precedence no matter whic= h >> - ;; direction we're going=2E >> - (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-for= ward) >> - " =2E") >> - (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) >> - "=2E"))))) >> - (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-se= xp >> + ;; putting us back to where we want to be, since forward-sexp= -function >> + ;; might do funny things like infix-precedence=2E >> + (if (if (> arg 0) >> + (looking-at "\\sw\\|\\s_") >> + (and (not (bobp)) >> + (save-excursion >> + (forward-char -1) >> + (looking-at "\\sw\\|\\s_")))) >> + ;; Jumping over a symbol=2E We might be inside it, mind = you=2E >> + (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=2E Take a step back befo= re jumping >> + ;; to make sure we'll obey the same precedence no matter wh= ich >> + ;; direction we're going=2E >> + (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-f= orward) >> + " =2E") >> + (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) >> + "=2E"))))) >> + (point)))))) >> arg 'special))) > >Could we use a `transpose-sexp-function` variable, which `treesit` can >then set, so `simple=2Eel` doesn't need to know about `treesit` at all? > Yes absolutely! I'll make that change=2E It makes sense, because we need n= ot really rely on forward-foo anyways:) >> (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))) >> ((=3D 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`)=2E > >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=2E 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=2E > > > Stefan > Yeah! I believe this either wasn't the latest patch, or i forgot to send i= t=2E I'll see what lies around my system and wrap things up=2E