Expand latex snippets in org-mode fragments on TAB

This commit is contained in:
Henrik Lissner 2021-07-24 19:43:51 -04:00
parent 017ada67c4
commit ce905b9246

View file

@ -417,11 +417,14 @@ Made for `org-tab-first-hook' in evil-mode."
(defun +org-yas-expand-maybe-h () (defun +org-yas-expand-maybe-h ()
"Expand a yasnippet snippet, if trigger exists at point or region is active. "Expand a yasnippet snippet, if trigger exists at point or region is active.
Made for `org-tab-first-hook'." Made for `org-tab-first-hook'."
(when (featurep! :editor snippets) (when (and (featurep! :editor snippets)
(require 'yasnippet) (require 'yasnippet nil t)
(and (let ((major-mode (if (org-in-src-block-p t) (bound-and-true-p yas-minor-mode))
(org-src-get-lang-mode (org-eldoc-get-src-lang)) (and (let ((major-mode (cond ((org-in-src-block-p t)
major-mode)) (org-src-get-lang-mode (org-eldoc-get-src-lang)))
((org-inside-LaTeX-fragment-p)
'latex-mode)
(major-mode)))
(org-src-tab-acts-natively nil) ; causes breakages (org-src-tab-acts-natively nil) ; causes breakages
;; Smart indentation doesn't work with yasnippet, and painfully slow ;; Smart indentation doesn't work with yasnippet, and painfully slow
;; in the few cases where it does. ;; in the few cases where it does.
@ -429,6 +432,9 @@ Made for `org-tab-first-hook'."
(cond ((and (or (not (bound-and-true-p evil-local-mode)) (cond ((and (or (not (bound-and-true-p evil-local-mode))
(evil-insert-state-p) (evil-insert-state-p)
(evil-emacs-state-p)) (evil-emacs-state-p))
(or (and (bound-and-true-p yas--tables)
(gethash major-mode yas--tables))
(progn (yas-reload-all) t))
(yas--templates-for-key-at-point)) (yas--templates-for-key-at-point))
(yas-expand) (yas-expand)
t) t)