1 ;;; pdfsync.el --- AUCTeX style for `pdfsync.sty'
3 ;; Copyright (C) 2005, 2008, 2014 Free Software Foundation, Inc.
5 ;; Author: Ralf Angeli <angeli@iwi.uni-sb.de>
6 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of AUCTeX.
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 ;; This file adds support for `pdfsync.sty'.
33 (defun LaTeX-pdfsync-output-page ()
34 "Return page number in output file corresponding to buffer position."
35 (let* ((line (TeX-line-number-at-pos))
36 (master (TeX-active-master))
37 (file (file-name-sans-extension
38 (file-relative-name (buffer-file-name)
39 (file-name-directory master))))
40 (pdfsync-file (concat master ".pdfsync"))
41 (buf-live-p (get-file-buffer pdfsync-file))
45 (when (file-exists-p pdfsync-file)
46 (with-current-buffer (find-file-noselect pdfsync-file)
48 (goto-char (point-min))
49 ;; Narrow region to file in question.
50 (when (not (string= file master))
51 (re-search-forward (concat "^(" file "\\(.tex\\)?$") nil t)
52 (let ((beg (match-beginning 0)))
54 (narrow-to-region (line-beginning-position 2)
55 (progn (forward-sexp) (point))))
56 (goto-char (point-min)))
57 ;; Look for the record number.
59 (while (re-search-forward "^(\\|^l \\([0-9]+\\) \\([0-9]+\\)" nil t)
60 (cond ((string= (match-string 0) "(")
61 (goto-char (match-beginning 0))
63 ((> (string-to-number (match-string 2)) line)
66 (setq sync-record (match-string 1)
67 last-match (match-beginning 0))))))
68 ;; Look for the page number.
69 (goto-char (or last-match (point-min)))
70 ;; There might not be any p or s lines for the current file,
71 ;; so make it possible to search further.
74 (while (re-search-forward "^p \\([0-9]+\\)" nil t)
75 (when (>= (string-to-number (match-string 1))
76 (string-to-number sync-record))
77 (re-search-backward "^s \\([0-9]+\\)" nil t)
78 (setq sync-page (match-string 1))
79 (throw 'break nil)))))
80 ;; Kill the buffer if it was loaded by us.
81 (unless buf-live-p (kill-buffer (current-buffer)))))
87 (setq TeX-source-correlate-output-page-function 'LaTeX-pdfsync-output-page))
90 ;;; pdfsync.el ends here