What is your emacs configuration? (+ my personal bugs)

Hi folks,

I am quite new to emacs, but already convinced of the power of this tool.
I would be very interested if you could share some configurations (.el files) or tips that go with super-collider.
I am sure others would be curious as well !

Thanks in advance !

Great tool indeed.

I use Doom-Emacs (in evil-mode) with sclang and sclang-extensions packages.

It works great, both for developing and live coding in SC.

So far, I simply added the sclang package, and the following lines in my init.el (I am under Ubuntu)

(add-to-list 'load-path "~/.local/share/SuperCollider/downloaded-quarks/scel/el")
(require 'sclang)


I don’t really know what to add more, if there are additional tweaks that worth it and goes well with it.

  • Curiously, I systematically have a bug when working in emacs with a .sc file: After calling sclang-start then booting the server, when navigating through a document, the mini buffer throws me an error SCLang: Error in command handler, which only goes away when calling the function sclang-ac-mode (the auto complete mode).

  • When I add the package sclang-extension, I got other kind of errors when sclang-ac-mode is activated. When I type some code into the buffer, or simply move the cursor around the text, for example

{SinOsc.ar(440);}.play

the post window continuously throws me errors that look like

ERROR: Parse error
  in interpreted text
  line 1 char 30:

  try { Emacs.message((({SinOsc).class).asCompileString) } {|err| err;} 
                               ^
-----------------------------------
opening bracket was a '{', but found a ')'
  in interpreted text line 1 char 30
ERROR: syntax error, unexpected BADTOKEN, expecting '}'
  in interpreted text
  line 1 char 30:

  try { Emacs.message((({SinOsc).class).asCompileString) } {|err| err;} 
                               ^
-----------------------------------
ERROR: Command line parse failed
ERROR: Class not defined.
  in interpreted text
  line 1 char 37:

  try { Emacs.message((Meta_Meta_SinOsc.methods.collect {|m| [m.name, m.argList, m.ownerClass] }).asCompileString) } {|err| err;} 

Any idea?

I reduced my configuration in my init.el to these simple lines, and I still get the errors

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(unless package-archive-contents (package-refresh-contents))

(add-to-list 'load-path "/home/sly/.local/share/SuperCollider/downloaded-quarks/scel/el")
(require 'sclang)

(require 'sclang-extensions)
(add-hook 'sclang-mode-hook 'sclang-extensions-mode)

I did some digging, and found that the those error messages shown in the consol come when either of the following three modes are activated: sclang-ac-mode, sclang-doc-mode, sclang-extensions-mode. It looks like they appear when those modes should enter in action. For example, when finishing typing SinOsc., putting the last dot triggers the following error in the post window:

ERROR: Class not defined.
  in interpreted text
  line 1 char 37:

  try { Emacs.message((Meta_Meta_SinOsc.superclasses).asCompileString) } {|err| err;} 

The only solution so far is to disable sclang-extension-mode, and all the other modes.

Just using this thread to revive it and ask a related question.

I played around with emacs and SC today and I got it running, including simple auto completion.
As I want to learn SC I thought it’s a good idea to also get used to emacs (or nvim). Meanwhile I prefer emacs. The configuration of emacs turned out to be simpler in my opinion.

What I did: I followed the instructions of the git page ( GitHub - supercollider/scel: Supercollider emacs package ) and first installed the emacs quark manually in the scIDE as suggested in option 1.

Then I adjusted the paths in my init.el file (see below). In the default configuration the post window was opened on the bottom and with the help of this forum and chatGPT I was able to open it on the right like in scIDE.

The help browser can be opened with C-c h .

For auto completion I installed company with the melpa package manager. This worked out of the box. The init file was adjusted with chatGPT.

Two things I’m currently still missing:

  1. In the default scIDE I get suggestions for the arguments after entering e.g. SinOsc.ar( . Is this also working in emacs? I watched some youtube videos (e.g. https://www.youtube.com/watch?v=n01nAN4I8wM ) and this does not seem to be the case. edit: also this works. With C-c RET it is shown on the bottom of the page.

  2. Is it possible to execute a code block embraced in (…) with one command?
    edit: it’s working with C-M-x (Ctrl + Alt + x) :slight_smile:

BTW. Installing the emacs extensions from here: GitHub - chrisbarrett/sclang-extensions: UNMAINTAINED made the configuration unusable. This seems to be outdated meanwhile or I just did it wrong. After deleting the package it worked again.

;; ------------------------
;; Package Manager Setup
;; ------------------------
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

;; Ensure use-package is installed
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(require 'use-package)

;; ------------------------
;; Startup UI
;; ------------------------
(setq inhibit-startup-screen t)   ;; disable welcome screen
(setq initial-scratch-message "") ;; empty scratch buffer

;; ------------------------
;; Theme
;; ------------------------
(use-package dracula-theme
  :ensure t
  :config
  (load-theme 'dracula t))

;; ------------------------
;; Company-mode (autocomplete)
;; ------------------------
(use-package company
  :ensure t
  :hook (after-init . global-company-mode)
  :config
  (setq company-idle-delay 0.2        ;; show completions after 0.2 sec
        company-minimum-prefix-length 1))

;; Configure company for SuperCollider specifically
(add-hook 'sclang-mode-hook
          (lambda ()
            (company-mode 1)
            (setq-local company-backends
                        '(company-capf company-dabbrev-code))
            (setq sclang-autocomplete-enable t)))

;; ------------------------
;; SuperCollider Emacs Integration
;; ------------------------
;; Adjust this path to where you installed the SC Quark 'scel'
(add-to-list 'load-path "~/.local/share/SuperCollider/downloaded-quarks/scel/el")
(require 'sclang)

;; Associate .scd and .sc files automatically
(add-to-list 'auto-mode-alist '("\\.scd$" . sclang-mode))
(add-to-list 'auto-mode-alist '("\\.sc$" . sclang-mode))

;; Move PostBuffer to right side window
(add-to-list 'display-buffer-alist
             '("\\*SCLang:PostBuffer\\*"
               (display-buffer-in-side-window)
               (side . right)
               (window-width . 30)))

;; ------------------------
;; Custom-set Variables (generated by Emacs, keep as is)
;; ------------------------
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages '(company dracula-theme use-package)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

I tried to implement some code flashing in emacs today with ChatGPT and after some interations it came up with something useful.

First I installed pulsar from melpa.

Then I put this in my init.el file:

;; ------------------------
;; Pulsar flash for SuperCollider evaluation
;; ------------------------
(require 'pulsar)
(pulsar-global-mode 1)

(setq pulsar-pulse t
      pulsar-delay 0.1
      pulsar-iterations 2
      pulsar-face 'pulsar-yellow)

(defun my/pulsar-flash-sc-defun-before (&rest _)
  "Flash the SC block for `sclang-eval-defun`."
  (save-excursion
    (let (beg end)
      (ignore-errors
        (while (and (not beg) (not (bobp)))
          (beginning-of-line)
          (if (looking-at-p "\\s-*(")
              (setq beg (point))
            (forward-line -1)))  ;; <-- was outside if, now inside while
        (when beg
          (goto-char beg)
          (forward-sexp 1)
          (setq end (point))))
      (if (and beg end)
          (pulsar--pulse nil pulsar-face beg end)
        (pulsar-pulse-line)))))

(defun my/pulsar-flash-line-before (&rest _) (pulsar-pulse-line))

(defun my/pulsar-flash-region-before (&rest _)
  (if (use-region-p)
      (pulsar--pulse nil pulsar-face (region-beginning) (region-end))
    (pulsar-pulse-line)))

(with-eval-after-load 'sclang
  ;; defun → block
  (advice-add 'sclang-eval-defun        :before #'my/pulsar-flash-sc-defun-before)
  ;; line → line
  (advice-add 'sclang-eval-line         :before #'my/pulsar-flash-line-before)
  ;; region → region
  (advice-add 'sclang-eval-region       :before #'my/pulsar-flash-region-before)
  (advice-add 'sclang-eval-region-or-line :before #'my/pulsar-flash-region-before)
  ;; everything else → line
  (dolist (fn '(sclang-eval-document
                sclang-eval-expression
                sclang-eval-current-block))
    (advice-add fn :before #'my/pulsar-flash-line-before)))


edit: 31.8. adjusted code to do the same like the code block search in SCnvim