From dae7521ccf53e68a370d4051d6909d38d4ac2ad0 Mon Sep 17 00:00:00 2001 From: BardofSprites <89086143+BardofSprites@users.noreply.github.com> Date: Tue, 20 Jan 2026 10:18:44 -0500 Subject: enhanced LaTeX editing --- bard-emacs-modules/bard-emacs-writing.el | 54 +++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'bard-emacs-modules/bard-emacs-writing.el') diff --git a/bard-emacs-modules/bard-emacs-writing.el b/bard-emacs-modules/bard-emacs-writing.el index 317dd42..1daed2a 100644 --- a/bard-emacs-modules/bard-emacs-writing.el +++ b/bard-emacs-modules/bard-emacs-writing.el @@ -29,10 +29,25 @@ (use-package yasnippet :ensure t + :hook ((LaTeX-mode . yas-minor-mode) + (post-self-insert . my/yas-try-expanding-auto-snippets)) :config (setq yas-snippet-dirs '("~/.emacs.d/snippets")) (yas-global-mode t) - ) + (use-package warnings + :config + (cl-pushnew '(yasnippet backquote-change) + warning-suppress-types + :test 'equal)) + + (setq yas-triggers-in-field t) + + ;; Function that tries to autoexpand YaSnippets + ;; The double quoting is NOT a typo! + (defun my/yas-try-expanding-auto-snippets () + (when (and (boundp 'yas-minor-mode) yas-minor-mode) + (let ((yas-buffer-local-condition ''(require-snippet-condition . auto))) + (yas-expand))))) (use-package yasnippet-capf :ensure t @@ -40,6 +55,43 @@ :config (add-to-list 'completion-at-point-functions #'yasnippet-capf)) +(use-package cdlatex + :hook ((cdlatex-tab . yas-expand) + (cdlatex-tab . cdlatex-in-yas-field)) + :config + (use-package yasnippet + :bind (:map yas-keymap + ("" . 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))))) + (use-package denote :ensure t :config -- cgit v1.2.3