[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Plug treesit.el into other emacs constructs
From: |
Theodor Thornhill |
Subject: |
Plug treesit.el into other emacs constructs |
Date: |
Mon, 12 Dec 2022 15:33:33 +0100 |
Hello!
I've started plugging tree-sitter support into other constructs in
emacs, and I would love some feedback and suggestions for how to
proceed. Emacs has some nice utilities we could piggyback on, namely:
- forward-sexp
- forward-sentence
- forward-*
What they provide is suddenly access to all of the transpose-*
functions. I'll show with some examples, where | denotes point, and if
there are two | it denotes active region, like this: |String foo|.
The patch supplied below enables the following:
* Navigation:
** Forward-sentence:
Executing M-e repeatedly will go from:
```
public void foo() {
|int x = 5;
int x = 6;
}
```
to
```
public void foo() {
int x = 5;|
int x = 6;
}
```
then
```
public void foo() {
int x = 5;
int x = 6;|
}
```
** transpose-sentence:
Executing M-x transpose-sentence repeatedly will go from:
```
public void foo() {
int x = 5;|
if (r) {
}
int x = 6;
}
```
to
```
public void foo() {
if (r) {
}
int x = 5;|
int x = 6;
}
```
then
```
public void foo() {
if (r) {
}
int x = 6;
int x = 5;|
}
```
Further transpose-sentence will not go out of the method because there
are no siblings
** kill-sentence:
Executing M-k repeatedly will go from:
```
public void foo() {
|int x = 6;
if (foo) {
}
}
```
to
```
public void foo() {
|
if (foo) {
}
}
```
then
```
public void foo() {
|
}
```
** Forward-sexp:
Executing C-M-f repeatedly will go from:
```
public void foo(|String bar, String baz) {}
```
to
```
public void foo(String bar|, String baz) {}
```
and
```
public void foo(String bar, String baz|) {}
```
** Mark-sexp:
Executing C-M-@ repeatedly will go from:
```
public void foo(|String bar, String baz) {}
```
to
```
public void foo(|String bar|, String baz) {}
```
then
```
public void foo(|String bar, String baz|) {}
```
** transpose-sexp:
Executing C-M-t repeatedly will go from:
```
public void foo(int bar,| String baz) {}
```
to
```
public void foo(String baz, int bar|) {}
```
** kill-sexp:
Executing C-M-k repeatedly will go from:
```
public void foo(|int bar, String baz) {}
```
to
```
public void foo(|, int bar) {}
```
then
```
public void foo() {}
```
And more.
The patch only adds a few things:
- (defvar-local forward-sentence-function nil), the analog to
forward-sexp-function and beginning-of-defun-function
- treesit-sexp-type-regexp and treesit-sentence-type-regexp, both to be
added to treesit-major-mode-setup, and added to each *-ts-mode.
Is the general idea ok? Could we add these or similar changes to
paragraphs.el and just piggyback on it inside of treesit?
If we want this I can start working on preparing a patch for this on the
master branch.
Theo
0001-WIP-forward-implementation.patch
Description: Text Data
- Plug treesit.el into other emacs constructs,
Theodor Thornhill <=
- Re: Plug treesit.el into other emacs constructs, Eli Zaretskii, 2022/12/12
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/12
- Re: Plug treesit.el into other emacs constructs, Theodor Thornhill, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Yuan Fu, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Perry Smith, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Stefan Monnier, 2022/12/13
- Re: Plug treesit.el into other emacs constructs, Yuan Fu, 2022/12/14
- Re: Plug treesit.el into other emacs constructs, Theodor Thornhill, 2022/12/14