From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#64574: [PATCH] Support not jumping to bol in beginning-of-defun Date: Wed, 12 Jul 2023 10:57:50 -0400 Message-ID: References: <83edle704t.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39649"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 64574@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jul 12 16:58:22 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qJbIK-000A2F-AV for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Jul 2023 16:58:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJbI4-0007cp-82; Wed, 12 Jul 2023 10:58:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJbI2-0007XK-Ov for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2023 10:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJbI2-0006xh-GD for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2023 10:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qJbI1-0001kA-S6 for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2023 10:58:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Jul 2023 14:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64574 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 64574-submit@debbugs.gnu.org id=B64574.16891738796694 (code B ref 64574); Wed, 12 Jul 2023 14:58:01 +0000 Original-Received: (at 64574) by debbugs.gnu.org; 12 Jul 2023 14:57:59 +0000 Original-Received: from localhost ([127.0.0.1]:52773 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJbHy-0001jt-Lj for submit@debbugs.gnu.org; Wed, 12 Jul 2023 10:57:59 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:40763) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJbHv-0001jc-VB for 64574@debbugs.gnu.org; Wed, 12 Jul 2023 10:57:56 -0400 In-Reply-To: <83edle704t.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 11 Jul 2023 21:50:58 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:264968 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Spencer Baugh >> Date: Tue, 11 Jul 2023 14:15:35 -0400 >> >> As mentioned in the commit, this default behavior by >> beginning-of-defun is undesirable in some languages and major modes. >> I'm thinking of OCaml in particular here, but it's also arguably >> unwanted in Python and C++ as well, where defs may be indented inside >> class definitions. Let's let users and major modes make this decision >> on a case-by-case basis. > > Such optional behavior is fine by me, but is there any evidence enough > people will want it? Can you gather some feedback about that? Users at my site have expressed a preference for this (including me, once I thought about it enough to realize I don't like the default behavior). And Jim Porter just mentioned that they would prefer this too. >> +(defvar beginning-of-defun-go-beginning-of-line t > > Why not defcustom? > > And I would use a shorter name, like beginning-of-defun-go-bol. Can do. >> + "If non-nil, `beginning-of-defun' runs `beginning-of-line' at the end. > > This describes implementation, not the behavior. It also assumes > everyone knows what exactly beginning-of-line does (think RTL text). > >> +By default, `beginning-of-defun' jumps to the beginning of the >> +line with `beginning-of-line' after finding the start of the >> +defun. > > I see no reason to tell in the doc string how exactly the function > goes to BOL. It can even be a problem if at some future point we > decide to change the implementation. Can do. >> +For languages where defuns may be indented inside nested >> +structures like classes or modules, this behavior may be >> +undesirable. Major modes for such languages can set this >> +variable to nil to avoid it.") > > Not sure we should leave this to major modes and not to the individual > users. > > Thanks. Sure, I'm fine with having it be a defcustom that users can set. Revised patch: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Support-not-jumping-to-bol-in-beginning-of-defun.patch >From be03d6e994303c3f32d676194f6f31e89917013e Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Tue, 11 Jul 2023 14:14:34 -0400 Subject: [PATCH] Support not jumping to bol in beginning-of-defun As mentioned in the commit, this default behavior by beginning-of-defun may be undesirable in some languages and major modes. I'm thinking of OCaml in particular here, but it's also arguably unwanted in Python and C++ as well, where defs may be indented inside class definitions. Let's let the user make this decision. * lisp/emacs-lisp/lisp.el (beginning-of-defun-go-bol): Add defcustom. (beginning-of-defun): Check beginning-of-defun-go-bol. --- lisp/emacs-lisp/lisp.el | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index b91d56cfb4f..e5b024b19a6 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -335,6 +335,17 @@ kill-backward-up-list (insert current-sexp)) (user-error "Not at a sexp")))) +(defcustom beginning-of-defun-go-bol t + "If non-nil, `beginning-of-defun' moves to beginning of line. + +By default, `beginning-of-defun' point moves to the beginning of +the line where a defun starts. For languages where defuns may be +indented inside nested structures like classes or modules, this +behavior may be undesirable." + :type '(choice (const :tag "Don't go to BOL in beginning-of-defun" nil) + (const :tag "Go to BOL in beginning-of-defun" t)) + :group 'lisp) + (defvar beginning-of-defun-function nil "If non-nil, function for `beginning-of-defun-raw' to call. This is used to find the beginning of the defun instead of using the @@ -367,16 +378,17 @@ beginning-of-defun value is called as a function, with argument ARG, to find the defun's beginning. -Regardless of the values of `defun-prompt-regexp' and -`beginning-of-defun-function', point always moves to the -beginning of the line whenever the search is successful." +If `beginning-of-defun-go-bol' is non-nil, point moves to the +beginning of the line if the search is successful." (interactive "^p") (or (not (eq this-command 'beginning-of-defun)) (eq last-command 'beginning-of-defun) (and transient-mark-mode mark-active) (push-mark)) (and (beginning-of-defun-raw arg) - (progn (beginning-of-line) t))) + (progn (when beginning-of-defun-go-bol + (beginning-of-line)) + t))) (defun beginning-of-defun-raw (&optional arg) "Move point to the character that starts a defun. -- 2.39.3 --=-=-=--