News for hackers. Stuff that matters.
Re:Emacs Info Expressions by submeta on Monday April 15, 2024 @11:40AM (#40042029)
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))))))))
## Edit

Emacs just rocks!

Re:Emacs Info Expressions by edrx on Tuesday April 16, 2024 @10:34PM (#40059830)
In eev I use M-e as a shorthand for C-e C-x C-e, but highlighting is optional and only happens when I type M-0 M-e... take a look:

http://anggtwu.net/eev-intros/find-eev-quick-intro.html#2

http://anggtwu.net/eev-intros/find-eev-quick-intro.html#3