Xah Talk Show 2026-01-21 Ep748 emacs lisp, write command to eval selection, fsharp, JavaScript.

Video Summary (Generated by AI, Edited by Human.)

Write an Emacs Lisp command to evaluate selected regions of code, specifically for fsharp.

console.log( 3 + 4 )
let x = 3
printfn "%i" (x+4)

printfn "%i" (3+4 )
(defun xah-fsharp-eval-region (Begin End &optional zinsert-output zadd-print)
  "Eval the current region in dotnet fsi, print result in buffer *xah fsharp output*.
If there is no text selection, eval current text block.

If `universal-argument' is called first, insert result below the region.

Require the external command dotnet.

Created: 2026-01-21
Version: 2026-01-21"
  (interactive
   (let (xbeg xend)
     (if (region-active-p)
         (setq xbeg (region-beginning) xend (region-end))
       (let ((xp (point)))
         (save-excursion
           (setq xbeg (if (re-search-backward "\n[ \t]*\n" nil 1)
                          (match-end 0)
                        (point)))
           (goto-char xp)
           (setq xend (if (re-search-forward "\n[ \t]*\n" nil 1)
                          (match-beginning 0)
                        (point))))))
     (list xbeg xend current-prefix-arg)))
  (let ((xoutbuf (get-buffer-create "*xah fsharp output*")))
    (with-current-buffer xoutbuf (erase-buffer))
    (call-process-region Begin End "dotnet" nil xoutbuf t "fsi" "--quiet")
    (if zinsert-output
        (progn
          (goto-char End)
          (insert "\n")
          (insert-buffer-substring xoutbuf))
      (progn
        (display-buffer xoutbuf)))))