This is interesting. Just yesterday I asked myself how I can embed links to info nodes in a markdown file. I realized it's easiest to just put the expression in my file like so:
(info "(elisp) Hash Tables")
(info "(elisp) Cons Cells")
(info "(elisp) Vectors")
Then I asked myself how I can run it without going to the last parenthesis and then hitting C-x C-e, so I wrote a function: ;;;; eval expression at point in text / markdown
(defun ugt-eval-expression-at-point ()
"Evaluate the expression at the current point."
(interactive)
(save-excursion
(while (ignore-errors (backward-up-list) t)) ; Move to the beginning of the outermost sexp
(let ((end (point)))
(forward-sexp) ; Move to the end of this sexp
(eval-region end (point)))))
(global-set-key (kbd "C-s-e") 'ugt-eval-outermost-sexp-at-point)
So now I can be in between the parentheses and hit C-s-e (Control-Command-e), and it will be evaluated.I even embed search expressions in my documents:
(ugt-search "French Revolution")
So be able to just click those expressions, I created another function: ;;;; highlight s-expressions
(defun ugt-highlight-expressions ()
"Make expressions starting with '(' and ending with ')' highlighted."
(interactive)
(save-excursion
(goto-char (point-min))
(let ((expression-regex "\\((.*?)\\)"))
(while (re-search-forward expression-regex nil t)
(let* ((start (match-beginning 0))
(end (match-end 0))
(expression (match-string-no-properties 0)))
(let ((overlay (make-overlay start end)))
(overlay-put overlay 'face '(:foreground "#8FBFDC" :weight bold))
(overlay-put overlay 'help-echo (concat "Click to evaluate: " expression))
(overlay-put overlay 'mouse-face 'highlight)
(overlay-put overlay 'keymap (let ((map (make-sparse-keymap)))
(define-key map [mouse-1]
`(lambda ()
(interactive)
(let ((expr ,expression))
(eval (read expr))
(message "Evaluated expression: %s" expr))))
map))))))))
## EditEmacs just rocks!