unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Don't move to eol in end-of-defun?
@ 2022-07-27 12:40 Filipp Gunbin
  2022-07-30 23:40 ` Daniel Martín
  2022-08-03  3:46 ` Richard Stallman
  0 siblings, 2 replies; 14+ messages in thread
From: Filipp Gunbin @ 2022-07-27 12:40 UTC (permalink / raw)
  To: emacs-devel

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.  But end-of-defun
first calls (end-of-line 1), before doing everything else, and so my
function finds itself at <2>!  And moves to <3>.

OTOH, end-of-defun is documented to move to "next end of defun", and one
could say that moving from <1> to <3> is just that.  I can agree, but
then I get strange behavior of narrow-to-defun, mark-defun and others,
because they rely on beginning / end of defun.

I can suggest this patch, but I don't very much like it.

Thoughts?

TIA
Filipp


diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 4b85414943..cc8185e453 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -507,6 +507,13 @@ end-of-defun-function
 So the function can assume that point is at the beginning of the defun body.
 It should move point to the first position after the defun.")
 
+(defvar end-of-defun-moves-to-eol t
+  "Defines whether `end-of-defun' moves to eol before doing
+everything else.
+
+Set this to nil in major mode if this movement affects mode's
+decisions about context in an unwanted way.")
+
 (defun buffer-end (arg)
   "Return the \"far end\" position of the buffer, in direction ARG.
 If ARG is positive, that's the end of the buffer.
@@ -538,7 +545,9 @@ end-of-defun
         (push-mark))
     (if (or (null arg) (= arg 0)) (setq arg 1))
     (let ((pos (point))
-          (beg (progn (end-of-line 1) (beginning-of-defun-raw 1) (point)))
+          (beg (progn (when end-of-defun-moves-to-eol
+                        (end-of-line 1))
+                      (beginning-of-defun-raw 1) (point)))
 	  (skip (lambda ()
 		  ;; When comparing point against pos, we want to consider that
 		  ;; if point was right after the end of the function, it's



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-08-08 14:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 12:40 Don't move to eol in end-of-defun? Filipp Gunbin
2022-07-30 23:40 ` Daniel Martín
2022-07-31 22:31   ` Filipp Gunbin
2022-08-01 17:50     ` Alan Mackenzie
2022-08-01 20:49       ` Filipp Gunbin
2022-08-01 22:01       ` Filipp Gunbin
2022-08-03  3:46 ` Richard Stallman
2022-08-03 12:37   ` Filipp Gunbin
2022-08-04  4:04     ` Richard Stallman
2022-08-04 14:58       ` Filipp Gunbin
2022-08-06  3:41         ` Richard Stallman
2022-08-06  9:33           ` Alan Mackenzie
2022-08-07  4:24             ` Richard Stallman
2022-08-08 14:29               ` Filipp Gunbin

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).