Skip to content

Instantly share code, notes, and snippets.

@ShingoFukuyama
Last active May 30, 2017 05:27
Show Gist options
  • Save ShingoFukuyama/9835808 to your computer and use it in GitHub Desktop.
Save ShingoFukuyama/9835808 to your computer and use it in GitHub Desktop.
Execute Emacs Lisp in org file when it's opened.
(setq my-org-init-elisp-beg "# elisp")
(setq my-org-init-elisp-end "# end")
(setq my-org-init-elisp-comment "^#")
(defun my-org-init-elisp ()
(save-excursion
(goto-char (point-min))
(while (re-search-forward my-org-init-elisp-beg nil t)
(let ($beg $end $elisp)
(forward-line 1)
(setq $beg (match-end 0))
(when (re-search-forward my-org-init-elisp-end nil t)
(setq $end (match-beginning 0))
(goto-char $beg)
(while (re-search-forward my-org-init-elisp-comment $end t)
(setq $elisp (cons (buffer-substring-no-properties
(match-end 0) (min (1+ (point-at-eol)) $end))
$elisp)))
(eval (read (concat "(progn" (apply 'concat (nreverse $elisp)) ")"))))))))
(add-hook 'org-mode-hook 'my-org-init-elisp)
;; Example
;; Write elisp like below in your org file
# elisp
# (highlight-regexp "elisp" 'hi-green)
# (highlight-regexp "high" 'hi-ping)
# (highlight-regexp
# "end"
# 'warning)
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment