From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.devel Subject: Re: Strange behavior of (beginning-of-defun 0) Date: Wed, 22 Feb 2017 10:13:29 +0100 Message-ID: <87o9xumvuu.fsf@jane> References: <87r339s12a.fsf@mbork.pl> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1487754850 13851 195.159.176.226 (22 Feb 2017 09:14:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 22 Feb 2017 09:14:10 +0000 (UTC) User-Agent: mu4e 0.9.19; emacs 26.0.50.5 To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 22 10:14:06 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgSzo-0002I5-7t for ged-emacs-devel@m.gmane.org; Wed, 22 Feb 2017 10:14:00 +0100 Original-Received: from localhost ([::1]:50904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgSzp-00010d-7P for ged-emacs-devel@m.gmane.org; Wed, 22 Feb 2017 04:14:01 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgSzi-00010V-QR for emacs-devel@gnu.org; Wed, 22 Feb 2017 04:13:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgSzd-0002dD-RB for emacs-devel@gnu.org; Wed, 22 Feb 2017 04:13:54 -0500 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:48944) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgSzd-0002bx-JM for emacs-devel@gnu.org; Wed, 22 Feb 2017 04:13:49 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id E87A2E6660 for ; Wed, 22 Feb 2017 10:13:42 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TrFwJGLE68PJ for ; Wed, 22 Feb 2017 10:13:39 +0100 (CET) Original-Received: from localhost (unknown [83.13.149.242]) by mail.mojserwer.eu (Postfix) with ESMTPSA id AD0C8E602D for ; Wed, 22 Feb 2017 10:13:39 +0100 (CET) In-reply-to: <87r339s12a.fsf@mbork.pl> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.110.48.8 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:212537 Archived-At: --=-=-= Content-Type: text/plain On 2017-02-08, at 06:29, Marcin Borkowski wrote: > Hi all, > > put this in an Elisp buffer: > > --8<---------------cut here---------------start------------->8--- > (defun a () > nil) > -!-(defun b () > nil) > --8<---------------cut here---------------end--------------->8--- > > put the point where the -!- is (of course, "-!-" is only a marker and > should not be in the buffer;-)) and say M-: (beginning-of-defun 0) (or > C-u 0 C-M-a). The point goes up one line. > > Is that intended? Is the behavior of (beginning-of-defun 0) defined at > all? Hi all, I spent a few minutes looking into this, and it seems that while a test for zero argument is actually present in `beginning-of-defun-raw', it (a) is (imho) located in the wrong place (too late in the `cond') and (b) returns t instead of nil (so that `beginning-of-defun' moves to the bol instead of not moving the point at all). So, here's a patch correcting this. WDYT? Best, -- Marcin Borkowski --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-beginning-of-defun-raw-0.patch >From daf641a0c57bd8fdcf1fad40bcfbc23a8fb40101 Mon Sep 17 00:00:00 2001 From: Marcin Borkowski Date: Wed, 22 Feb 2017 10:02:47 +0100 Subject: [PATCH] Fix (beginning-of-defun-raw 0) * lisp/emacs-lisp/lisp.el (beginning-of-defun-raw): fix behavior with arg equal to zero Unless `beginning-of-defun-function' is non-nil (and should take care of that situation), do nothing when argument is 0. --- lisp/emacs-lisp/lisp.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 0172e3af26..b2dd8edf42 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -337,6 +337,8 @@ beginning-of-defun-raw (dotimes (_ (- arg)) (funcall end-of-defun-function)))))) + ((eq arg 0) nil) + ((or defun-prompt-regexp open-paren-in-column-0-is-defun-start) (and (< arg 0) (not (eobp)) (forward-char 1)) (and (re-search-backward (if defun-prompt-regexp @@ -356,8 +358,6 @@ beginning-of-defun-raw ;; call to scan-lists below can be extremely slow. This is because ;; back_comment in syntax.c may have to scan from bob to find the ;; beginning of each comment. Fixing this is not trivial -- cyd. - - ((eq arg 0)) (t (let ((floor (point-min)) (ceiling (point-max)) -- 2.11.1 --=-=-=--