branch: elpa
commit ccfe3167c40a4b4c241bbc4f3b0445381f6ace8d
Author: Tassilo Horn <[email protected]>
Commit: Tassilo Horn <[email protected]>
Make TeX-view work better with regions
* tex-buf.el (TeX-region-update-point): New function which sets point in
the region buffer so that it matches the location of point in the
current buffer.
(TeX-view): Use it.
---
tex-buf.el | 25 ++++++++++++++++++++++++-
tex.el | 2 +-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/tex-buf.el b/tex-buf.el
index f2017cd..0fe7b9d 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -892,6 +892,25 @@ QUEUE is non-nil when we are checking for the printer
queue."
(goto-char (posn-point (event-start event)))
(TeX-view)))
+(defun TeX-region-update-point ()
+ "Syncs the location of point in the region file with the current file.
+
+Thereafter, point in the region file is on the same text as in
+the current buffer.
+
+Does nothing in case the last command hasn't operated on the
+region."
+ (when TeX-current-process-region-p
+ (let ((region-buf (get-file-buffer (TeX-region-file t)))
+ (current-line (line-number-at-pos)))
+ (when region-buf
+ (with-current-buffer region-buf
+ (goto-char (point-min))
+ (when (re-search-forward "!offset(\\(-?[0-9]+\\)")
+ (let ((offset (string-to-int (match-string 1))))
+ (goto-char (point-min))
+ (forward-line (- current-line (1+ offset))))))))))
+
(defun TeX-view ()
"Start a viewer without confirmation.
The viewer is started either on region or master file,
@@ -899,7 +918,11 @@ depending on the last command issued."
(interactive)
(let ((output-file (TeX-active-master (TeX-output-extension))))
(if (file-exists-p output-file)
- (TeX-command "View" 'TeX-active-master 0)
+ (progn
+ ;; When we're operating on a region, we need to update the position
+ ;; of point in the region file so that forward search works.
+ (TeX-region-update-point)
+ (TeX-command "View" 'TeX-active-master 0))
(message "Output file %S does not exist." output-file))))
(defun TeX-output-style-check (styles)
diff --git a/tex.el b/tex.el
index 6902de9..8ea0b45 100644
--- a/tex.el
+++ b/tex.el
@@ -1271,7 +1271,7 @@ entry in `TeX-view-program-list-builtin'."
(if (and TeX-source-correlate-mode
(fboundp 'pdf-sync-forward-search))
(with-current-buffer (or (when TeX-current-process-region-p
- (get-file-buffer (TeX-region-file t)))
+ (get-file-buffer (TeX-region-file t)))
(current-buffer))
(pdf-sync-forward-search))
(let ((pdf (concat file "." (TeX-output-extension))))