From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Bach Subject: Re: LaTeX export: Keep point position in TeX file Date: Mon, 23 Jan 2012 23:09:00 +0100 Message-ID: <4f1dd95d.d0770e0a.24a7.41e4@mx.google.com> References: <4f0ed0da.82600e0a.21d0.29ec@mx.google.com> <87hb01qczx.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:51445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpRzu-0007bf-8t for emacs-orgmode@gnu.org; Mon, 23 Jan 2012 17:04:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RpRzs-0007WC-LK for emacs-orgmode@gnu.org; Mon, 23 Jan 2012 17:04:18 -0500 Received: from mail-ee0-f41.google.com ([74.125.83.41]:51667) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpRzs-0007Vz-GY for emacs-orgmode@gnu.org; Mon, 23 Jan 2012 17:04:16 -0500 Received: by eekc13 with SMTP id c13so1332748eek.0 for ; Mon, 23 Jan 2012 14:04:14 -0800 (PST) In-Reply-To: <87hb01qczx.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Thu, 12 Jan 2012 13:14:26 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Eric S Fraga 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