The Complete Computer

Using rustic, eglot, and org-babel for literate programming with LSP support in emacs

LifeTechEmacsArcology

This cool little hack makes it easier to use LSP in Literate Programming ; it'll still struggle on noweb syntax but this will at least have decent LSP support in org-src blocks.

this doesn't work reliably with lsp and envrc and desktop-save-mode
#+ARROYO_EMACS_MODULE: superior-rustic
emacs-lisp source: :tangle ~/org/cce/superior-rustic.el :results none
(defun my-read-file-to-string (fname) (with-temp-buffer (insert-file-contents fname) (buffer-string))) ;; (defun org-babel-edit-prep:python (babel-info) ;; ;; This gets the second item in the "babel-info" list, which holds the code in the original src block ;; (setq-local src-code (nth 1 babel-info)) ;; (setq-local buffer-file-name (expand-file-name (thread-last babel-info caddr (alist-get :tangle)))) ;; (setq-local buffer-src-code (replace-regexp-in-string (regexp-quote src-code) "" (my-read-file-to-string (buffer-file-name)))) ;; (goto-char (point-max)) ;; (insert buffer-src-code) ;; (narrow-to-region (point-min) (+ (point-min) (length src-code))) ;; (python-mode) ;; (org-src-mode) ;; (lsp) ;; ) ;; Make sure rustic gets activated in the org-src block and add the original file's source code. (defun org-babel-edit-prep:rust (babel-info) ;; This gets the second item in the "babel-info" list, which holds the code in the original src block (setq-local src-code (nth 1 babel-info)) (setq-local buffer-file-name (expand-file-name (thread-last babel-info caddr (alist-get :tangle)))) (setq-local buffer-src-code (replace-regexp-in-string src-code "" (my-read-file-to-string (buffer-file-name)))) (goto-char (point-max)) (insert buffer-src-code) (narrow-to-region (point-min) (+ (point-min) (length src-code))) (rustic-mode) (org-src-mode)) (defun cce/delete-hidden-text () "Remove all text that would be revealed by a call to `widen'" (-let [p-start (point-max)] (widen) (delete-region p-start (point-max)))) (define-advice org-edit-src-exit (:before (&rest _args) remove-src-block) (when (eq major-mode 'rustic-mode) (cce/delete-hidden-text))) (define-advice org-edit-src-save (:before (&rest _args) remove-src-block) (when (eq major-mode 'rustic-mode) (cce/delete-hidden-text)))