emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Don't move to eol in end-of-defun?


From: Filipp Gunbin
Subject: Re: Don't move to eol in end-of-defun?
Date: Mon, 01 Aug 2022 23:49:47 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin)

Hello Alan,

On 01/08/2022 17:50 +0000, Alan Mackenzie wrote:

> Hello, Filipp.
>
> On Mon, Aug 01, 2022 at 01:31:28 +0300, Filipp Gunbin wrote:
>> On 31/07/2022 01:40 +0200, Daniel Martín wrote:
>
>> > Filipp Gunbin <fgunbin@fastmail.fm> writes:
>
>> >> In Java, it's a common style to have hanging parentheses:
>
>> >> class C <1>{<2>
>> >>   void foo() {
>> >>   }<3>
>> >> }<4>
>
>> >> If we're at position <1> and press C-M-e, then it's logical to move to
>> >> <4>, and that's what I implement in javaimp package, by defining my own
>> >> beginning-of-defun-function / end-of-defun-function.
>
> Be aware that end-of-defun-function is broken.  Before calling e-o-d-f,
> end-of-defun first moves point somewhere else and then calls it.  That
> somewhere else could easily be in a different function.  Say if you have
>
> class C <1>{ <2>void foo () {
>              }<3>
> }<4>
>
> and start at <1>, that somewhere else is likely to be <2> from where
> your e-o-d-f will probably go to <3>.

.. and that is exactly what I'm trying to prevent.

>> > If I yank your sample program in a buffer in Java mode, with point at
>> > <1>, C-M-e goes to <4>, as expected.  So I don´t know why you need to
>> > implement your own end-of-defun-function in your package.
>
>> I'd like to not rely on java-mode (part of cc-mode).
>
> Be further aware that in languages like Java, you can't do a fully
> accurate job without scanning braces back to BOB.  CC Mode has its own
> c-end-of-defun function, which uses a cache of brace blocks, for the
> reasons in this post (amongst others).  You're welcome to take stuff
> from it, if that might help.

Of course, I already do context parsing (via syntax-ppss), it's in
<elpa>/packages/javaimp/javaimp-parse.el.  That is, my code knows enough
about context.  I just need to prevent end-of-defun from messing with
position.

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]