Hitting C-x n C-h
gives a short overview of what narrowing commands are there available in Emacs. Unfortunately, narrow-to-defun
does not (as I hoped) narrow to the current environment in LaTeX. This is Emacs, however, so why not fix this problem? Here’s a LaTeX-narrow-to-environment
function I wrote some time ago.
(defun LaTeX-narrow-to-environment (&optional count) "Narrow buffer to current LaTeX environment (or COUNT environments around point)" (interactive "p") (LaTeX-mark-environment count) (narrow-to-region (save-excursion (goto-char (region-beginning)) (beginning-of-line) (point)) (region-end)) (deactivate-mark))
I decided that C-x n e
is a natural binding:
(eval-after-load 'latex '(define-key LaTeX-mode-map (kbd "C-x n e") 'LaTeX-narrow-to-environment))
(The eval-after-load
form is needed in my init.el
, because LaTeX-mode-map
is not actually defined until loading latex.el
.)
As can be seen, it is basically a wrapper around LaTeX-mark-environment
– it even accepts the prefix argument of how many environments up the syntax tree it should go.
Happy TeXing!