Implement override advice toggling of TeX-brace-count-line

This commit is contained in:
Gerard Vermeulen 2022-04-22 06:34:58 +02:00
parent 3a17276629
commit 5245248921

View File

@ -590,9 +590,14 @@ defined in this Org file.
(with-eval-after-load 'shortdoc (with-eval-after-load 'shortdoc
;; Ensure defining the functions before documenting them. ;; Ensure defining the functions before documenting them.
(define-short-documentation-group init (define-short-documentation-group init
"Advice"
(toggle-advice :no-manual t)
"Face" "Face"
(invert-default-face :no-manual t) (invert-default-face :no-manual t)
(set-default-face-height :no-manual t) (set-default-face-height :no-manual t)
"LaTeX"
(TeX-brace-count-line-override :no-manual t)
(toggle-TeX-brace-count-line-override :no-manual t)
"Org" "Org"
(by-backend :no-manual t) (by-backend :no-manual t)
(by-backend-kbd-org-macro :no-manual t) (by-backend-kbd-org-macro :no-manual t)
@ -1226,7 +1231,10 @@ Loading =tex.el= immediately instead of lazily ensures proper initialization of
elisp library file has no autoload cookie. Without prior loading of =tex.el=, elisp library file has no autoload cookie. Without prior loading of =tex.el=,
Emacs will complain that ~TeX-master~ is no safe local variable in case it reads Emacs will complain that ~TeX-master~ is no safe local variable in case it reads
a LaTeX file that sets ~TeX-master~. Listing [[lst:require-auctex]] initializes a LaTeX file that sets ~TeX-master~. Listing [[lst:require-auctex]] initializes
[[https://en.wikipedia.org/wiki/AUCTeX][AUCTeX]] properly for LuaTeX or LuaLaTeX. [[https://en.wikipedia.org/wiki/AUCTeX][AUCTeX]] properly for LuaTeX or LuaLaTeX. Finally, out of the box, [[https://en.wikipedia.org/wiki/AUCTeX][AUCTeX]] does
not indent text between square brackets. The code in listing [[lst:configure-auctex]]
corrects this by advising to override ~TeX-brace-count-line~ with
~TeX-brace-count-line-advice~.
#+caption[Require =AUCTeX=]: #+caption[Require =AUCTeX=]:
#+caption: Require =AUCTeX=. #+caption: Require =AUCTeX=.
@ -1238,61 +1246,19 @@ a LaTeX file that sets ~TeX-master~. Listing [[lst:require-auctex]] initializes
'(TeX-auto-save t) '(TeX-auto-save t)
'(TeX-engine 'luatex) '(TeX-engine 'luatex)
'(TeX-install-font-lock #'font-latex-setup) '(TeX-install-font-lock #'font-latex-setup)
'(TeX-parse-self t))) '(TeX-parse-self t)
#+end_src
Listing [[lst:configure-bibtex]] configures the Emacs =bibtex= library to use the
LaTeX =BiBTeX= dialect for backwards compatibility.
#+caption[Configure =bibtex=]:
#+caption: Configure =bibtex=.
#+name: lst:configure-bibtex
#+begin_src emacs-lisp
(with-eval-after-load 'bibtex
(custom-set-variables '(bibtex-dialect 'BibTeX)))
#+end_src
Listing [[lst:configure-font-latex]] disables font scaling of section titles.
#+caption[Configure =font-latex=]:
#+caption: Configure =font-latex=.
#+name: lst:configure-font-latex
#+begin_src emacs-lisp
(with-eval-after-load 'font-latex
(custom-set-variables
'(font-latex-fontify-sectioning 1.0)))
#+end_src
Listing [[lst:configure-latex]] configures =latex= for a full featured
=LaTeX-section-command=. Finally, out of the box, [[https://en.wikipedia.org/wiki/AUCTeX][AUCTeX]] does not indent text
between square brackets. The code in listing [[lst:configure-tex]] corrects this by
advising to override ~TeX-brace-count-line~ with ~my-TeX-brace-count-line~.
#+caption[Configure =latex=]:
#+caption: Configure =latex=.
#+name: lst:configure-latex
#+begin_src emacs-lisp
(with-eval-after-load 'latex
(custom-set-variables
'(LaTeX-section-hook '(LaTeX-section-heading
LaTeX-section-title
LaTeX-section-toc
LaTeX-section-section
LaTeX-section-label))))
#+end_src
#+caption[Configure =TeX=]:
#+caption: Configure =TeX=.
#+name: lst:configure-tex
#+begin_src emacs-lisp
(with-eval-after-load 'tex
(custom-set-variables
;; Disable `TeX-electric-math' to prevent collisions with `smartparens'. ;; Disable `TeX-electric-math' to prevent collisions with `smartparens'.
'(TeX-electric-math nil)) '(TeX-electric-math nil)))
#+end_src
;; https://emacs.stackexchange.com/questions/17396/ #+caption[Configure =AUCTeX=]:
;; indentation-in-square-brackets #+caption: Configure =AUCTeX=.
(defun my-TeX-brace-count-line () #+name: lst:configure-auctex
#+begin_src emacs-lisp
(when (require 'tex nil 'noerror)
;; https://emacs.stackexchange.com/a/35507 answers:
;; How to indent between square brackets?
(defun TeX-brace-count-line-override ()
"Count number of open/closed braces." "Count number of open/closed braces."
(save-excursion (save-excursion
(let ((count 0) (limit (line-end-position)) char) (let ((count 0) (limit (line-end-position)) char)
@ -1314,7 +1280,58 @@ advising to override ~TeX-brace-count-line~ with ~my-TeX-brace-count-line~.
(forward-char) t)))))) (forward-char) t))))))
count))) count)))
(advice-add 'TeX-brace-count-line :override #'my-TeX-brace-count-line)) (defun toggle-advice (symbol where function &optional props)
"Toggle between states after `advice-remove' and `advice-add'."
(let ((how "%s `%s' advice `%s' %s `%s'"))
(if (advice-member-p function symbol)
(progn
(message how "Removal of" where function "from" symbol)
(advice-remove symbol function))
(message how "Addition of" where function "to" symbol)
(advice-add symbol where function props))))
(defun toggle-TeX-brace-count-line-override ()
"Toggle `TeX-brace-count-line-override' advice."
(interactive)
(toggle-advice #'TeX-brace-count-line-advice :override 'TeX-brace-count-line))
(toggle-TeX-brace-count-line-override))
#+end_src
Listing [[lst:configure-bibtex]] configures the Emacs =bibtex= library to use the
LaTeX =BiBTeX= dialect for backwards compatibility. Listing
[[lst:configure-font-latex]] disables font scaling of section titles. Listing
[[lst:configure-latex]] configures =latex= for a full featured
=LaTeX-section-command=.
#+caption[Configure =bibtex=]:
#+caption: Configure =bibtex=.
#+name: lst:configure-bibtex
#+begin_src emacs-lisp
(with-eval-after-load 'bibtex
(custom-set-variables '(bibtex-dialect 'BibTeX)))
#+end_src
#+caption[Configure =font-latex=]:
#+caption: Configure =font-latex=.
#+name: lst:configure-font-latex
#+begin_src emacs-lisp
(with-eval-after-load 'font-latex
(custom-set-variables
'(font-latex-fontify-sectioning 1.0)))
#+end_src
#+caption[Configure =latex=]:
#+caption: Configure =latex=.
#+name: lst:configure-latex
#+begin_src emacs-lisp
(with-eval-after-load 'latex
(custom-set-variables
'(LaTeX-section-hook '(LaTeX-section-heading
LaTeX-section-title
LaTeX-section-toc
LaTeX-section-section
LaTeX-section-label))))
#+end_src #+end_src
*** [[https://gitlab.com/matsievskiysv/math-preview/-/blob/master/README.md][Math-preview]] *** [[https://gitlab.com/matsievskiysv/math-preview/-/blob/master/README.md][Math-preview]]