From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Filipp Gunbin Newsgroups: gmane.emacs.devel Subject: Don't move to eol in end-of-defun? Date: Wed, 27 Jul 2022 15:40:57 +0300 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11014"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 27 14:42:53 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oGgNI-0002hj-Ag for ged-emacs-devel@m.gmane-mx.org; Wed, 27 Jul 2022 14:42:52 +0200 Original-Received: from localhost ([::1]:40180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGgNG-0003lb-Sf for ged-emacs-devel@m.gmane-mx.org; Wed, 27 Jul 2022 08:42:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGgLb-0002mC-2t for emacs-devel@gnu.org; Wed, 27 Jul 2022 08:41:07 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:57867) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGgLV-0001rP-Nc for emacs-devel@gnu.org; Wed, 27 Jul 2022 08:41:06 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 89CEC5C0189 for ; Wed, 27 Jul 2022 08:40:59 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 27 Jul 2022 08:40:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm3; t= 1658925659; x=1659012059; bh=pzIooPbRKRRqa4JIKFt4FvUPLewDrRRR17n vWd3yiAs=; b=U9q87awBC40lDSPioJpDlT1V04DbBBCfg+l5Rjvqb0QgAgj+KZt Uk6QAyEpPfzi/+a8DRbRHaTJGgFxrrNKZZWK5DDg5rmZccMCNX8MphblSlEThfxF MB35VwyptQ+XtgaVyuj1k3+Q/x4eN21FVvn7Bo1auCEGgK8fa6ZjN6zQ9Ta/FCXl IUOgv5fMp0iiFCVt3DCEfnVQgVFBnq3cgaQiN/V3tezNjs1vP/pNAWL88hv11oda bAzuwTZhBB8aokd6Tq4h0NKalldY2IYfN/U4fNWPqzUvPQpHOi7hi1gonCUL7AYT URyX/Ws3Fjpp5Be84bWimwa4GWAxUvfu3CA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1658925659; x= 1659012059; bh=pzIooPbRKRRqa4JIKFt4FvUPLewDrRRR17nvWd3yiAs=; b=l LmaA3l0FgJmvln4s1Sm98wfYSjxHB2wVd4SPgtyVRENivVG6l7k5u5uo+FnJ+GF3 8ZEyqqxCinnOlAvInsw8EexaFEKHEF/vvN0cH8fMFUfyuYke94qJPhNI8pXhLaRb 0CKp8QeMP0mDtjPqFJgeaBF9J5VxxUY2Z8p2blfjbkx9douOeFFs77bBH0IAscMS YXLMugMYOy5xDRkcwjpfpipImeurmL8PENvEV9VI3YgZ8hLCMbJ+Kg8pqZzmw87a qkbVFrTKH6dcDJ4qwi1XL2+0ycgPjvvTGLqsqYvhj5vaR/EscbQZ5dhOEvAlQBre wlM9wPYNMk4yFc5aPjMhg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdduvddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufgffkfggtgesthdtredttd ertdenucfhrhhomhephfhilhhiphhpucfiuhhnsghinhcuoehfghhunhgsihhnsehfrghs thhmrghilhdrfhhmqeenucggtffrrghtthgvrhhnpeetkefggfejudejkeevheduteffud ffjeeutdevveefueevgfeiieeuueelkeduudenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehfghhunhgsihhnsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: id48c41f1:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 27 Jul 2022 08:40:58 -0400 (EDT) Mail-Followup-To: emacs-devel@gnu.org Received-SPF: pass client-ip=66.111.4.25; envelope-from=fgunbin@fastmail.fm; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:292742 Archived-At: 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