unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Strange behavior of (beginning-of-defun 0)
@ 2017-02-08  5:29 Marcin Borkowski
  2017-02-22  9:13 ` Marcin Borkowski
  0 siblings, 1 reply; 2+ messages in thread
From: Marcin Borkowski @ 2017-02-08  5:29 UTC (permalink / raw)
  To: Emacs developers

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?

Best,

--
Marcin Borkowski



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Strange behavior of (beginning-of-defun 0)
  2017-02-08  5:29 Strange behavior of (beginning-of-defun 0) Marcin Borkowski
@ 2017-02-22  9:13 ` Marcin Borkowski
  0 siblings, 0 replies; 2+ messages in thread
From: Marcin Borkowski @ 2017-02-22  9:13 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 984 bytes --]


On 2017-02-08, at 06:29, Marcin Borkowski <mbork@mbork.pl> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-beginning-of-defun-raw-0.patch --]
[-- Type: text/x-diff, Size: 1312 bytes --]

From daf641a0c57bd8fdcf1fad40bcfbc23a8fb40101 Mon Sep 17 00:00:00 2001
From: Marcin Borkowski <mbork@mbork.pl>
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-22  9:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-08  5:29 Strange behavior of (beginning-of-defun 0) Marcin Borkowski
2017-02-22  9:13 ` Marcin Borkowski

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).