diff options
| author | BardofSprites <[email protected]> | 2026-01-20 10:18:44 -0500 |
|---|---|---|
| committer | BardofSprites <[email protected]> | 2026-01-20 10:18:44 -0500 |
| commit | dae7521ccf53e68a370d4051d6909d38d4ac2ad0 (patch) | |
| tree | 62cdde6a5f33d08dedae29913c2129a0937a298d /bard-emacs-modules/bard-emacs-writing.el | |
| parent | 8d91ee4fa386943b5952da1055cff3b2ae4540ed (diff) | |
enhanced LaTeX editing
Diffstat (limited to 'bard-emacs-modules/bard-emacs-writing.el')
| -rw-r--r-- | bard-emacs-modules/bard-emacs-writing.el | 54 |
1 files changed, 53 insertions, 1 deletions
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 + ("<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))))) + (use-package denote :ensure t :config |
