diff options
author | JSDurand <mmemmew@gmail.com> | 2021-03-08 10:39:49 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2021-03-08 10:39:49 +0800 |
commit | 7985baf7b2279005d030f313e0673e82a08de930 (patch) | |
tree | 55c2a09e106051991c7a8b6307b8b4abe23737ff /tex-conf.el | |
parent | 9557f53e775ffa9e7f86dfa2371b856c60835cca (diff) |
More settings with LaTeX
* tex-conf.el (TeX-after-compilation-finished-functions): Revert the
PDF after compilation.
(pdf-sync-forward-display-action):
(pdf-sync-backward-display-action): Display the PDF in the same
window.
(TeX-source-correlate-start-server): Start syncronization between the
TeX buffer and the PDF buffer.
(font-latex-fontify-sectioning): Make sections bigger.
(LaTeX-mode-hook): Add my own preparation function.
(open-paren): Insert a pair of parentheses and put the cursor in
between.
(open-curly): Insert a pair of curly braces and put the cursor in
between.
(open-bracket): Insert a pair of square brackets and put the cursor in
between.
(durand-delete-pair): When the character before point is an open
bracket, delete the corresponding closing bracket as well.
(end-exit-paren): When the character after point is a closing bracket,
exit out of it instead of inserting a closing bracket.
(open-back-paren): If the character before point is a closing bracket,
go back one character into the brackets.
(parens-require-spaces): Don't require spaces around parentheses.
(durand-prepare-latex): Treat the escape character as a symbol, turn
on auto-fill, and don't require spaces around parentheses.
(durand-latex-delete-newline): Delete a newline before point, if any.
(LaTeX-section-hook): Delete the newline between the section and the
label, so that chktex doesn't complain about that space.
Diffstat (limited to 'tex-conf.el')
-rw-r--r-- | tex-conf.el | 130 |
1 files changed, 129 insertions, 1 deletions
diff --git a/tex-conf.el b/tex-conf.el index 4c5211d..be0ad34 100644 --- a/tex-conf.el +++ b/tex-conf.el @@ -35,7 +35,7 @@ (output-pdf "PDF Tools") (output-html "open"))) -;; I don't want to split the screen. +;;; I don't want to split the screen. ;;;###autoload (defun durand-TeX-pdf-tools-sync-view-a () @@ -56,9 +56,27 @@ (switch-to-buffer (or (find-buffer-visiting pdf) (find-file-noselect pdf)))))) +(add-hook 'TeX-after-compilation-finished-functions + #'TeX-revert-document-buffer) + +(setq pdf-sync-forward-display-action + (list (list 'display-buffer-same-window))) + +(setq pdf-sync-backward-display-action + (list (list 'display-buffer-same-window))) + (advice-add #'TeX-pdf-tools-sync-view :override #'durand-TeX-pdf-tools-sync-view-a) +;;; Correlate + +(setq TeX-source-correlate-start-server t) +(TeX-source-correlate-mode 1) + +;;; Section display + +(setq font-latex-fontify-sectioning 1.3) + ;;; Dollars (setq TeX-electric-math (cons "\\(" "\\)")) @@ -71,6 +89,116 @@ (interactive) (insert "\\")) +;;; Parens don't require space + +(add-hook 'LaTeX-mode-hook #'durand-prepare-latex) + +;;; Brackets handling + +(mapc + (function + (lambda (cell) + (define-key LaTeX-mode-map (vector (car cell)) (cdr cell)))) + (list + (cons ?\( #'open-paren) + (cons ?{ #'open-curly) + (cons ?\[ #'open-bracket) + (cons 'backspace #'durand-delete-pair) + (cons ?\) #'end-exit-paren) + (cons ?à #'open-back-paren))) + +;;;###autoload +(defun open-paren () + "open parenthesis inserts a matching pair" + (interactive) + (progn + (insert "()") + (backward-char))) + +;;;###autoload +(defun open-curly () + "open curly inserts a matching pair" + (interactive) + (progn + (insert "{}") + (backward-char))) + +;;;###autoload +(defun open-bracket () + "open bracket inserts a matching pair" + (interactive) + (progn + (insert "[]") + (backward-char))) + +;;;###autoload +(defun durand-delete-pair () + "Delete the matching pair" + (interactive) + (cond ((region-active-p) ; if the region is active, then do the original thing + (delete-backward-char 1)) + ((looking-back "\\(\\\\(\\|\\\\\\[\\)" (- (point) 2)) + (save-excursion + (backward-char 1) + (ignore-errors + (forward-sexp 1) + (delete-char -2))) + (delete-char -2)) + ((memq (char-before) '(?\( ?\[ ?\{)) + (save-excursion + (backward-char 1) + (ignore-errors + (forward-sexp 1) + (delete-char -1))) + (delete-char -1)) + (t + (backward-delete-char-untabify 1)))) + +;;;###autoload +(defun end-exit-paren () + "Use closing pasenthesis to exit the parenthesis" + (interactive) + (let ((ch (char-after nil)) + (ch-list '(?\) ?\} ?\] ?\$))) + (cond ((memq ch ch-list) (forward-char)) + ((looking-at-p "\\(\\\\)\\|\\\\]\\|\\\\}\\)") + (forward-char 2)) + (t (self-insert-command 1))))) + +;;;###autoload +(defun open-back-paren () + "Use \"à\" to go back to the parenthesis." + (interactive) + (let ((ch (char-before nil)) + (ch-list '(?\) ?\} ?\] ?\$))) + (cond ((looking-back "\\(\\\\)\\|\\\\]\\|\\\\}\\)" (- (point) 2)) + (forward-char -2)) + ((memq ch ch-list) (backward-char)) + (t (self-insert-command 1))))) + +(make-variable-buffer-local 'parens-require-spaces) + +;;;###autoload +(defun durand-prepare-latex () + "Prepare some settings in LateX mode." + (modify-syntax-entry ?\\ "_") + (turn-on-auto-fill) + (setq parens-require-spaces nil)) + +;;; Don't insert a new line between the section and the label. + +;;;###autoload +(defun durand-latex-delete-newline () + "If the character before point is a newline, then delete it." + (cond + ((= (char-before) ?\n) + (delete-char -1)))) + +(setq LaTeX-section-hook + '(LaTeX-section-heading LaTeX-section-title + LaTeX-section-section durand-latex-delete-newline + LaTeX-section-label)) + ;;; Expansions (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode) |