summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-01-29 17:47:42 -0500
committerKyle Meyer <kyle@kyleam.com>2014-01-29 17:47:42 -0500
commit0a34ba8d6f769b730ab3bbf444bfc0b4756e5426 (patch)
tree83dacb95a4fbba04c4952b54d96967fda3cb4031 /lisp
parent01ec43ca3054f67bf057b728102aec0d165689e0 (diff)
downloademacs.d-0a34ba8d6f769b730ab3bbf444bfc0b4756e5426.tar.gz
Add LaTeX narrowing functions
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-tex.el46
1 files changed, 46 insertions, 0 deletions
diff --git a/lisp/init-tex.el b/lisp/init-tex.el
index 10539c0..b2f4d0f 100644
--- a/lisp/init-tex.el
+++ b/lisp/init-tex.el
@@ -15,4 +15,50 @@
(setq reftex-default-bibliography '("~/refs/refs.bib"))
+(defun km/latex-narrow-to-single-tag (&optional tag)
+ "Narrow region to LaTeX tag.
+This is meant for single elements, like \"\\section\". If TAG is
+not given, it is taken from the active region."
+ (interactive)
+ (save-excursion
+ (let* ((tag (or tag
+ (buffer-substring-no-properties (mark) (point))))
+ (tag (if (s-starts-with? "\\" tag)
+ tag
+ (concat "\\" tag)))
+ (beg (progn (end-of-line)
+ (search-backward tag)))
+ (end (progn (forward-line 1)
+ (unless (search-forward tag nil t)
+ (search-forward "\\end{document}"))
+ (forward-line -1)
+ (point))))
+ (narrow-to-region beg end))))
+
+(defun km/latex-narrow-to-paired-tag (&optional tag)
+ "Narrow region to LaTeX tag.
+This is meant for paired, like \"\\begin{document}\". If TAG is
+not given, it is taken from the active region."
+ (interactive)
+ (save-excursion
+ (let* ((tag (or tag
+ (buffer-substring-no-properties (mark) (point))))
+ (beg (progn (end-of-line)
+ (search-backward (format "\\begin{%s}" tag))))
+ (end (progn (forward-line 1)
+ (search-forward (format "\\end{%s}" tag)))))
+ (narrow-to-region beg end))))
+
+(defun km/latex-narrow-to-document ()
+ "Narrow region to LaTeX document text.
+The point should be beyond \"\\begin{document}\"."
+ (interactive)
+ (km/latex-narrow-to-paired-tag "document"))
+
+(defun km/latex-narrow-to-section ()
+ "Narrow region to current LaTeX section.
+The point should be beyond \"\\section\"."
+ (interactive)
+ (km/latex-narrow-to-single-tag "section"))
+
(provide 'init-tex)