Fix yasnippet expansion in org src blocks

This is hacky, and causes weirdness with org-bullets-mode, but it works.
This commit is contained in:
Henrik Lissner 2020-01-01 20:59:58 -05:00
parent d0380c42e7
commit 07823d00a7
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 23 additions and 15 deletions

View file

@ -374,18 +374,26 @@ Made for `org-tab-first-hook' in evil-mode."
"Tries to expand a yasnippet snippet, if one is available. Made for
`org-tab-first-hook'."
(when (bound-and-true-p yas-minor-mode)
(cond ((and (or (not (bound-and-true-p evil-local-mode))
(evil-insert-state-p))
(yas--templates-for-key-at-point))
(call-interactively #'yas-expand)
t)
((use-region-p)
;; Triggering mode-specific indentation is expensive in src blocks
;; (if `org-src-tab-acts-natively' is non-nil), and can cause errors,
;; so we avoid smart indentation in this case.
(let ((yas-indent-line 'fixed))
(call-interactively #'yas-insert-snippet))
t))))
(let ((major-mode (if (org-in-src-block-p t)
(org-src-get-lang-mode (org-eldoc-get-src-lang))
major-mode))
(org-src-tab-acts-natively nil) ; causes breakages
;; Smart indentation doesn't work with yasnippet, and painfully slow
;; in the few cases where it does.
(yas-indent-line 'fixed))
;; HACK Yasnippet field overlays break org-bullet-mode. Don't ask me why.
(add-hook! 'yas-after-exit-snippet-hook :local
(when (bound-and-true-p org-bullets-mode)
(org-bullets-mode -1)
(org-bullets-mode +1)))
(cond ((and (or (not (bound-and-true-p evil-local-mode))
(evil-insert-state-p))
(yas--templates-for-key-at-point))
(yas-expand)
t)
((use-region-p)
(yas-insert-snippet)
t)))))
;;;###autoload
(defun +org-cycle-only-current-subtree-h (&optional arg)