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: Tue, 11 Jul 2023 14:15:35 -0400 Message-ID: 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="27828"; mail-complaints-to="usenet@ciao.gmane.io" To: 64574@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 11 20:16:23 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 1qJHuR-000739-EL for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 11 Jul 2023 20:16:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJHu9-0005tQ-3J; Tue, 11 Jul 2023 14:16:05 -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 1qJHu6-0005qD-M4 for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2023 14:16: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 1qJHu6-0000Kh-E8 for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2023 14:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qJHu6-00072g-9s for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2023 14:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Jul 2023 18:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64574 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168909934727041 (code B ref -1); Tue, 11 Jul 2023 18:16:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Jul 2023 18:15:47 +0000 Original-Received: from localhost ([127.0.0.1]:51025 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJHtq-000724-PP for submit@debbugs.gnu.org; Tue, 11 Jul 2023 14:15:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:44814) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJHto-00071w-5h for submit@debbugs.gnu.org; Tue, 11 Jul 2023 14:15:45 -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 1qJHtm-0005os-2B for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2023 14:15:44 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJHth-0000H1-KL for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2023 14:15:41 -0400 Received-SPF: pass client-ip=64.215.233.18; envelope-from=sbaugh@janestreet.com; helo=mxout5.mail.janestreet.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H5=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: 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:264936 Archived-At: --=-=-= Content-Type: text/plain Tags: patch 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. In GNU Emacs 29.0.92 (build 5, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2023-07-10 built on igm-qws-u22796a Repository revision: dd15432ffacbeff0291381c0109f5b1245060b1d Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: CentOS Linux 7 (Core) Configured using: 'configure --config-cache --with-x-toolkit=lucid --with-gif=ifavailable' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Support-not-jumping-to-bol-in-beginning-of-defun.patch >From 12c4f80e046c3c6dd6996e13f332d0eb41d1f1dd 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 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. * lisp/emacs-lisp/lisp.el (beginning-of-defun-go-beginning-of-line): Add variable. (beginning-of-defun): Check variable. --- lisp/emacs-lisp/lisp.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index b91d56cfb4f..70c296b2c31 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -335,6 +335,18 @@ kill-backward-up-list (insert current-sexp)) (user-error "Not at a sexp")))) +(defvar beginning-of-defun-go-beginning-of-line t + "If non-nil, `beginning-of-defun' runs `beginning-of-line' at the end. + +By default, `beginning-of-defun' jumps to the beginning of the +line with `beginning-of-line' after finding the start of the +defun. + +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.") + (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 @@ -376,7 +388,9 @@ 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-beginning-of-line + (beginning-of-line)) + t))) (defun beginning-of-defun-raw (&optional arg) "Move point to the character that starts a defun. -- 2.39.3 --=-=-=--