``` refactor(tex,completion,edit): Reorganize LaTeX configuration

and cleanup

- Require init-tex module in main init.el Change marginalia
- initialization from hook to immediate mode activation Enable
- yasnippet globally in init-edit Remove unused init-snippet.el
- module Simplify init-tex.el by removing redundant
- cdlatex-yasnippet integration Add lexical binding and proper
- package demand configuration for AuCTeX Clean up commented code in
- init-org.el ```
This commit is contained in:
Zelong Kuang
2025-12-14 19:27:57 +11:00
parent 9e7872b4aa
commit 8b88b04c1b
7 changed files with 19 additions and 63 deletions

View File

@@ -60,7 +60,8 @@
;; Enrich existing commands with completion annotations
(use-package marginalia
:hook (after-init . marginalia-mode))
:init
(marginalia-mode))
;; Consulting completing-read
(use-package consult

View File

@@ -18,6 +18,7 @@
:hook ((LaTeX-mode . yas-minor-mode)
(post-self-insert . my/yas-try-expanding-auto-snippets))
:config
(yas-global-mode)
(use-package warnings
:config
(cl-pushnew '(yasnippet backquote-change)

View File

@@ -68,28 +68,14 @@
;; Increase preview width
(plist-put org-latex-preview-appearance-options
:page-width 0.8)
;; ;; Use dvisvgm to generate previews
;; ;; You don't need this, it's the default:
;; (setq org-latex-preview-process-default 'dvisvgm)
;; Turn on `org-latex-preview-mode', it's built into Org and much faster/more
;; featured than org-fragtog. (Remember to turn off/uninstall org-fragtog.)
;; ;; Block C-n, C-p etc from opening up previews when using `org-latex-preview-mode'
;; (setq org-latex-preview-mode-ignored-commands
;; '(next-line previous-line mwheel-scroll
;; scroll-up-command scroll-down-command))
;; ;; Enable consistent equation numbering
(setq org-latex-preview-numbered t)
;; Bonus: Turn on live previews. This shows you a live preview of a LaTeX
;; fragment and updates the preview in real-time as you edit it.
;; To preview only environments, set it to '(block edit-special) instead
(setq org-latex-preview-mode-display-live t)
;; More immediate live-previews -- the default delay is 1 second
(setq org-latex-preview-mode-update-delay 0.25))
(use-package org-roam

View File

@@ -1,10 +0,0 @@
(use-package! yasnippet
:config
(defun my-yas-try-expanding-auto-snippets ()
(when yas-minor-mode
(let ((yas-buffer-local-condition ''(require-snippet-condition . auto)))
(yas-expand))))
(add-hook 'post-command-hook #'my-yas-try-expanding-auto-snippets)
)
(provide 'init-snippet)

View File

@@ -1,7 +1,13 @@
;; -*- lexical-binding: t; -*-
(use-package latex
:ensure auctex
:demand t
:ensure (auctex :pre-build (("./autogen.sh")
("./configure" "--without-texmf-dir" "--with-lispdir=.")
("make")))
:mode (("\\.tex\\'" . LaTeX-mode))
:hook ((LaTeX-mode . prettify-symbols-mode))
:bind (:map LaTeX-mode-map
("C-S-e" . latex-math-from-calc))
@@ -29,39 +35,6 @@
:hook (LaTeX-mode . turn-on-cdlatex)
:bind (:map cdlatex-mode-map
("<tab>" . cdlatex-tab)))
(use-package cdlatex
:hook ((cdlatex-tab . yas-expand)
(cdlatex-tab . cdlatex-in-yas-field))
:config
(use-package yasnippet
:bind (:map yas-keymap
("<tab>" . yas-next-field-or-cdlatex)
("TAB" . yas-next-field-or-cdlatex))
:config
(defun cdlatex-in-yas-field ()
;; Check if we're at the end of the Yas field
(when-let* ((_ (overlayp yas--active-field-overlay))
(end (overlay-end yas--active-field-overlay)))
(if (>= (point) end)
;; Call yas-next-field if cdlatex can't expand here
(let ((s (thing-at-point 'sexp)))
(unless (and s (assoc (substring-no-properties s)
cdlatex-command-alist-comb))
(yas-next-field-or-maybe-expand)
t))
;; otherwise expand and jump to the correct location
(let (cdlatex-tab-hook minp)
(setq minp
(min (save-excursion (cdlatex-tab)
(point))
(overlay-end yas--active-field-overlay)))
(goto-char minp) t))))
(defun yas-next-field-or-cdlatex nil
(interactive)
"Jump to the next Yas field correctly with cdlatex active."
(if
(or (bound-and-true-p cdlatex-mode)
(bound-and-true-p org-cdlatex-mode))
(cdlatex-tab)
(yas-next-field-or-maybe-expand)))))
(provide 'init-tex)