emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martyn Jago <martyn.jago@btinternet.com>
To: Aankhen <aankhen@gmail.com>
Cc: Org-mode ml <emacs-orgmode@gnu.org>
Subject: Re: [BUG] Unmatched #+end-src
Date: Sat, 12 Mar 2011 20:43:12 +0000	[thread overview]
Message-ID: <87aah0cbof.fsf@btinternet.com> (raw)
In-Reply-To: <AANLkTi=SSAi275cQD6v4GKKVZ0_f5XEF7CAbt2V-zkD+@mail.gmail.com> (aankhen@gmail.com's message of "Sun, 13 Mar 2011 00:59:07 +0530")

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

Aankhen <aankhen@gmail.com> writes:

Thanks for the heads-up Aankhen, I had indeed missed the enclosing
infinite loop.

I modified your patch slightly since my test still failed, and made
further tests.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix-endless-loop-in-org-in-item-p --]
[-- Type: text/x-diff, Size: 995 bytes --]

From b55d846b57fc2ebf3c282cb1fbb27becfdd7d4fd Mon Sep 17 00:00:00 2001
From: Martyn Jago <martyn.jago@btinternet.com>
Date: Sat, 12 Mar 2011 20:38:14 +0000
Subject: [PATCH] Fix endless loop in 'org-in-item-p where #+end_ block has no matching beginning block

---
 lisp/org-list.el |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 4b50910..7d8692b 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -465,8 +465,9 @@ This checks `org-list-ending-method'."
 		     (looking-at org-list-end-re))
 		(throw 'exit nil))
 	       ;; Skip blocks, drawers, inline-tasks, blank lines
-	       ((looking-at "^[ \t]*#\\+end_")
-		(re-search-backward "^[ \t]*#\\+begin_" nil t))
+	       ((and (looking-at "^[ \t]*#\\+end_")
+		     (not (re-search-backward "^[ \t]*#\\+begin_" nil t)))
+		(throw 'exit nil))
 	       ((looking-at "^[ \t]*:END:")
 		(re-search-backward org-drawer-regexp nil t)
 		(beginning-of-line))
-- 
1.7.4.1


[-- Attachment #3: Type: text/plain, Size: 2633 bytes --]


Regards

Martyn

> Hi,
>
> On Sat, Mar 12, 2011 at 22:26, Martyn Jago <martyn.jago@btinternet.com> wrote:
>> --8<---------------cut here---------------start------------->8---
>> * Unmatched #+end-src bug
>>
>> #+end_src
>> --8<---------------cut here---------------end--------------->8---
>>
>> With the above simple org file, placing the cursor at the end of
>> #+end_src and hitting return causes emacs to hang.
>>
>> The bug can be replicated with the following simple test which also
>> causes emacs to hang...
>>
>> [snip]
>>
>> It appears to be related to the following in 'org-in-item-p
>> (org-list.el)...
>>
>> --8<---------------cut here---------------start------------->8---
>>               ((looking-at "^[ \t]*#\\+end_")
>>                (re-search-backward "^[ \t]*#\\+begin_" nil t))
>> --8<---------------cut here---------------end--------------->8---
>>
>> I've tried to pin down the bug but its left me perplexed, so I'm going
>> to defer to more experienced org lispers!
>
> The =cond= is part of a =while= loop; it just keeps looping, entering
> that branch and doing nothing (rather than moving point and picking up
> again from there).  Going by the other branches, I think the correct
> thing to do is just exit the loop:
>
> diff --git a/lisp/org-list.el b/lisp/org-list.el
> --- a/lisp/org-list.el
> +++ b/lisp/org-list.el
> @@ -450,17 +450,19 @@ This checks `org-list-ending-method'."
>                ;; At upper bound of search or looking at the end of a
>                ;; previous list: search is over.
>                ((<= (point) lim-up) (throw 'exit nil))
>                ((and (not (eq org-list-ending-method 'indent))
>                      (looking-at org-list-end-re))
>                 (throw 'exit nil))
>                ;; Skip blocks, drawers, inline-tasks, blank lines
>                ((looking-at "^[ \t]*#\\+end_")
> -               (re-search-backward "^[ \t]*#\\+begin_" nil t))
> +               (condition-case nil
> +                   (re-search-backward "^[ \t]*#\\+begin_" nil)
> +                 (search-failed (throw 'exit nil))))
>                ((looking-at "^[ \t]*:END:")
>                 (re-search-backward org-drawer-regexp nil t)
>                 (beginning-of-line))
>                ((and inlinetask-re (looking-at inlinetask-re))
>                 (org-inlinetask-goto-beginning)
>                 (forward-line -1))
>                ((looking-at "^[ \t]*$") (forward-line -1))
>                ;; Text at column 0 cannot belong to a list: stop.
>
> Hope this helps,
> Aankhen

  parent reply	other threads:[~2011-03-12 20:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-12 16:56 [BUG] Unmatched #+end-src Martyn Jago
2011-03-12 19:29 ` Aankhen
2011-03-12 20:07   ` Nicolas
2011-03-12 20:20     ` Aankhen
2011-03-12 21:05     ` Martyn Jago
2011-03-13  0:31       ` Nicolas
2011-03-13 13:49         ` Eric Schulte
2011-03-17 12:09           ` Nicolas Goaziou
2011-03-12 20:43   ` Martyn Jago [this message]
2011-03-23 17:38 ` Nicolas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87aah0cbof.fsf@btinternet.com \
    --to=martyn.jago@btinternet.com \
    --cc=aankhen@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).