From unknown Wed Jun 18 23:05:11 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#2379 <2379@debbugs.gnu.org> To: bug#2379 <2379@debbugs.gnu.org> Subject: Status: [PATCH?] lisp.el: beginning-of-defun Reply-To: bug#2379 <2379@debbugs.gnu.org> Date: Thu, 19 Jun 2025 06:05:11 +0000 retitle 2379 [PATCH?] lisp.el: beginning-of-defun reassign 2379 emacs submitter 2379 "Aaron S. Hawley" severity 2379 normal thanks From aaron.s.hawley@gmail.com Wed Feb 18 18:37:46 2009 Received: (at submit) by emacsbugs.donarmstrong.com; 19 Feb 2009 02:37:46 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=0.0 required=4.0 tests=MURPHY_DRUGS_REL8 autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n1J2bg9Q021174 for ; Wed, 18 Feb 2009 18:37:44 -0800 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LZynG-0005r9-I0 for bug-gnu-emacs@gnu.org; Wed, 18 Feb 2009 21:37:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LZynF-0005qx-QO for bug-gnu-emacs@gnu.org; Wed, 18 Feb 2009 21:37:41 -0500 Received: from [199.232.76.173] (port=35070 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LZynF-0005qu-KT for bug-gnu-emacs@gnu.org; Wed, 18 Feb 2009 21:37:41 -0500 Received: from yx-out-1718.google.com ([74.125.44.154]:18619) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LZynF-0002E3-6y for bug-gnu-emacs@gnu.org; Wed, 18 Feb 2009 21:37:41 -0500 Received: by yx-out-1718.google.com with SMTP id 34so88814yxf.66 for ; Wed, 18 Feb 2009 18:37:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=1ZwD/lO5umvoGnIu/dLB8mWaPOXqbdYC/Ik6cn8WAz8=; b=b8gDj/BFhkLa3mUoOskQx9CvQ4uiolH2o0fAACNoQyHyWtY7X6POkgOrUfH6jxkwV8 CRhKfDvZlPhQeZGa8we4jHHTlk+aBl02V2V9hVQdRpx6Xw+izurtmgBDWwR8XAuighaJ bvLDGvNvWtcu3sDhHA/7jhrXY8E0vqVExLK1c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=U+1iTJsqD/qFF5aWhfWLWrwa73wzm36hJ6R9gaq7HP/+5rkPKsc8YTrVFBu+W4Uzzi WozjjMJQDIXYBO2ETsSZepJqBlWyucY8VaiypYlo4mUKpmwOsELOOH1mJNP7DOA/lDEI gox1rJwGWEtQ0hNVr9rkLcQJ/rfyHL3+57Gog= MIME-Version: 1.0 Received: by 10.100.143.17 with SMTP id q17mr9321451and.29.1235011059716; Wed, 18 Feb 2009 18:37:39 -0800 (PST) Date: Wed, 18 Feb 2009 21:37:39 -0500 Message-ID: Subject: [PATCH?] lisp.el: beginning-of-defun From: "Aaron S. Hawley" To: bug-gnu-emacs@gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) There's some strange programming style in `beginning-of-defun-raw' for Emacs 22.2, perhaps this is what was meant by the use of this `progn' syntax? --- lisp.el 18 Feb 2009 20:56:29 -0500 1.79.2.3 +++ lisp.el 18 Feb 2009 21:07:49 -0500 @@ -234,7 +234,7 @@ "\\(?:" defun-prompt-regexp "\\)\\s(") "^\\s(") nil 'move arg) - (progn (goto-char (1- (match-end 0)))) t)) + (progn (goto-char (1- (match-end 0))) t))) ;; If open-paren-in-column-0-is-defun-start and defun-prompt-regexp ;; are both nil, column 0 has no significance - so scan forward If not, then this is what it probably should be: --- lisp.el 18 Feb 2009 20:56:29 -0500 1.79.2.3 +++ lisp.el 18 Feb 2009 21:10:21 -0500 @@ -234,7 +234,7 @@ "\\(?:" defun-prompt-regexp "\\)\\s(") "^\\s(") nil 'move arg) - (progn (goto-char (1- (match-end 0)))) t)) + (goto-char (1- (match-end 0))))) ;; If open-paren-in-column-0-is-defun-start and defun-prompt-regexp ;; are both nil, column 0 has no significance - so scan forward Then, once that is figured out, why doesn't `beginning-of-defun' manage zero arguments like many of the movement commands do? Running C-0 C-M-a seems to run `beginning-of-line' regardless. That's an easy fix with this patch: --- lisp.el 18 Feb 2009 20:56:29 -0500 1.79.2.3 +++ lisp.el 18 Feb 2009 21:25:05 -0500 @@ -204,7 +204,7 @@ (and transient-mark-mode mark-active) (push-mark)) (and (beginning-of-defun-raw arg) - (progn (beginning-of-line) t))) + (progn (if (and (integerp arg) (/= arg 0)) (beginning-of-line)) t))) (defun beginning-of-defun-raw (&optional arg) "Move point to the character that starts a defun. But then, `beginning-of-defun-raw' seems to run (forward-char -1). That requires this patch. --- lisp.el 18 Feb 2009 20:56:29 -0500 1.79.2.3 +++ lisp.el 18 Feb 2009 21:28:22 -0500 @@ -234,7 +234,7 @@ "\\(?:" defun-prompt-regexp "\\)\\s(") "^\\s(") nil 'move arg) - (progn (goto-char (1- (match-end 0)))) t)) + (progn (or (zerop arg) (goto-char (1- (match-end 0))))) t)) ;; If open-paren-in-column-0-is-defun-start and defun-prompt-regexp ;; are both nil, column 0 has no significance - so scan forward That's my best look at the situation. Support for a zero argument in these functions is important for situations where you want to be programmatic with `beginning-of-defun', Can this be fixed? Thanks, /a From monnier@iro.umontreal.ca Thu Feb 19 09:31:30 2009 Received: (at submit) by emacsbugs.donarmstrong.com; 19 Feb 2009 17:31:30 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-0.5 required=4.0 tests=HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,XIRONPORT autolearn=unavailable version=3.2.5-bugs.debian.org_2005_01_02 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n1JHVQJA029599 for ; Thu, 19 Feb 2009 09:31:27 -0800 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LaCk9-0001sv-OP for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 12:31:25 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LaCk9-0001si-28 for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 12:31:25 -0500 Received: from [199.232.76.173] (port=49520 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LaCk8-0001sc-QB for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 12:31:24 -0500 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:1303) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LaCk8-0003rR-HZ for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 12:31:24 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqQEAOclnUlMCpTK/2dsb2JhbACBbtFjhA4Ggz0 X-IronPort-AV: E=Sophos;i="4.38,236,1233550800"; d="scan'208";a="34094371" Received: from 76-10-148-202.dsl.teksavvy.com (HELO pastel.home) ([76.10.148.202]) by ironport2-out.teksavvy.com with ESMTP; 19 Feb 2009 12:31:23 -0500 Received: by pastel.home (Postfix, from userid 20848) id 3F84B4B488; Thu, 19 Feb 2009 12:31:22 -0500 (EST) From: Stefan Monnier To: "Aaron S. Hawley" Cc: 2379@debbugs.gnu.org, bug-gnu-emacs@gnu.org Subject: Re: bug#2379: [PATCH?] lisp.el: beginning-of-defun Message-ID: References: Date: Thu, 19 Feb 2009 12:31:22 -0500 In-Reply-To: (Aaron S. Hawley's message of "Wed, 18 Feb 2009 21:37:39 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. > There's some strange programming style in `beginning-of-defun-raw' for > Emacs 22.2, perhaps this is what was meant by the use of this `progn' > syntax? > - (progn (goto-char (1- (match-end 0)))) t)) > + (progn (goto-char (1- (match-end 0))) t))) I think that was the intention. Note that it turns out that the two forms are equivalent in this context (because goto-char never returns nil). > Then, once that is figured out, why doesn't `beginning-of-defun' > manage zero arguments like many of the movement commands do? I'd rather not touch its behavior for 0. Basically, it should never be called with a 0 argument (see below). > Support for a zero argument in these functions is important for > situations where you want to be programmatic with > `beginning-of-defun', Can this be fixed? AFAICT, proper support for 0 would require a serious rethink of BOD's semantics: currently if you're inside defun number N, then (BOD i) moves to (N-(i-1)) is i is positive and to (N-i) if i is negative. I.e. it moves to N if i=1 and to N+1 if i=-1, so where should 0 move to: there is no other defun between those two. Stefan From cyd@stupidchicken.com Thu Feb 19 17:44:48 2009 Received: (at control) by emacsbugs.donarmstrong.com; 20 Feb 2009 01:44:48 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=0.0 required=4.0 tests=none autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02 Received: from cyd.mit.edu (CYD.MIT.EDU [18.115.2.24]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n1K1ijbL015247 for ; Thu, 19 Feb 2009 17:44:46 -0800 Received: by cyd.mit.edu (Postfix, from userid 1000) id 9ED6A57E20C; Thu, 19 Feb 2009 20:45:40 -0500 (EST) From: Chong Yidong To: control@debbugs.gnu.org Subject: reassign bugs Date: Thu, 19 Feb 2009 20:45:40 -0500 Message-ID: <87mychx4mz.fsf@cyd.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii close 2379 reassign 2382 spam reassign 2389 spam reassign 2390 spam reassign 2392 spam reassign 2393 spam reassign 2396 spam reassign 2399 spam thanks From aaron.s.hawley@gmail.com Thu Feb 19 20:27:41 2009 Received: (at submit) by emacsbugs.donarmstrong.com; 20 Feb 2009 04:27:41 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-3.0 required=4.0 tests=HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=unavailable version=3.2.5-bugs.debian.org_2005_01_02 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n1K4Rbra029166 for ; Thu, 19 Feb 2009 20:27:39 -0800 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LaMzB-0000xE-MD for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 23:27:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LaMz9-0000x2-8e for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 23:27:36 -0500 Received: from [199.232.76.173] (port=60542 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LaMz9-0000wz-3Y for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 23:27:35 -0500 Received: from an-out-0708.google.com ([209.85.132.246]:38222) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LaMz8-0007RC-Ox for bug-gnu-emacs@gnu.org; Thu, 19 Feb 2009 23:27:34 -0500 Received: by an-out-0708.google.com with SMTP id b6so311105ana.21 for ; Thu, 19 Feb 2009 20:27:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=N1KMIpHbrLhtWaDc9/2wsCxyz8UZhoLpz7voSPRZjCw=; b=QoKo9HOW+FZ3AQ7DiDHQSb/5JUDvo+01u4LleUibltVl/E16MEPyVyjxaxsAMqsKhm w61Vwee87oGLCIr6jlD9WD6E+u0ZIkH5sIGIijtU8Q+Y6euOIrlSB7Tj/2pFhuyCzTU5 AsBEyh3DgjFr0w7W1cewYp1izqUm9ALCYPyhI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=EJuNHGu6RRN75VX5n4widv4XHSoyI0K77T+li4FAjhGv4wbkRbBj5t1hgsTswM+CwP FfTizhpRU8cdX7e5dJ9n1ktEdDQMirKjoukQKcebNRQDxK4f1/0sqvANZuqxOK/6Lznz HUfNT9N9PLwCVoq3TM/SN8ZnWoq2inSA8P93k= MIME-Version: 1.0 Received: by 10.100.125.12 with SMTP id x12mr651257anc.4.1235104053293; Thu, 19 Feb 2009 20:27:33 -0800 (PST) In-Reply-To: References: Date: Thu, 19 Feb 2009 23:27:33 -0500 Message-ID: Subject: Re: bug#2379: [PATCH?] lisp.el: beginning-of-defun From: "Aaron S. Hawley" To: Stefan Monnier Cc: 2379@debbugs.gnu.org, bug-gnu-emacs@gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Hey Stefan. Thanks for the reply. >> - (progn (goto-char (1- (match-end 0)))) t)) >> + (progn (goto-char (1- (match-end 0))) t))) > > I think that was the intention. Note that it turns out that the two > forms are equivalent in this context (because goto-char never returns > nil). Yes, I had noticed sloppy programming got lucky. > AFAICT, proper support for 0 would require a serious rethink of BOD's > semantics: currently if you're inside defun number N, then (BOD i) moves > to (N-(i-1)) is i is positive and to (N-i) if i is negative. I.e. it > moves to N if i=1 and to N+1 if i=-1, so where should 0 move to: there > is no other defun between those two. Fair enough. I notice that C-0 M-x end-of-defun is the same as just regular M-x end-of-defun. Also, It's worth citing beginning-of-line's behavior here, since it departs by moving in the oppisite direction -- N-1+i. Anyway, I'm just surprised this critical code for Lisp support is this sloppy. Cheers, /a From monnier@iro.umontreal.ca Fri Feb 20 07:25:51 2009 Received: (at submit) by emacsbugs.donarmstrong.com; 20 Feb 2009 15:25:52 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-0.5 required=4.0 tests=HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,XIRONPORT autolearn=unavailable version=3.2.5-bugs.debian.org_2005_01_02 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n1KFPkdb024054 for ; Fri, 20 Feb 2009 07:25:48 -0800 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LaXG3-0005xu-Pv for bug-gnu-emacs@gnu.org; Fri, 20 Feb 2009 10:25:43 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LaXG2-0005xP-VB for bug-gnu-emacs@gnu.org; Fri, 20 Feb 2009 10:25:43 -0500 Received: from [199.232.76.173] (port=51801 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LaXG2-0005xJ-Nc for bug-gnu-emacs@gnu.org; Fri, 20 Feb 2009 10:25:42 -0500 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:31827) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LaXG2-00055F-87 for bug-gnu-emacs@gnu.org; Fri, 20 Feb 2009 10:25:42 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkwFACdanklMCpTK/2dsb2JhbACBbtMZhA8Gg0o X-IronPort-AV: E=Sophos;i="4.38,241,1233550800"; d="scan'208";a="34142152" Received: from 76-10-148-202.dsl.teksavvy.com (HELO pastel.home) ([76.10.148.202]) by ironport2-out.teksavvy.com with ESMTP; 20 Feb 2009 10:25:41 -0500 Received: by pastel.home (Postfix, from userid 20848) id E8D854B488; Fri, 20 Feb 2009 10:25:40 -0500 (EST) From: Stefan Monnier To: "Aaron S. Hawley" Cc: 2379@debbugs.gnu.org, bug-gnu-emacs@gnu.org Subject: Re: bug#2379: [PATCH?] lisp.el: beginning-of-defun Message-ID: References: Date: Fri, 20 Feb 2009 10:25:40 -0500 In-Reply-To: (Aaron S. Hawley's message of "Thu, 19 Feb 2009 23:27:33 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. >> AFAICT, proper support for 0 would require a serious rethink of BOD's >> semantics: currently if you're inside defun number N, then (BOD i) moves >> to (N-(i-1)) is i is positive and to (N-i) if i is negative. I.e. it >> moves to N if i=1 and to N+1 if i=-1, so where should 0 move to: there >> is no other defun between those two. > Fair enough. > I notice that C-0 M-x end-of-defun is the same as just regular M-x > end-of-defun. Yes, I also noticed it when I rewrite end-of-defun, but just as is the case for BOD, making it to "TRT" for 0 would require more significant changes I think. So I figured I may as well preserve the old broken behavior rather than change it to some other broken behavior. > Also, It's worth citing beginning-of-line's behavior > here, since it departs by moving in the opposite direction -- N-1+i. > Anyway, I'm just surprised this critical code for Lisp support is > this sloppy. We're all surprised. But remember: Emacs is mostly made up of "sloppy" code. And there's a good reaon for that: it's often very difficult to figure out what is "the right behavior", so the first implementations just do an approximate job, which gets somewhat refined over time, but backward compatibility means that it often can't be refined to the point of being correct. Stefan From unknown Wed Jun 18 23:05:11 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: $requester Subject: Internal Control Message-Id: bug archived. Date: Sat, 21 Mar 2009 14:24:10 +0000 User-Agent: Fakemail v42.6.9 # A New Hope # A log time ago, in a galaxy far, far away # something happened. # # Magically this resulted in the following # action being taken, but this fake control # message doesn't tell you why it happened # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator