Last active
May 30, 2017 05:27
-
-
Save ShingoFukuyama/9835808 to your computer and use it in GitHub Desktop.
Execute Emacs Lisp in org file when it's opened.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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