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:
parent
d0380c42e7
commit
07823d00a7
2 changed files with 23 additions and 15 deletions
|
@ -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
|
"Tries to expand a yasnippet snippet, if one is available. Made for
|
||||||
`org-tab-first-hook'."
|
`org-tab-first-hook'."
|
||||||
(when (bound-and-true-p yas-minor-mode)
|
(when (bound-and-true-p yas-minor-mode)
|
||||||
(cond ((and (or (not (bound-and-true-p evil-local-mode))
|
(let ((major-mode (if (org-in-src-block-p t)
|
||||||
(evil-insert-state-p))
|
(org-src-get-lang-mode (org-eldoc-get-src-lang))
|
||||||
(yas--templates-for-key-at-point))
|
major-mode))
|
||||||
(call-interactively #'yas-expand)
|
(org-src-tab-acts-natively nil) ; causes breakages
|
||||||
t)
|
;; Smart indentation doesn't work with yasnippet, and painfully slow
|
||||||
((use-region-p)
|
;; in the few cases where it does.
|
||||||
;; Triggering mode-specific indentation is expensive in src blocks
|
(yas-indent-line 'fixed))
|
||||||
;; (if `org-src-tab-acts-natively' is non-nil), and can cause errors,
|
;; HACK Yasnippet field overlays break org-bullet-mode. Don't ask me why.
|
||||||
;; so we avoid smart indentation in this case.
|
(add-hook! 'yas-after-exit-snippet-hook :local
|
||||||
(let ((yas-indent-line 'fixed))
|
(when (bound-and-true-p org-bullets-mode)
|
||||||
(call-interactively #'yas-insert-snippet))
|
(org-bullets-mode -1)
|
||||||
t))))
|
(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
|
;;;###autoload
|
||||||
(defun +org-cycle-only-current-subtree-h (&optional arg)
|
(defun +org-cycle-only-current-subtree-h (&optional arg)
|
||||||
|
|
|
@ -184,7 +184,7 @@ background (and foreground) match the current theme."
|
||||||
|
|
||||||
(defun +org-init-babel-h ()
|
(defun +org-init-babel-h ()
|
||||||
(setq org-src-preserve-indentation t ; use native major-mode indentation
|
(setq org-src-preserve-indentation t ; use native major-mode indentation
|
||||||
org-src-tab-acts-natively t
|
org-src-tab-acts-natively t ; we do this ourselves
|
||||||
;; You don't need my permission (just be careful, mkay?)
|
;; You don't need my permission (just be careful, mkay?)
|
||||||
org-confirm-babel-evaluate nil
|
org-confirm-babel-evaluate nil
|
||||||
org-link-elisp-confirm-function nil
|
org-link-elisp-confirm-function nil
|
||||||
|
@ -581,8 +581,8 @@ between the two."
|
||||||
org-insert-heading-respect-content t)
|
org-insert-heading-respect-content t)
|
||||||
|
|
||||||
(add-hook! 'org-tab-first-hook
|
(add-hook! 'org-tab-first-hook
|
||||||
#'+org-indent-maybe-h
|
#'+org-yas-expand-maybe-h
|
||||||
#'+org-yas-expand-maybe-h)
|
#'+org-indent-maybe-h)
|
||||||
|
|
||||||
(add-hook 'doom-delete-backward-functions
|
(add-hook 'doom-delete-backward-functions
|
||||||
#'+org-delete-backward-char-and-realign-table-maybe-h)
|
#'+org-delete-backward-char-and-realign-table-maybe-h)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue