emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] LaTeX export: Keep point position in TeX file


From: Michael Bach
Subject: Re: [O] LaTeX export: Keep point position in TeX file
Date: Mon, 23 Jan 2012 23:09:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Eric S Fraga <address@hidden> writes:

> If so, I suggest you could achieve what you want by using the
> org-export-* hooks to, for instance, save current position before export
> and then jump to that position after export?  Maybe
> org-export-first-hook and org-export-latex-final-hook could be used?
>

Thanks for your thoughts on this and sorry for being late to reply.  I
stumbled upon your reply and have tried it today with this:

--8<---------------cut here---------------start------------->8---
(defun my-org-latex-export-save-point ()
  (interactive)
  (let ((latexfile (concat (file-name-sans-extension (buffer-name)) ".tex"))
        (orgfile (buffer-name)))
    (if (get-buffer latexfile)
        (save-excursion (set-buffer latexfile)
                        (setq temppoint (point)))
      (message "Open exported LaTeX file to save point position"))))
--8<---------------cut here---------------end--------------->8---

`(interactive)' is only for testing purposes.  Saving of point in .tex
file under `temppoint' works this way.

I tried further restoring point but failed.  For reference:

--8<---------------cut here---------------start------------->8---
(defun my-org-latex-export-restore-point ()
  (interactive)
  (let ((latexfile (concat (file-name-sans-extension (buffer-name)) ".tex"))
        (orgfile (concat (file-name-sans-extension (buffer-name)) ".org")))
    (progn
      (switch-to-buffer-other-frame (get-buffer latexfile))
      (goto-char temppoint))))
--8<---------------cut here---------------end--------------->8--- 

The switching to latex file works, but `(goto-char temppoint)' does not
- for a reason I do not understand.  The only benefit of this is that
after export, emacs switches to the latex file automatically, which may
or may not be wanted (in my case, it is).

The last thing is to bind the functions to the correct hooks.  I found
this worked:

--8<---------------cut here---------------start------------->8---
(add-hook 'org-export-latex-after-initial-vars-hook
          'my-org-latex-export-save-point)
(add-hook 'org-export-latex-after-save-hook
          'my-org-latex-export-restore-point)
--8<---------------cut here---------------end--------------->8---

> Untried and obviously untested!  And likely beyond my elisp capabilities
> so I'd be very keen on seeing a solution.  This behaviour has also
> bothered me (well, very minor irritation) for a long time as I often
> export to latex when debugging the export to PDF.
>

It is also a minor irritation to me.  And even if I could get my
solution to work as intended, this approach only helps for minor edits,
since the org-export could insert arbitrarily many new lines into the
latex file, making the "restore by previous point position" rather
useless.

What would be needed is a context sensitive position check which can
check for environments and contents simultaneously.  Just guessing and
thinking aloud here.  A solution by hobby-elispers like me will be
necessarily cumbersome, but maybe someone more skilled can pick up the
scraps and make it work better :-)

Best,
Michael



reply via email to

[Prev in Thread] Current Thread [Next in Thread]