unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6157: narrow-to-defun fix when point is on function beginning
@ 2010-05-10 14:51 Lennart Borgman
  2010-05-10 17:06 ` Stefan Monnier
  2011-09-21 20:03 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 6+ messages in thread
From: Lennart Borgman @ 2010-05-10 14:51 UTC (permalink / raw)
  To: 6157

`beginning-of-defun' goes to previous function when point is on the
first character of a function. This is not currently taken care of in
`narrow-to-defun'. This patch fixes this:


c:\emacs-lp\bld\emacs\emacsw32\lisp\emacs-lisp>bzr diff --old
c:\emacs-lp\bld\emacs\trunk -p trunk/:patched/ lisp.el
=== modified file 'lisp/emacs-lisp/lisp.el'
--- trunk/lisp/emacs-lisp/lisp.el	2010-04-27 17:57:32 +0000
+++ patched/lisp/emacs-lisp/lisp.el	2010-05-10 14:21:59 +0000
@@ -438,7 +438,20 @@
       ;; Try first in this order for the sake of languages with nested
       ;; functions where several can end at the same place as with
       ;; the offside rule, e.g. Python.
-      (beginning-of-defun)
+
+      ;; Finding the start of the function is a bit problematic since
+      ;; `beginning-of-defun' when we are on the first character of
+      ;; the function might go to the previous function.
+      ;;
+      ;; Therefor we first move one character forward and then call
+      ;; `beginning-of-defun'.  However now we must check that we did
+      ;; not move into the next function.
+      (let ((here (point)))
+        (unless (eobp) (forward-char))
+        (beginning-of-defun)
+        (when (< (point) here)
+          (goto-char here)
+          (beginning-of-defun)))
       (setq beg (point))
       (end-of-defun)
       (setq end (point))





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

* bug#6157: narrow-to-defun fix when point is on function beginning
  2010-05-10 14:51 bug#6157: narrow-to-defun fix when point is on function beginning Lennart Borgman
@ 2010-05-10 17:06 ` Stefan Monnier
  2011-09-21 20:03 ` Lars Magne Ingebrigtsen
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2010-05-10 17:06 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: 6157

> `beginning-of-defun' goes to previous function when point is on the
> first character of a function. This is not currently taken care of in
> `narrow-to-defun'. This patch fixes this:

Looks good, thank you (tho I'd use (eolp) rather than (eobp), and I'd
write "Therefore" rather than "Therefor").


        Stefan





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

* bug#6157: narrow-to-defun fix when point is on function beginning
  2010-05-10 14:51 bug#6157: narrow-to-defun fix when point is on function beginning Lennart Borgman
  2010-05-10 17:06 ` Stefan Monnier
@ 2011-09-21 20:03 ` Lars Magne Ingebrigtsen
  2011-09-21 20:19   ` Lennart Borgman
  1 sibling, 1 reply; 6+ messages in thread
From: Lars Magne Ingebrigtsen @ 2011-09-21 20:03 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: 6157

Lennart Borgman <lennart.borgman@gmail.com> writes:

> `beginning-of-defun' goes to previous function when point is on the
> first character of a function. This is not currently taken care of in
> `narrow-to-defun'. This patch fixes this:
>
> c:\emacs-lp\bld\emacs\emacsw32\lisp\emacs-lisp>bzr diff --old
> c:\emacs-lp\bld\emacs\trunk -p trunk/:patched/ lisp.el
> === modified file 'lisp/emacs-lisp/lisp.el'
> --- trunk/lisp/emacs-lisp/lisp.el	2010-04-27 17:57:32 +0000
> +++ patched/lisp/emacs-lisp/lisp.el	2010-05-10 14:21:59 +0000
> @@ -438,7 +438,20 @@
>        ;; Try first in this order for the sake of languages with nested
>        ;; functions where several can end at the same place as with
>        ;; the offside rule, e.g. Python.
> -      (beginning-of-defun)
> +
> +      ;; Finding the start of the function is a bit problematic since
> +      ;; `beginning-of-defun' when we are on the first character of
> +      ;; the function might go to the previous function.
> +      ;;
> +      ;; Therefor we first move one character forward and then call
> +      ;; `beginning-of-defun'.  However now we must check that we did
> +      ;; not move into the next function.
> +      (let ((here (point)))
> +        (unless (eobp) (forward-char))
> +        (beginning-of-defun)
> +        (when (< (point) here)
> +          (goto-char here)
> +          (beginning-of-defun)))
>        (setq beg (point))
>        (end-of-defun)
>        (setq end (point))

This patch was apparently approved by Stefan, but not applied, as far as
I can tell.  Did it turn out to not be correct after all?

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/





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

* bug#6157: narrow-to-defun fix when point is on function beginning
  2011-09-21 20:03 ` Lars Magne Ingebrigtsen
@ 2011-09-21 20:19   ` Lennart Borgman
  2012-04-11  2:11     ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Lennart Borgman @ 2011-09-21 20:19 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: 6157

On Wed, Sep 21, 2011 at 22:03, Lars Magne Ingebrigtsen <larsi@gnus.org> wrote:
> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
>> `beginning-of-defun' goes to previous function when point is on the
>> first character of a function. This is not currently taken care of in
>> `narrow-to-defun'. This patch fixes this:
>>
>> c:\emacs-lp\bld\emacs\emacsw32\lisp\emacs-lisp>bzr diff --old
>> c:\emacs-lp\bld\emacs\trunk -p trunk/:patched/ lisp.el
>> === modified file 'lisp/emacs-lisp/lisp.el'
>> --- trunk/lisp/emacs-lisp/lisp.el     2010-04-27 17:57:32 +0000
>> +++ patched/lisp/emacs-lisp/lisp.el   2010-05-10 14:21:59 +0000
>> @@ -438,7 +438,20 @@
>>        ;; Try first in this order for the sake of languages with nested
>>        ;; functions where several can end at the same place as with
>>        ;; the offside rule, e.g. Python.
>> -      (beginning-of-defun)
>> +
>> +      ;; Finding the start of the function is a bit problematic since
>> +      ;; `beginning-of-defun' when we are on the first character of
>> +      ;; the function might go to the previous function.
>> +      ;;
>> +      ;; Therefor we first move one character forward and then call
>> +      ;; `beginning-of-defun'.  However now we must check that we did
>> +      ;; not move into the next function.
>> +      (let ((here (point)))
>> +        (unless (eobp) (forward-char))
>> +        (beginning-of-defun)
>> +        (when (< (point) here)
>> +          (goto-char here)
>> +          (beginning-of-defun)))
>>        (setq beg (point))
>>        (end-of-defun)
>>        (setq end (point))
>
> This patch was apparently approved by Stefan, but not applied, as far as
> I can tell.  Did it turn out to not be correct after all?

I think it was correct, but the problem is that I never submit
anything to the repository. (Since I did not trust myself to make the
submission in a correct way...)





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

* bug#6157: narrow-to-defun fix when point is on function beginning
  2011-09-21 20:19   ` Lennart Borgman
@ 2012-04-11  2:11     ` Lars Magne Ingebrigtsen
  2012-04-11  9:47       ` Lennart Borgman
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Magne Ingebrigtsen @ 2012-04-11  2:11 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: 6157

Lennart Borgman <lennart.borgman@gmail.com> writes:

> I think it was correct, but the problem is that I never submit
> anything to the repository. (Since I did not trust myself to make the
> submission in a correct way...)

I've now applied it to the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/





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

* bug#6157: narrow-to-defun fix when point is on function beginning
  2012-04-11  2:11     ` Lars Magne Ingebrigtsen
@ 2012-04-11  9:47       ` Lennart Borgman
  0 siblings, 0 replies; 6+ messages in thread
From: Lennart Borgman @ 2012-04-11  9:47 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: 6157

On Wed, Apr 11, 2012 at 04:11, Lars Magne Ingebrigtsen <larsi@gnus.org> wrote:
> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
>> I think it was correct, but the problem is that I never submit
>> anything to the repository. (Since I did not trust myself to make the
>> submission in a correct way...)
>
> I've now applied it to the trunk.

Thanks.





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

end of thread, other threads:[~2012-04-11  9:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-10 14:51 bug#6157: narrow-to-defun fix when point is on function beginning Lennart Borgman
2010-05-10 17:06 ` Stefan Monnier
2011-09-21 20:03 ` Lars Magne Ingebrigtsen
2011-09-21 20:19   ` Lennart Borgman
2012-04-11  2:11     ` Lars Magne Ingebrigtsen
2012-04-11  9:47       ` Lennart Borgman

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).