From e51d89105d1aad390c5d04060fe616a0e0aed1e4 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Tue, 24 Jun 2025 18:55:01 +0700 Subject: [PATCH] emacs: Programming enhancements to Lisp, C, Rust, and Clojure --- .config/emacs/init.org | 62 +++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/.config/emacs/init.org b/.config/emacs/init.org index 09a8eb3..15eba9f 100644 --- a/.config/emacs/init.org +++ b/.config/emacs/init.org @@ -2213,6 +2213,7 @@ These help speed eglot up apparently [[https://www.reddit.com/r/emacs/comments/1 ;; All this changes because we are using eglot now (when (boundp 'evil-mode) (evil-global-set-key 'normal (kbd "M-d") #'lsp-ui-doc-glance) + (evil-global-set-key 'normal (kbd "M-D") #'lsp-describe-thing-at-point) (evil-global-set-key 'normal (kbd "M-r") #'lsp-rename) (evil-global-set-key 'insert (kbd "M-i") #'lsp-signature-activate) (evil-global-set-key 'normal (kbd "gD") #'xref-find-definitions-other-window) @@ -2447,6 +2448,19 @@ And we do the rest here, including a macro #+begin_src emacs-lisp (setq sly-lisp-implementations '((sbcl ("/usr/local/bin/sbcl" "--dynamic-space-size" "4096")) (ecl ("/usr/bin/ecl")))) +(defun joe/sly-copy-call-to-repl () + "Copy name/symbol of toplevel sexp to sly-mREPL and select sly-mREPL." + (interactive) + (let (string + replwin) + (save-excursion + (beginning-of-defun) + (forward-thing 'symbol 2) + (setq string (format "(%s )" (thing-at-point 'symbol 'no-props)))) + (setq replwin (get-buffer-window (call-interactively #'sly-mrepl))) + (with-selected-window replwin + (insert string) + (forward-char -1)))) #+end_src *** Odin #+begin_src emacs-lisp @@ -2475,14 +2489,26 @@ whether the point hasn't been moved. This way, if I switched to another popper b it doesn't close it. #+begin_src emacs-lisp -(require 'disaster) -(setq c-default-style "bsd") -(defun joe/c-mode-hook () - (local-set-key (kbd "C-x c r") (defun joe/make-run () (interactive) (compile "make run"))) - (local-set-key (kbd "C-x c c") (defun joe/make () (interactive) (compile "make"))) - (electric-pair-local-mode t) - (c-toggle-comment-style -1)) -(add-hook 'c-mode-hook #'joe/c-mode-hook) + (require 'disaster) + + (defun joe/disaster (arg) + (interactive "P") + (if arg + (let ((disaster-cflags (concat disaster-cflags " -O2"))) + (disaster)) + (disaster))) + + (defun joe/c-mode-hook () + (setq c-default-style "bsd") + (define-key c-mode-map (kbd "C-c d") #'joe/disaster) + (local-set-key (kbd "C-x c r") (defun joe/make-run () (interactive) (compile "make run"))) + (local-set-key (kbd "C-x c c") (defun joe/make () (interactive) (compile "make"))) + (electric-pair-local-mode t) + (c-toggle-comment-style -1)) + + (with-eval-after-load 'cc-mode + (add-hook 'c-mode-hook #'joe/c-mode-hook)) + #+end_src *** Python #+begin_src emacs-lisp @@ -2509,10 +2535,21 @@ it doesn't close it. ;; :host github ;; :repo "serialdev/evcxr-mode")) +(defun joe/save-then-rustic-cargo-check () + "Save the buffer before recompiling" + (interactive) + (when (buffer-file-name) + (save-buffer)) + (rustic-cargo-check)) + (add-hook 'rust-mode-hook (lambda () ;; (evcxr-minor-mode) - (electric-pair-local-mode))) + (electric-pair-local-mode) + (yas-minor-mode) + (define-key rustic-mode-map (kbd "") #'joe/save-then-rustic-cargo-check) + (define-key rustic-cargo-run-mode-map (kbd "") #'joe/save-then-rustic-cargo-check) + (define-key rustic-mode-map (kbd "") #'joe/save-then-recompile))) ;; (with-eval-after-load 'rustic ;; ;; Don't autostart @@ -2944,20 +2981,25 @@ Org mode buffers have associated files. (ocaml . t) (python . t) (C . t) + (lisp . t) (haskell . t) - ;; (rust . t) + (rust . t) + (clojure . t) (shell . t))) (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) +(add-to-list 'org-structure-template-alist '("cl" . "src common-lisp")) (add-to-list 'org-structure-template-alist '("ml" . "src ocaml")) (add-to-list 'org-structure-template-alist '("rs" . "src rust")) (add-to-list 'org-structure-template-alist '("py" . "src python")) (add-to-list 'org-structure-template-alist '("hs" . "src haskell")) (add-to-list 'org-structure-template-alist '("sh" . "src shell")) (add-to-list 'org-structure-template-alist '("cs" . "src csharp")) +(add-to-list 'org-structure-template-alist '("clj" . "src clojure")) (add-to-list 'org-structure-template-alist '("cc" . "src C :includes stdio.h stdlib.h")) (setq org-edit-src-content-indentation 0) (setq org-src-window-setup 'current-window) +(setq org-babel-lisp-eval-fn 'sly-eval) #+end_src