TransWikia.com

Inverse search on AUCTeX opens file in new Emacs window instead of main Emacs window - how to avoid that?

TeX - LaTeX Asked by Benedikt Ahrens on June 19, 2021

I am using Emacs+auctex+evince on Debian. Suppose I have a latex document main.tex which includessections/sec1.tex. When compiling with C-c C-a from within main.tex and using backwards search in Section 1, Emacs opens sections/sec1.tex within a new Emacs window (Ew) (but within the same window in the sense of the window manager, aka frame in Emacs speak, see https://emacs.stackexchange.com/questions/13583/whats-the-difference-between-a-buffer-a-file-a-window-and-a-frame). That is, the Ew showing main.tex is halved in size, a new Ew is created in the spare space, and I am seeing both main.tex and sec1.tex.

I would like to avoid that, instead having the file opened in the Ew that showed main.tex before.

I am using Emacs on Debian stable:

GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
 of 2019-09-22, modified by Debian 

The undesired behaviour is shown with a virgin configuration, hence does not seem to be caused by any customization I am using.

2 Answers

As noted in a comment, the answer

(setq same-window-regexps '(".tex$"))

has the unintended consequence of breaking the AucTeX commands C-c C-l and C-c C-` . One way to fix this is to restrict the new value of same-window-regexps to TeX-mode buffers, i.e. replace the above line with

(add-hook 'LaTeX-mode-hook
           '(lambda () (set (make-local-variable 'same-window-regexps) '(".tex$"))))

However, this restricts it as a solution to the original problem so that it only works when Emacs is currently viewing some TeX file; if the current buffer is a different mode, then reverse-search opens in a separate Emacs-window.

A different solution that seems to work in all cases is to keep the original global (setq same-window-regexps '(".tex$")), but trick C-c C-l and C-c C-` into telling TeX-pop-to-buffer to always open in another window:

(defun TeX-force-pop-to-buffer-other-window (orig-fun buffer &optional other-window norecord)
  (funcall orig-fun buffer t norecord))
(defun TeX-force-pop-in-other-window (orig-fun &rest rest)
  "Don't depend on `pop-to-buffer' using a different window."
  (advice-add 'TeX-pop-to-buffer :around 'TeX-force-pop-to-buffer-other-window)
  (apply orig-fun rest)
  (advice-remove 'TeX-pop-to-buffer 'TeX-force-pop-to-buffer-other-window))  
(advice-add 'TeX-help-error :around 'TeX-force-pop-in-other-window)
(advice-add 'TeX-recenter-output-buffer :around 'TeX-force-pop-in-other-window)

Correct answer by Mike Shulman on June 19, 2021

A solution to this question, provided by Mike Shulman, is to use

(setq same-window-regexps '(".tex$"))

Answered by Benedikt Ahrens on June 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP