* How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
@ 2021-09-27 20:53 Pierre Rouleau
2021-09-27 21:13 ` Nikolay Kudryavtsev
2021-09-27 21:14 ` Thibaut Verron
0 siblings, 2 replies; 9+ messages in thread
From: Pierre Rouleau @ 2021-09-27 20:53 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I am trying to find an easy and efficient way to modify the behaviour of
`forward-sexp` to handle
balanced pairs of characters not normally supported by it, such as balanced
`<` and `>` and
balanced `<<` and `>>`.
My specific case is to enhance the support of Erlang but I believe it could
apply to a lot of scenarios.
The implementation of `forward-sexp` allows the use of a
`forward-sexp-function` which means I
could implement such a function.
However I was hoping to find a variable that the C-implemented `scan-sexp`
could use to define
the matching pair but have not succeeded so far.
It would seem the easiest and most efficient way of implementing such
handling of balanced pairs
would be done there.
I also tried to modify the syntax table the erlang-mode uses but although
it matches all sorts of
Unicode character pairs, I can't get forward-sexp to work with ?< and ?>.
Is there a variable one can use to augment or modify the behaviour of
`scan-sexp`?
Or is forward-sexp meant to be limited to lisp-like syntaxes and I have to
use another method
(like SMIE or writing my own forward-sexp-function)?
Thanks!
--
/Pierre
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-27 20:53 How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others? Pierre Rouleau
@ 2021-09-27 21:13 ` Nikolay Kudryavtsev
2021-09-27 21:17 ` Pierre Rouleau
2021-09-27 21:14 ` Thibaut Verron
1 sibling, 1 reply; 9+ messages in thread
From: Nikolay Kudryavtsev @ 2021-09-27 21:13 UTC (permalink / raw)
To: Pierre Rouleau, help-gnu-emacs
Have you tried smartparens? It provides it's own implementation of
forward-sexp for most of such cases, so maybe it's exactly what you're
looking for.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-27 20:53 How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others? Pierre Rouleau
2021-09-27 21:13 ` Nikolay Kudryavtsev
@ 2021-09-27 21:14 ` Thibaut Verron
2021-09-27 21:22 ` Pierre Rouleau
1 sibling, 1 reply; 9+ messages in thread
From: Thibaut Verron @ 2021-09-27 21:14 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: help-gnu-emacs
Hi,
Adding the characters to the syntax table is the canonical answer.
Maybe erlang-mode sets forward-sexp-function? This is typically done
to enhance the sexp movement beyond simple parentheses, for instance
for modes using SMIE.
If you (setq forward-sexp-function nil), does forward-sexp do what you want?
Best wishes,
Thibaut
Le lun. 27 sept. 2021 à 22:54, Pierre Rouleau <prouleau001@gmail.com> a écrit :
>
> Hi,
>
> I am trying to find an easy and efficient way to modify the behaviour of
> `forward-sexp` to handle
> balanced pairs of characters not normally supported by it, such as balanced
> `<` and `>` and
> balanced `<<` and `>>`.
>
> My specific case is to enhance the support of Erlang but I believe it could
> apply to a lot of scenarios.
>
> The implementation of `forward-sexp` allows the use of a
> `forward-sexp-function` which means I
> could implement such a function.
>
> However I was hoping to find a variable that the C-implemented `scan-sexp`
> could use to define
> the matching pair but have not succeeded so far.
> It would seem the easiest and most efficient way of implementing such
> handling of balanced pairs
> would be done there.
>
> I also tried to modify the syntax table the erlang-mode uses but although
> it matches all sorts of
> Unicode character pairs, I can't get forward-sexp to work with ?< and ?>.
>
> Is there a variable one can use to augment or modify the behaviour of
> `scan-sexp`?
>
> Or is forward-sexp meant to be limited to lisp-like syntaxes and I have to
> use another method
> (like SMIE or writing my own forward-sexp-function)?
>
> Thanks!
> --
> /Pierre
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-27 21:13 ` Nikolay Kudryavtsev
@ 2021-09-27 21:17 ` Pierre Rouleau
0 siblings, 0 replies; 9+ messages in thread
From: Pierre Rouleau @ 2021-09-27 21:17 UTC (permalink / raw)
To: Nikolay Kudryavtsev; +Cc: help-gnu-emacs
I have tried smartparens. I was able to add support for << and >> pairs
but it still does not work as I'd wish for. And besides, I am curious to
get the normal forward-sexp working because that would unlock a large set
of functionality.
On Mon, Sep 27, 2021 at 5:13 PM Nikolay Kudryavtsev <
nikolay.kudryavtsev@gmail.com> wrote:
> Have you tried smartparens? It provides it's own implementation of
> forward-sexp for most of such cases, so maybe it's exactly what you're
> looking for.
>
>
--
/Pierre
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-27 21:14 ` Thibaut Verron
@ 2021-09-27 21:22 ` Pierre Rouleau
2021-09-27 21:34 ` Thibaut Verron
0 siblings, 1 reply; 9+ messages in thread
From: Pierre Rouleau @ 2021-09-27 21:22 UTC (permalink / raw)
To: thibaut.verron; +Cc: help-gnu-emacs
On Mon, Sep 27, 2021 at 5:14 PM Thibaut Verron <thibaut.verron@gmail.com>
wrote:
> Hi,
>
> Adding the characters to the syntax table is the canonical answer.
> Maybe erlang-mode sets forward-sexp-function? This is typically done
> to enhance the sexp movement beyond simple parentheses, for instance
> for modes using SMIE.
>
> If you (setq forward-sexp-function nil), does forward-sexp do what you
> want?
>
>
In erlang-mode forward-sexp-function is already nil and forward-sexp does
not
deal with ?< and ?> as a matching pair then.
I tried to modify the syntax table but that did not work either.
At the moment I'm trying to write a function that I will provide as the
forward-sexp-function to do the job.
Really I would think would have been to modify the syntax table to get
scan-sexps to
do the job. Perhaps something inside erlang.el /erlang-mode gets in the
way,
but I have not fully studied its code
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-27 21:22 ` Pierre Rouleau
@ 2021-09-27 21:34 ` Thibaut Verron
2021-09-27 21:48 ` Pierre Rouleau
0 siblings, 1 reply; 9+ messages in thread
From: Thibaut Verron @ 2021-09-27 21:34 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: help-gnu-emacs
Le lun. 27 sept. 2021 à 23:22, Pierre Rouleau <prouleau001@gmail.com> a écrit :
>
>
>
> On Mon, Sep 27, 2021 at 5:14 PM Thibaut Verron <thibaut.verron@gmail.com> wrote:
>>
>> Hi,
>>
>> Adding the characters to the syntax table is the canonical answer.
>> Maybe erlang-mode sets forward-sexp-function? This is typically done
>> to enhance the sexp movement beyond simple parentheses, for instance
>> for modes using SMIE.
>>
>> If you (setq forward-sexp-function nil), does forward-sexp do what you want?
>>
>
> In erlang-mode forward-sexp-function is already nil and forward-sexp does not
> deal with ?< and ?> as a matching pair then.
> I tried to modify the syntax table but that did not work either.
How are you modifying the syntax table? Directly in the source code of
the erlang mode, or in your user configuration?
If it's in the source code, maybe there is a compiled .elc file which
shadows your modifications?
If it's in your user configuration, you have to make sure that you
define the new syntax table before loading the major-mode. If
erlang.el defines the syntax table with a defvar, it won't change the
variable if already set. But it's important that the
define-derived-mode form gets evaluated with the new syntax table.
> Really I would think would have been to modify the syntax table to get scan-sexps to
> do the job.
Yes that should be the case.
Best wishes,
Thibaut
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-27 21:34 ` Thibaut Verron
@ 2021-09-27 21:48 ` Pierre Rouleau
2021-09-28 3:45 ` Thibaut Verron
0 siblings, 1 reply; 9+ messages in thread
From: Pierre Rouleau @ 2021-09-27 21:48 UTC (permalink / raw)
To: thibaut.verron; +Cc: help-gnu-emacs
On Mon, Sep 27, 2021 at 5:34 PM Thibaut Verron <thibaut.verron@gmail.com>
wrote:
> Le lun. 27 sept. 2021 à 23:22, Pierre Rouleau <prouleau001@gmail.com> a
> écrit :
>
> > On Mon, Sep 27, 2021 at 5:14 PM Thibaut Verron <thibaut.verron@gmail.com>
> wrote:
> >>
>
> How are you modifying the syntax table? Directly in the source code of
> the erlang mode, or in your user configuration?
>
> For investigation purpose I modified the erlang.el file directly and then
byte compiled it,
ensuring that my modifications are taken by adding a special variable I can
check.
I modified the code inside the function
`erlang-ensure-syntax-table-is-initialized' which
dynamically modifies the syntax table because the initial variable sets it
to nil.
I commented out the lines that identified ?< and ?> as "." and added after
the following 2 lines:
(modify-syntax-entry ?< "(>" table)
(modify-syntax-entry ?> "(<" table)
After byte-compiling I start a new Emacs instance and open a .erl file
which uses the erlang-mode.
Then I check if the syntax table is what I think it should be by executing
describe-syntax.
--
/Pierre
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-27 21:48 ` Pierre Rouleau
@ 2021-09-28 3:45 ` Thibaut Verron
2021-09-28 11:22 ` Pierre Rouleau
0 siblings, 1 reply; 9+ messages in thread
From: Thibaut Verron @ 2021-09-28 3:45 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: help-gnu-emacs
On Mon, 27 Sep 2021, 23:48 Pierre Rouleau, <prouleau001@gmail.com> wrote:
>
>
> On Mon, Sep 27, 2021 at 5:34 PM Thibaut Verron <thibaut.verron@gmail.com>
> wrote:
>
>> Le lun. 27 sept. 2021 à 23:22, Pierre Rouleau <prouleau001@gmail.com> a
>> écrit :
>>
>> > On Mon, Sep 27, 2021 at 5:14 PM Thibaut Verron <
>> thibaut.verron@gmail.com> wrote:
>> >>
>>
>> How are you modifying the syntax table? Directly in the source code of
>> the erlang mode, or in your user configuration?
>>
>> For investigation purpose I modified the erlang.el file directly and then
> byte compiled it,
> ensuring that my modifications are taken by adding a special variable I
> can check.
>
That's a good approach, investigation purposes or not. If you want to
accelerate the feedback cycle, you don't even need to byte compile, just
delete the elc file (or tell emacs to always prefer a newer el over an elc,
there is a variable for that) and load the mode normally.
> I commented out the lines that identified ?< and ?> as "." and added after
> the following 2 lines:
>
> (modify-syntax-entry ?< "(>" table)
> (modify-syntax-entry ?> "(<" table)
>
There is a typo there, the second one should be )<.
Best wishes,
Thibaut
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others?
2021-09-28 3:45 ` Thibaut Verron
@ 2021-09-28 11:22 ` Pierre Rouleau
0 siblings, 0 replies; 9+ messages in thread
From: Pierre Rouleau @ 2021-09-28 11:22 UTC (permalink / raw)
To: thibaut.verron; +Cc: help-gnu-emacs
On Mon, Sep 27, 2021 at 11:45 PM Thibaut Verron <thibaut.verron@gmail.com>
wrote:
>
> On Mon, 27 Sep 2021, 23:48 Pierre Rouleau, <prouleau001@gmail.com> wrote:
>
>>
>>
>> On Mon, Sep 27, 2021 at 5:34 PM Thibaut Verron <thibaut.verron@gmail.com>
>> wrote:
>>
>>>
>>> How are you modifying the syntax table? Directly in the source code of
>>> the erlang mode, or in your user configuration?
>>>
>>>
>> I commented out the lines that identified ?< and ?> as "." and added
>> after
>> the following 2 lines:
>>
>> (modify-syntax-entry ?< "(>" table)
>> (modify-syntax-entry ?> "(<" table)
>>
>
> There is a typo there, the second one should be )<.
>
> Ahhhhh!!! That's it!! Thanks!!
--
/Pierre
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-09-28 11:22 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-27 20:53 How to make `forward-sexp` handle other balanced character-pairs such as < and > or << and >> in erlang-mode or others? Pierre Rouleau
2021-09-27 21:13 ` Nikolay Kudryavtsev
2021-09-27 21:17 ` Pierre Rouleau
2021-09-27 21:14 ` Thibaut Verron
2021-09-27 21:22 ` Pierre Rouleau
2021-09-27 21:34 ` Thibaut Verron
2021-09-27 21:48 ` Pierre Rouleau
2021-09-28 3:45 ` Thibaut Verron
2021-09-28 11:22 ` Pierre Rouleau
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.