Adjust behavior of TeX-font

master
Jacopo De Simoi 6 years ago
parent c7927fccb4
commit 1c2faf77f8
  1. 60
      global.org

@ -1449,6 +1449,66 @@
(run-hook-with-args 'LaTeX-after-insert-env-hooks (run-hook-with-args 'LaTeX-after-insert-env-hooks
environment env-start env-end))) environment env-start env-end)))
#+END_SRC #+END_SRC
*** Patch auctex
I don't particularly like the way that the prefix arguments works
with font selection. The function below patches the annoying
behavior, by defaulting to the default behavior if the prefix
argument is 0
#+BEGIN_SRC emacs-lisp
(defun wilder/TeX-font (replace what)
"Insert template for font change command.
If REPLACE is not nil, replace current font. WHAT determines the font
to use, as specified by `TeX-font-list'."
(interactive "*P\nc")
(TeX-update-style)
(let* ((entry (assoc what TeX-font-list))
(in-math (texmathp))
(before (nth 1 entry))
(after (nth 2 entry)))
(setq replace (or replace (eq t (nth 3 entry)) (eq t (nth 5 entry))))
(if (and in-math (stringp (nth 3 entry)))
(setq before (nth 3 entry)
after (nth 4 entry)))
(setq arg (prefix-numeric-value replace))
(cond
((null entry)
(let ((help (concat
"Font list: "
"KEY TEXTFONT MATHFONT\n\n"
(mapconcat 'TeX-describe-font-entry
TeX-font-list "\n"))))
(with-output-to-temp-buffer "*Help*"
(set-buffer "*Help*")
(insert help))))
((and replace (eq 0 arg))
(funcall TeX-font-replace-function before after))
((and replace (< arg 0) )
(progn
(save-excursion
(backward-sexp (- 0 arg))
(insert before))
(insert after)))
((and replace (> arg 0))
(insert before)
(save-excursion
(forward-sexp arg)
(insert after)))
((TeX-active-mark)
(save-excursion
(cond ((> (mark) (point))
(insert before)
(goto-char (mark))
(insert after))
(t
(insert after)
(goto-char (mark))
(insert before)))))
(t
(insert before)
(save-excursion
(insert after))))))
(advice-add 'TeX-font :override #'wilder/TeX-font)
#+END_SRC
*** The hook *** The hook
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(add-hook 'LaTeX-mode-hook (add-hook 'LaTeX-mode-hook

Loading…
Cancel
Save