branch: externals/auctex commit 4f397a2a34836fb508b555d850e91b72745f8f84 Author: Ikumi Keita <ik...@ikumi.que.jp> Commit: Ikumi Keita <ik...@ikumi.que.jp>
Imporve fix for Bug#26694 * tex-buf.el (TeX-command): Update point in region file if the command is "View". (TeX-view): (TeX-region-create): Pass the above job to `TeX-command'. (TeX-region-update-point): Move point according to the column in the original buffer. Do nothing when `TeX-source-correlate-mode' is disabled. Use `TeX-current-offset' instead of `TeX-line-number-at-pos' in case narrowing is in effect in the original buffer. * preview.el.in (preview-at-point): Revert previous commit in accord with the changes above. * tex.el (TeX-evince-sync-view-1): Use `TeX-current-offset' instead of `TeX-line-number-at-pos' in case narrowing is in effect in the original buffer. Add FIXME comment about using `current-column'. (TeX-synctex-output-page-1): Ditto. Arrange regexp to pick up page number more correctly. (TeX-view-program-list-builtin): Remove spurious quotation around %b in SumatraPDF entry. --- preview.el.in | 7 ++----- tex-buf.el | 38 ++++++++++++++++---------------------- tex.el | 19 ++++++++++++++----- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/preview.el.in b/preview.el.in index 1b24b5b..1aa7e1a 100644 --- a/preview.el.in +++ b/preview.el.in @@ -1622,11 +1622,8 @@ through `preview-region'." (unless (eq preview-state 'disabled) (preview-toggle ovr 'toggle (selected-window)) (throw 'exit t))))) - ;; Let-bind `TeX-source-correlate-mode' to nil in order to work around - ;; bug#26694. - (let ((TeX-source-correlate-mode nil)) - (preview-region (preview-next-border t) - (preview-next-border nil)))))) + (preview-region (preview-next-border t) + (preview-next-border nil))))) (defun preview-disabled-string (ov) "Generate a before-string for disabled preview overlay OV." diff --git a/tex-buf.el b/tex-buf.el index c39d059..fa92335 100644 --- a/tex-buf.el +++ b/tex-buf.el @@ -492,6 +492,11 @@ been set." (setq TeX-current-process-region-p t)) ((eq file #'TeX-master-file) (setq TeX-current-process-region-p nil))) + + ;; When we're operating on a region, we need to update the position + ;; of point in the region file so that forward search works. + (if (string= name "View") (TeX-region-update-point)) + (let ((command (TeX-command-expand (nth 1 (assoc name TeX-command-list)) file)) (hook (nth 2 (assoc name TeX-command-list))) @@ -899,18 +904,22 @@ QUEUE is non-nil when we are checking for the printer queue." 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 +Do nothing in case the last command hasn't operated on the region +or `TeX-source-correlate-mode' is disabled." + (when (and TeX-current-process-region-p TeX-source-correlate-mode) (let ((region-buf (get-file-buffer (TeX-region-file t))) - (current-line (TeX-line-number-at-pos))) + (orig-line (TeX-current-offset)) + (pos-in-line (- (point) (max (line-beginning-position) + (or TeX-command-region-begin + (region-beginning)))))) (when region-buf (with-current-buffer region-buf (goto-char (point-min)) - (when (re-search-forward "!offset(\\(-?[0-9]+\\)") + (when (re-search-forward "!offset(\\(-?[0-9]+\\)" nil t) (let ((offset (string-to-number (match-string 1)))) (goto-char (point-min)) - (forward-line (- current-line (1+ offset)))))))))) + (forward-line (- orig-line offset)) + (forward-char pos-in-line)))))))) (defun TeX-view () "Start a viewer without confirmation. @@ -919,11 +928,7 @@ depending on the last command issued." (interactive) (let ((output-file (TeX-active-master (TeX-output-extension)))) (if (file-exists-p output-file) - (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)) + (TeX-command "View" 'TeX-active-master 0) (message "Output file %S does not exist." output-file)))) (defun TeX-output-style-check (styles) @@ -2142,17 +2147,6 @@ original file." ") }\n" trailer) (setq TeX-region-orig-buffer orig-buffer) - ;; Position point at the line/col that corresponds to point's line in - ;; orig-buffer in order to make forward search work. Move point only - ;; when `TeX-source-correlate-mode' is non-nil, in order to work around - ;; bug#26694. - (when TeX-source-correlate-mode - (let ((line-col (with-current-buffer orig-buffer - (cons (TeX-line-number-at-pos) - (current-column))))) - (goto-char (point-min)) - (forward-line (1- (abs (- header-offset (car line-col))))) - (forward-char (cdr line-col)))) (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 eed4093..aeaf67c 100644 --- a/tex.el +++ b/tex.el @@ -1335,7 +1335,13 @@ DE is the name of the desktop environment, either \"gnome\" or (format "org.%s.%s.Window" de app) "SyncView" (buffer-file-name) - (list :struct :int32 (TeX-line-number-at-pos) + (list :struct :int32 (1+ (TeX-current-offset)) + ;; FIXME: Using `current-column' here is dubious. + ;; Most of CJK letters count as occupying 2 columns, + ;; so the column number is not equal to the number of + ;; the characters counting from the beginning of a + ;; line. What is the right number to specify here? + ;; number of letters? bytes in UTF8? or other? :int32 (1+ (current-column))) :uint32 0)) (error "Couldn't find the %s instance for %s" (capitalize app) uri)))) @@ -1385,7 +1391,7 @@ DE is the name of the desktop environment, either \"gnome\" or "%d" (mode-io-correlate " \"# %n '%b'\"")) "dviout") ("SumatraPDF" ("SumatraPDF -reuse-instance" - (mode-io-correlate " -forward-search \"%b\" %n") " %o") + (mode-io-correlate " -forward-search %b %n") " %o") "SumatraPDF") ("dvips and start" "dvips %d -o && start \"\" %f" "dvips") ("start" "start \"\" %o"))) @@ -2090,11 +2096,14 @@ enabled and the `synctex' binary is available." (let ((synctex-output (with-output-to-string (call-process "synctex" nil (list standard-output nil) nil "view" - "-i" (format "%s:%s:%s" (TeX-line-number-at-pos) - (current-column) + "-i" (format "%s:%s:%s" (1+ (TeX-current-offset)) + ;; FIXME: Using `current-column' + ;; here is dubious. See comment in + ;; `TeX-evince-sync-view-1'. + (1+ (current-column)) file) "-o" (TeX-active-master (TeX-output-extension)))))) - (when (string-match "Page:\\([0-9]+\\)" synctex-output) + (when (string-match "^Page:\\([0-9]+\\)" synctex-output) (match-string 1 synctex-output)))) (defun TeX-synctex-output-page ()