Highlight evaluated SuperCollider code in Emacs
Someone on the Fediverse asked if it’s possible to have Emacs visually
highlight / flash the fragment of code that is currently evaluated in
SuperCollider (via scel). It is! Here’s the code I use in my init.el
to implement this, based on some example from some since-forgotten
corner of the Net:
(defun undltd/sclang-highlight-defun (&optional silent-p)
(cl-multiple-value-bind (beg end) (sclang-point-in-defun-p)
(and beg end (pulse-momentary-highlight-region beg end))))
(defun undltd/sclang-highlight-region-or-line (&optional silent-p)
(if (and transient-mark-mode mark-active)
(pulse-momentary-highlight-region (region-beginning) (region-end))
(pulse-momentary-highlight-one-line (point))))
(advice-add 'sclang-eval-defun :before #'undltd/sclang-highlight-defun)
(advice-add 'sclang-eval-region-or-line :before #'undltd/sclang-highlight-region-or-line)
(I tend to prefix all my custom functions with undltd/
to avoid
potential name clashes with other libraries in the future).