Edit shader code from a string in a buffer

With a little bit of code, you can have it so that when your point is at a string you can press C-c C-. to get a temporary buffer to edit the shader in. The convenience of a string, the benefits of a file/buffer.

(require 'glsl-mode)
(require 'separedit)

(defun zyd/choose-glsl-mode (fn &rest args)
  (if (eq major-mode 'lisp-mode)
      "glsl-mode"
    (apply fn args)))

(advice-add 'separedit--select-mode :around #'zyd/choose-glsl-mode)

(defun zyd/indirectly-edit ()
  (interactive)
  (let ((current-prefix-arg t))
    (separedit-dwim-default)))

(define-key slime-mode-map (kbd "C-c C-.") #'zyd/indirectly-edit)
        
Video demonstration of editing GLSL shader code from a string to a temporary buffer. The buffer provides syntax highlighting as well as auto indentation. After I'm finished with the buffer, it spits out the contents back to the string, maintaining proper indentation.