emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Bach <phaebz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: LaTeX export: Keep point position in TeX file
Date: Mon, 23 Jan 2012 23:09:00 +0100	[thread overview]
Message-ID: <4f1dd95d.d0770e0a.24a7.41e4@mx.google.com> (raw)
In-Reply-To: <87hb01qczx.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Thu, 12 Jan 2012 13:14:26 +0000")

Eric S Fraga <e.fraga@ucl.ac.uk> 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	other threads:[~2012-01-23 22:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-12 12:28 LaTeX export: Keep point position in TeX file Michael Bach
2012-01-12 13:14 ` Eric S Fraga
2012-01-23 22:09   ` Michael Bach [this message]
2012-01-24  8:50     ` Eric S Fraga

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=4f1dd95d.d0770e0a.24a7.41e4@mx.google.com \
    --to=phaebz@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).