-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlatex-tweaks.el
71 lines (55 loc) · 2.29 KB
/
latex-tweaks.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;;; latex-tweaks.el --- A collection of tweaks for auctex. -*- lexical-binding: t; -*-
;; Copyright (C) 2017
;; Author: Jan Seeger <[email protected]>
;; Keywords: tex
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Enable all tweaks with (LaTeX-tweaks-insinuate).
;;; Code:
(defcustom LaTeX-inhibited-auto-fill-environments
'("tabular" "tikzpicture") "For which LaTeX environments not to run auto-fill.")
(defun LaTeX-limited-auto-fill ()
(let ((environment (LaTeX-current-environment)))
(when (not (member environment LaTeX-inhibited-auto-fill-environments))
(do-auto-fill))))
(defun LaTeX-dont-break-on-nbsp ()
(and (eq major-mode 'latex-mode)
(eq (char-before (- (point) 1)) ?\\)))
(defun LaTeX-collapse-table ()
(interactive)
(save-excursion
(LaTeX-mark-environment)
(while (re-search-forward "[[:space:]]+\\(&\\|\\\\\\\\\\)" (region-end) t)
(replace-match " \\1"))))
(defun LaTeX-align-environment (arg)
(interactive "P")
(if arg
(LaTeX-collapse-table)
(save-excursion
(LaTeX-mark-environment)
(align (region-beginning) (region-end)))))
(defun LaTeX-underscore-maybe (arg)
(interactive "p")
(if (eq last-command 'LaTeX-underscore-maybe)
(progn
(delete-backward-char 2)
(self-insert-command 1))
(if (or (or (> 1 arg) (texmathp)))
(self-insert-command 1)
(insert "\\_"))))
(defun LaTeX-tweaks-insinuate ()
(local-set-key (kbd "_" #'LaTeX-underscore-maybe))
(local-set-key (kbd "C-c f") #'LaTeX-align-environment)
(setq auto-fill-function #'LaTeX-limited-auto-fill)
(add-to-list 'fill-nobreak-predicate #'LaTeX-dont-break-on-nbsp))
(provide 'latex-tweaks)
;;; latex-tweaks.el ends here