branch: externals/auctex
commit 0cb3759d548be9b52cf53295ab5d10f7bf7d2c92
Author: Tassilo Horn <[email protected]>
Date: Wed Nov 19 12:46:15 2014 +0100
Implement inverse/backward search for TeX regions.
* tex.el (TeX-source-correlate-sync-source): Make backward/inverse
search form PDF to tex work also for TeX-regions.
* tex-buf.el (TeX-region-orig-buffer): New variable.
(TeX-region-create): Set TeX-region-orig-buffer.
---
ChangeLog | 6 ++++++
tex-buf.el | 5 +++++
tex.el | 55 +++++++++++++++++++++++++++++++++++++++++--------------
3 files changed, 52 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 49310be..7321d9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2014-11-19 Tassilo Horn <[email protected]>
+ * tex.el (TeX-source-correlate-sync-source): Make backward/inverse
+ search form PDF to tex work also for TeX-regions.
+
+ * tex-buf.el (TeX-region-orig-buffer): New variable.
+ (TeX-region-create): Set TeX-region-orig-buffer.
+
* tex.el (TeX-submit-bug-report): Adapt bug report intro text to
mention debbugs url.
diff --git a/tex-buf.el b/tex-buf.el
index 3810ea9..7b6905b 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -1387,6 +1387,10 @@ The hooks are run in the region buffer, you may use the
variable
(defvar font-lock-auto-fontify)
(defvar font-lock-defaults-alist)
+(defvar TeX-region-orig-buffer nil
+ "The original buffer in which the TeX-region was created.")
+(make-variable-buffer-local 'TeX-region-orig-buffer)
+
(defun TeX-region-create (file region original offset)
"Create a new file named FILE with the string REGION.
The region is taken from ORIGINAL starting at line OFFSET.
@@ -1490,6 +1494,7 @@ original file."
(1+ (TeX-current-offset))))
") }\n"
trailer)
+ (setq TeX-region-orig-buffer orig-buffer)
(run-hooks 'TeX-region-hook)
(if (string-equal (buffer-string) original-content)
(set-buffer-modified-p nil)
diff --git a/tex.el b/tex.el
index fc74537..ffd0ecf 100644
--- a/tex.el
+++ b/tex.el
@@ -1579,25 +1579,52 @@ or newer."
;; FILE may be given as relative path to the TeX-master root document or as
;; absolute file:// URL. In the former case, the tex file has to be already
;; opened.
- (let ((buf (let ((f (condition-case nil
- (progn
- (require 'url-parse)
- (require 'url-util)
- (url-unhex-string (aref (url-generic-parse-url
file) 6)))
- ;; For Emacs 21 compatibility, which doesn't have the
- ;; url package.
- (file-error (replace-regexp-in-string "^file://" ""
file)))))
- (if (file-name-absolute-p f)
- (find-file f)
- (get-buffer (file-name-nondirectory file)))))
- (line (car linecol))
- (col (cadr linecol)))
+ (let* ((line (car linecol))
+ (col (cadr linecol))
+ (region (string= TeX-region (file-name-sans-extension
+ (file-name-nondirectory file))))
+ (region-search-string nil)
+ (buf (let ((f (condition-case nil
+ (progn
+ (require 'url-parse)
+ (require 'url-util)
+ (url-unhex-string (aref (url-generic-parse-url
file) 6)))
+ ;; For Emacs 21 compatibility, which doesn't have the
+ ;; url package.
+ (file-error (replace-regexp-in-string "^file://" ""
file)))))
+ (cond
+ ;; Copy the text referenced by syntex relative in the region
+ ;; file so that we can search it in the original file.
+ (region (let ((region-buf (get-buffer (file-name-nondirectory
file))))
+ (when region-buf
+ (with-current-buffer region-buf
+ (goto-char (point-min))
+ (forward-line (1- line))
+ (let* ((p (point))
+ (bound (save-excursion
+ (re-search-backward
"\\\\message{[^}]+}" nil t)
+ (end-of-line)
+ (point)))
+ (start (save-excursion
+ (while (< (- p (point)) 250)
+ (backward-paragraph))
+ (point))))
+ (setq region-search-string
(buffer-substring-no-properties
+ (if (< start
bound) bound start)
+ (point))))
+ ;; TeX-region-create stores the original buffer
+ ;; locally as TeX-region-orig-buffer.
+ (get-buffer TeX-region-orig-buffer)))))
+ ((file-name-absolute-p f) (find-file f))
+ (t (get-buffer (file-name-nondirectory file)))))))
(if (null buf)
(message "No buffer for %s." file)
(switch-to-buffer buf)
(push-mark (point) 'nomsg)
(goto-char (point-min))
- (forward-line (1- line))
+ (if region
+ (search-forward region-search-string nil t)
+ (forward-line (1- line)))
(unless (= col -1)
(move-to-column col))
(raise-frame))))