From: Theodor Thornhill <theo@thornhill.no>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Yuan Fu <casouri@gmail.com>, emacs-devel@gnu.org, eliz@gnu.org
Subject: Re: Plug treesit.el into other emacs constructs
Date: Sat, 24 Dec 2022 15:15:40 +0100 [thread overview]
Message-ID: <5DF07C4E-2CCD-4561-AFFB-D5D81D67BFE0@thornhill.no> (raw)
In-Reply-To: <jwvedsogbo3.fsf-monnier+emacs@gnu.org>
On 24 December 2022 15:01:36 CET, Stefan Monnier <monnier@iro.umontreal.ca> 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.
>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?
>
Yes absolutely! I'll make that change. It makes sense, because we need not 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)))
>> ((= 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
>
Yeah! I believe this either wasn't the latest patch, or i forgot to send it. I'll see what lies around my system and wrap things up.
next prev parent reply other threads:[~2022-12-24 14:15 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 14:33 Plug treesit.el into other emacs constructs Theodor Thornhill
2022-12-12 14:45 ` Eli Zaretskii
2022-12-13 18:17 ` Theodor Thornhill
2022-12-12 15:46 ` Stefan Monnier
2022-12-13 18:27 ` Theodor Thornhill
2022-12-13 19:37 ` Stefan Monnier
2022-12-13 19:53 ` Yuan Fu
2022-12-13 20:06 ` Perry Smith
2022-12-13 23:19 ` Stefan Monnier
2022-12-14 8:14 ` Yuan Fu
2022-12-14 8:42 ` Theodor Thornhill
2022-12-14 14:01 ` Stefan Monnier
2022-12-14 16:24 ` Theodor Thornhill
2022-12-14 17:46 ` Stefan Monnier
2022-12-14 18:07 ` Theodor Thornhill
2022-12-14 19:25 ` Stefan Monnier
2022-12-14 19:35 ` Stefan Monnier
2022-12-14 20:04 ` Theodor Thornhill
2022-12-14 20:50 ` Stefan Monnier
2022-12-14 21:15 ` Theodor Thornhill
2022-12-14 21:34 ` Stefan Monnier
2022-12-15 19:37 ` Theodor Thornhill
2022-12-15 19:56 ` Stefan Monnier
2022-12-15 20:03 ` Theodor Thornhill
2022-12-15 20:33 ` Theodor Thornhill
2022-12-15 20:57 ` Theodor Thornhill
2022-12-24 7:00 ` Eli Zaretskii
2022-12-24 8:44 ` Yuan Fu
2022-12-24 14:01 ` Stefan Monnier
2022-12-24 14:15 ` Theodor Thornhill [this message]
2022-12-26 19:11 ` Theodor Thornhill
2022-12-26 22:46 ` Stefan Monnier
2022-12-26 22:51 ` Stefan Monnier
2022-12-27 22:15 ` Theodor Thornhill via Emacs development discussions.
2022-12-28 0:12 ` Stefan Monnier
2022-12-28 9:26 ` Theodor Thornhill via Emacs development discussions.
2022-12-28 18:01 ` Stefan Monnier
2022-12-28 18:27 ` Theodor Thornhill
2022-12-26 22:56 ` Theodor Thornhill
2022-12-27 15:46 ` Lynn Winebarger
2022-12-14 23:31 ` Yuan Fu
2022-12-15 0:05 ` Yuan Fu
2022-12-15 7:09 ` Eli Zaretskii
2022-12-15 7:14 ` Theodor Thornhill
2022-12-15 4:37 ` Stefan Monnier
2022-12-15 5:59 ` Theodor Thornhill
2022-12-15 21:23 ` Yuan Fu
2022-12-15 21:28 ` Theodor Thornhill
2022-12-13 20:02 ` Theodor Thornhill
2022-12-13 23:10 ` Stefan Monnier
2022-12-14 23:32 ` Stephen Leake
2022-12-16 10:02 ` Kévin Le Gouguec
2022-12-16 11:54 ` [SPAM UNSURE] " Stephen Leake
2022-12-17 15:30 ` Kévin Le Gouguec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5DF07C4E-2CCD-4561-AFFB-D5D81D67BFE0@thornhill.no \
--to=theo@thornhill.no \
--cc=casouri@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).