phillord / lentic

Create views of the same content in two Emacs buffers
183 stars 12 forks source link

Confusing lentic with "begin_src" inside code (emacs lisp to org) #36

Closed brabalan closed 9 years ago

brabalan commented 9 years ago

Lentic works great with my 3400 lines init.el file, but there are two places where it gets confused:

;; #+begin_src emacs-lisp
(setq org-structure-template-alist
      (quote (("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>")
          ("e" "#+begin_example\n?\n#+end_example" "<example>\n?\n</example>")
          ("q" "#+begin_quote\n?\n#+end_quote" "<quote>\n?\n</quote>")
          ("v" "#+begin_verse\n?\n#+end_verse" "<verse>\n?\n</verse>")
          ("c" "#+begin_center\n?\n#+end_center" "<center>\n?\n</center>")
          ("l" "#+begin_latex\n?\n#+end_latex" "<literal style=\"latex\">\n?\n</literal>")
          ("L" "#+latex: " "<literal style=\"latex\">?</literal>")
          ("h" "#+begin_html\n?\n#+end_html" "<literal style=\"html\">\n?\n</literal>")
          ("H" "#+html: " "<literal style=\"html\">?</literal>")
          ("a" "#+begin_ascii\n?\n#+end_ascii")
          ("A" "#+ascii: ")
          ("i" "#+index: ?" "#+index: ?")
          ("I" "#+include %file ?" "<include file=%file markup=\"?\">"))))
;; #+end_src

and another similar place (some code to surround a region with source markers).

By "gets confused", I mean that the org buffer is created correctly, but as soon as I edit the org buffer, the code above gets commented out, as if the "end_src" in the code indicated the end of the code block.

phillord commented 9 years ago

So, it does. As a workaround you could break the #begin_src using two strings and a concat. Clearly I need a start-of-line anchor somewhere.

brabalan commented 9 years ago

Thank you for the suggestion, I'll give it a try.

phillord commented 9 years ago

I tried this when I got the bug report and, indeed, everything was as you say. Now I get some time to fix and, of course, I find it completely impossible to replicate.

Using the "better to guess than test" approach to development, I have pushed a potential fix up to this branch.

fix/orgel-stringed-delimitor

Could you see if it addresses your issue for me?

Failing that, can you tell me which version of lentic, and send me a complete (but minimal) example please and a set of steps that I need to do to cause the problem.

I'm pleased it's working well on 3000+ of config! Ironically, I haven't done my config yet, but it needs it.

brabalan commented 9 years ago

This was tricky to reproduce, but I think I got it. I'm using the current version from Melpa, with your fix installed (I manually added the anchors, byte-compiled the file, and restarted emacs).

Here is an ECM:

;;; lentic_test --- testing it

;;; Code:

;; ** a subsection
;; #+begin_src emacs-lisp
(message "foo")
;; #+end_src

;; ** testing commented code

;; #+begin_src emacs-lisp
(setq org-structure-template-alist
      (quote (("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>")
          ("e" "#+begin_example\n?\n#+end_example" "<example>\n?\n</example>")
          ("I" "#+include %file ?" "<include file=%file markup=\"?\">"))))
;; #+end_src

;; # Local Variables:
;; # lentic-init: lentic-orgel-org-init
;; # End:

To trigger the problem, generate the org buffer, go to it, and delete the line with begin_example in it (using C-k). Alternatively, you can copy a heading line and paste it (still in the org buffer), or copy a line and paste it.

I found that typing enter in the second code block trigger the problem, but not in the first code block. However, typing text, or enter outside of code blocks, works fine.

Do you see the same thing?

phillord commented 9 years ago

Yes, I can confirm this works (or rather breaks). It only happens when you change the second block because lentic is doing incremental updates -- so it has to be the same block. Why it is happening at all, I do not know, but now I have a clean test case, I am sure that I can work it out.

It may take a while. Rather work spammed at the moment!

phillord commented 9 years ago

Can you repull fix/orgel-string-delimitor and try again?

Turns out my "find the start/stop" markers logic was a real mess. Once I fixed that, it's a one-character change!

Anyway, let me know.

brabalan commented 9 years ago

It's working great, thanks a lot.