From 7985baf7b2279005d030f313e0673e82a08de930 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Mon, 8 Mar 2021 10:39:49 +0800 Subject: 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. --- tex-conf.el | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3-18-g5258