darwinsenior
darwinsenior

Reputation: 496

Evil mode hook with specific major mode?

Is it possible to hook evil-insert-enter-state and other states only within org-mode with the org-toggle-latex-fragment?

p.s.

finally the suggestions work. I currently have the following pieces that make the org mode automatically render the content when you are in the normal mode, but expand the content when you are in other modes.

(defun org-preview-all-latex-fragments ()
  "Toggle all the latex fragments."
     (org-toggle-latex-fragment '(16)))


(add-hook 'org-mode-hook (lambda ()
                           (add-hook 'evil-normal-state-entry-hook 'org-preview-all-latex-fragments nil t)
                           (add-hook 'evil-normal-state-exit-hook 'org-remove-latex-fragment-image-overlays nil t)))

Upvotes: 0

Views: 1109

Answers (1)

Henrik
Henrik

Reputation: 982

You could add buffer local hooks inside a org-mode hook:

(add-hook 'org-mode-hook
  (lambda ()
    (add-hook 'evil-insert-state-entry-hook 'org-toggle-latex-fragment nil t)))

The third argument of add-hook is the buffer-local flag.

(add-hook HOOK FUNCTION &optional APPEND LOCAL)

The problem with the above is that org-toggle-latex-fragment works differently depending on where the cursor is. If you mean to activate all latex fragments across the file, you may need to modify my suggestion slighty:

(defun org-toggle-all-latex-fragments ()
  (org-toggle-latex-fragment '(16)))

(add-hook 'org-mode-hook
  (lambda ()
    (add-hook 'evil-insert-state-entry-hook 'org-toggle-all-latex-fragments nil t)))

Upvotes: 1

Related Questions