refactor: Move user config into modules/

This commit is contained in:
Madeleine Sydney
2025-03-13 11:14:32 -06:00
parent 257f011a99
commit fb3299d89c
85 changed files with 597 additions and 542 deletions

View File

@@ -1,42 +0,0 @@
;;; syd-lang-agda.el -*- lexical-binding: t; -*-
(with-eval-after-load 'agda2
(general-define-key
:keymaps 'agda2-mode-map
:states '(normal visual motion emacs insert)
:major-modes t
:prefix syd-localleader-key
:non-normal-prefix syd-alt-localleader-key
"?" #'agda2-show-goals
"." #'agda2-goal-and-context-and-inferred
"," #'agda2-goal-and-context
"=" #'agda2-show-constraints
"SPC" #'agda2-give
"a" #'agda2-mimer-maybe-all
"b" #'agda2-previous-goal
"c" #'agda2-make-case
"d" #'agda2-infer-type-maybe-toplevel
"e" #'agda2-show-context
"f" #'agda2-next-goal
"gG" #'agda2-go-back
"h" #'agda2-helper-function-type
"l" #'agda2-load
"n" #'agda2-compute-normalised-maybe-toplevel
"p" #'agda2-module-contents-maybe-toplevel
"r" #'agda2-refine
"s" #'agda2-solveAll
"t" #'agda2-goal-type
"w" #'agda2-why-in-scope-maybe-toplevel
"x c" #'agda2-compile
"x d" #'agda2-remove-annotations
"x h" #'agda2-display-implicit-arguments
"x q" #'agda2-quit
"x r" #'agda2-restart)
(general-def
:keymaps 'agda2-mode-map
:states '(motion normal)
"[ n" #'agda2-previous-goal
"] n" #'agda2-next-goal)
(setq agda2-fontset-name "JuliaMono"))
(provide 'syd-lang-agda)

View File

@@ -1,106 +0,0 @@
;;; syd-lang-clojure.el -*- lexical-binding: t; -*-
(use-package clojure-mode
:mode (("\\.\\(clj\\|cljd\\|dtm\\|edn\\|lpy\\)\\'" . clojure-mode)
("\\.cljc\\'" . clojurec-mode)
("\\.cljs\\'" . clojurescript-mode)
("\\(?:build\\|profile\\)\\.boot\\'" . clojure-mode))
:interpreter (("bb" . clojure-mode)
("nbb" . clojurescript-mode))
:config
(add-hook 'clojure-mode-hook #'syd-lisp-mode)
(dolist (c '(?- ?_ ?? ?! ?+ ?* ?/ ?: ?> ?< ?= ?&))
(modify-syntax-entry c "w" clojure-mode-syntax-table)))
(use-package cider
:after clojure-mode)
(defun syd-clojure-open-repl (&optional arg type)
"Open a Cider REPL for clojure and return the buffer."
(interactive "P")
;; TODO: Better error handling
;; type is `clj' for clojure and `cljs' for clojurescript
;; ... with no type specified, assume `clj'.
(let ((type (or type 'clj)))
(if-let* ((buffer (cider-current-repl type)))
(pop-to-buffer buffer)
(let ((process (cond ((eq type 'clj) (cider-jack-in-clj arg))
((eq type 'cljs) (cider-jack-in-cljs arg)))))
(message "Starting CIDER server for the first time...")
(while (and (process-live-p process)
(not (cider-current-repl type)))
(sit-for 1))
(message "Starting CIDER server for the first time...done")
(pop-to-buffer (cider-current-repl type))))))
(defun syd-clojure-open-cljs-repl (&optional arg)
(interactive "P")
(syd-clojure-open-repl arg 'cljs))
(use-package cider-mode
:straight nil
;; :after clojure-mode
:hook (clojure-mode-local-vars . cider-mode)
:init
(with-eval-after-load 'clojure-mode
(set-repl-handler! '(clojure-mode clojurec-mode)
#'syd-clojure-open-repl :persist t)
(set-repl-handler! 'clojurescript-mode
#'syd-clojure-open-cljs-repl :persist t)
(set-eval-handler! '(clojure-mode clojurec-mode clojurescript-mode)
#'cider-eval-region))
:custom ((cider-show-error-buffer nil))
:general
;; DEPRECATED: Remove once a `map!' equivalent is implemented.
(:keymaps 'cider-repl-mode-map
:states '(normal insert)
"C-k" #'cider-repl-backward-input
"C-j" #'cider-repl-forward-input
"C-s" #'cider-repl-previous-matching-input)
;; DEPRECATED: Remove once a `map!' equivalent is implemented.
(:keymaps 'clojure-mode-map
:states '(normal visual motion emacs insert)
:major-modes t
:prefix syd-localleader-key
:non-normal-prefix syd-alt-localleader-key
"\"" #'cider-jack-in-cljs
"'" #'cider-jack-in-clj
"c" #'cider-connect-clj
"C" #'cider-connect-cljs
"r l" #'cider-load-buffer
"r n" #'cider-repl-set-ns
"r r" #'cider-ns-refresh
"r R" #'cider-restart
"r q" #'cider-quit
"h c" #'cider-cheatsheet)
:config
(add-hook 'cider-mode-hook #'eldoc-mode)
(add-hook 'cider-repl-mode-hook #'syd-lisp-mode)
(set-popup-rules!
`(("^\\*cider-error\\*" :ignore t)
("^\\*cider-repl" :quit nil :ttl nil)
("^\\*cider-repl-history" :vslot 2 :ttl nil)
(,(rx bol "*cider-nrepl-middleware") :slot 3 :quit t :ttl 0)
(,(rx bol "*cider-cheatsheet*")
:width ,(lambda (win)
(with-selected-window win
(enlarge-window (- (min 45 (* 0.2 (frame-width)))
(window-width))
t)))
:side right :vslot -8 :quit t :select t)
(,(rx bol "*cider-doc*")
:slot 2 :vslot -8 :quit t :select t)))
;; DEPRECATED: Remove once syd-strategies is working.
(syd-add-hook 'clojure-mode-hook
(defun syd-clojure-set-handlers-h ()
(setq-local syd-lookup-documentation-handlers
(list #'cider-doc))))
;; Correctly indent some common macros.
(put-clojure-indent 'match 1))
;; Give different pairs of delimiters different colours.
(use-package rainbow-delimiters
:hook (clojure-mode . rainbow-delimiters-mode))
(provide 'syd-lang-clojure)

View File

@@ -1,105 +0,0 @@
;;; emacs-lisp.el -*- lexical-binding: t; -*-
(require 'syd-handle-repl)
(require 'syd-handle-lookup)
(require 'syd-handle-eval)
(require 'syd-lisp-lib)
;; (require 'handle)
;; Don't `use-package' `ielm', since it's loaded by Emacs. You'll get weird
;; autoload errors if you do.
;; https://www.reddit.com/r/emacs/comments/q7fjbi/comment/lml127d
(use-package emacs
:custom ((ielm-history-file-name ; Stay out of my config dir!
(file-name-concat syd-cache-dir "ielm-history.eld"))))
;;;###autoload
(defun syd/open-emacs-lisp-repl ()
(interactive)
(pop-to-buffer
(or (get-buffer "*ielm*")
(progn (ielm) ; Creates the *ielm* buffer.
(let ((b (get-buffer "*ielm*")))
;; We leave it to the enclosing `pop-to-buffer' to display the
;; buffer.
(bury-buffer b)
b)))))
;;;###autoload
(defun syd-emacs-lisp-lookup-documentation (identifier)
"Lookup IDENTIFIER with `describe-symbol'"
;; HACK: Much to my frustration, `describe-symbol' has no defined return
;; value. To test if the call was successful or not, we check if any window
;; is displaying the help buffer. This breaks if
;; `syd-emacs-lisp-lookup-documentation' is called while the help buffer is
;; already open.
(describe-symbol (intern identifier))
(let ((buffer (get-buffer (help-buffer))))
(and (get-buffer-window-list buffer)
buffer)))
;;;###autoload
(defun syd-emacs-lisp-eval (beg end)
"Evaluate a region and print it to the echo area (if one line long), otherwise
to a pop up buffer."
(syd-eval-display-results
(string-trim-right
(let ((buffer (generate-new-buffer " *eval-output*"))
(debug-on-error t))
(unwind-protect
(condition-case-unless-debug e
(progn (eval-region beg end buffer load-read-function)
(with-current-buffer buffer
(let ((pp-max-width nil))
(require 'pp)
(pp-buffer)
(replace-regexp-in-string
"\\\\n" "\n" (string-trim-left (buffer-string))))))
(error (format "ERROR: %s" e)))
(kill-buffer buffer))))
:source-buffer (current-buffer)
:force-popup current-prefix-arg))
(dolist (m '(emacs-lisp-mode lisp-data-mode))
(set-repl-handler! 'emacs-lisp-mode
#'syd/open-emacs-lisp-repl)
(set-eval-handler! 'emacs-lisp-mode
#'syd-emacs-lisp-eval))
(syd-add-hook '(emacs-lisp-mode-hook lisp-data-mode)
#'syd-lisp-mode)
;; DEPRECATED: Remove once syd-strategies is working.
(syd-add-hook '(emacs-lisp-mode-hook help-mode-hook lisp-data-mode)
(defun syd-emacs-set-handlers-h ()
(setq-local syd-lookup-documentation-handlers
(list #'syd-emacs-lisp-lookup-documentation))))
;; Semantic highlighting for Elisp.
(use-package highlight-defined
:hook (emacs-lisp-mode-hook . highlight-defined-mode))
;; Automatically and inteligently expand abbreviations. E.g. `wcb` will be
;; expanded to `(with-current-buffer)`, but only where it makes sense for a
;; function/macro call to be.
(use-package sotlisp
:straight (:host github
:repo "Malabarba/speed-of-thought-lisp")
:hook (emacs-lisp-mode . speed-of-thought-mode))
;; Give different pairs of delimiters different colours.
(use-package rainbow-delimiters
:hook (emacs-lisp-mode . rainbow-delimiters-mode))
(use-package macrostep
:commands (macrostep-expand)
:init
(general-define-key
:keymaps 'emacs-lisp-mode-map
:states '(normal visual motion emacs insert)
:major-modes t
:prefix syd-localleader-key
:non-normal-prefix syd-alt-localleader-key
"m" #'macrostep-expand))
(provide 'syd-lang-emacs-lisp)

View File

@@ -1,73 +0,0 @@
;;; syd-lang-haskell.el -*- lexical-binding: t; -*-
(require 'syd-handle-repl)
(require 'syd-handle-lookup)
(defun syd-haskell-open-repl ()
"Open a Haskell REPL."
(interactive)
(require 'inf-haskell)
(run-haskell))
(defun syd-haskell-evil-open-above ()
"Opens a line above the current, following Haskell-mode's indentation"
(interactive)
(evil-beginning-of-line)
(haskell-indentation-newline-and-indent)
(evil-previous-line)
(haskell-indentation-indent-line)
(evil-append-line nil))
(defun syd-haskell-evil-open-below ()
"Opens a line below the current, following Haskell-mode's indentation"
(interactive)
(evil-append-line nil)
(haskell-indentation-newline-and-indent))
(use-package haskell-mode
:mode (("\\.l?hs'" . haskell-literate-mode)
("\\.hs'" . haskell-mode))
:custom (; Show errors in REPL, not popup buffers.
(haskell-interactive-popup-errors nil)
(haskell-process-suggest-remove-import-line t)
(haskell-process-auto-import-loaded-modules t))
:general
;; DEPRECATED: Remove once a `map!' equivalent is implemented.
(:keymaps 'haskell-mode-map
:states '(normal visual motion emacs insert)
:major-modes t
:prefix syd-localleader-key
:non-normal-prefix syd-alt-localleader-key
"c" #'haskell-cabal-visit-file
"h s" #'haskell-hoogle-start-server
"h q" #'haskell-hoogle-kill-server)
(:keymaps 'interactive-haskell-mode-map
:states '(normal insert)
"C-j" #'haskell-interactive-mode-history-next
"C-k" #'haskell-interactive-mode-history-previous)
(:keymaps 'haskell-mode-map
:states 'normal
[remap evil-open-above] #'syd-haskell-evil-open-above
[remap evil-open-below] #'syd-haskell-evil-open-below)
:config
(set-repl-handler! '(haskell-mode haskell-cabal-mode literate-haskell-mode)
#'syd-haskell-open-repl
;; Haskell-mode provides IDE features by communicating with a persistent
;; REPL process à la Lisp.
:persist t)
(add-to-list 'completion-ignored-extensions ".hi")
;; Don't kill REPL popup on ESC/C-g
(set-popup-rule! "^\\*haskell\\*" :quit nil)
(syd-add-hook 'haskell-mode-local-vars-hook
;; Folding of Haskell sections.
#'haskell-collapse-mode
#'interactive-haskell-mode))
(use-package lsp-haskell
:defer t
:init
(add-hook 'haskell-mode-local-vars-hook #'lsp 'append)
(add-hook 'haskell-literate-mode-local-vars-hook #'lsp 'append))
(provide 'syd-lang-haskell)

View File

@@ -1,40 +0,0 @@
;;; syd-lang-nix.el -*- lexical-binding: t; -*-
(require 'syd-handle-repl)
(require 'syd-handle-lookup)
(defun syd-nix-open-nix-repl ()
(interactive)
;; If possible, cd to the project root. Flakes force you to use relative
;; paths, which can be annoying in combination with
;;
;; REVIEW: Should this be something handled by `syd--call-repl-handler'?
(-some-> (syd-project-root) cd)
(nix-repl)
(current-buffer))
(use-package nix-mode
:mode "\\.nix\\'"
:init
(add-to-list 'auto-mode-alist
(cons (rx "/flake.lock'")
(if (fboundp 'json-mode)
'json-mode
'js-mode)))
:config
(add-hook 'nix-mode-hook #'lsp)
(set-popup-rule! (rx bol "*nixos-options-doc*" eol) :ttl 0 :quit t)
(set-repl-handler! 'nix-mode #'syd-nix-open-nix-repl)
(dolist (c '(?- ?_))
(modify-syntax-entry c "w" nix-mode-syntax-table))
;; Inform Smartparens and Evil-surround of Nix's alternative string syntax.
(with-eval-after-load 'smartparens
(sp-local-pair 'nix-mode "''" "''"))
(syd-add-hook 'nix-mode-hook
(defun syd-nix--configure-evil-surround-h ()
(with-eval-after-load 'evil-surround
(push '(?Q . ("''" . "''"))
evil-surround-pairs-alist)))))
(provide 'syd-lang-nix)

View File

@@ -1,6 +0,0 @@
;;; syd-lang-sql.el -*- lexical-binding: t; -*-
(with-eval-after-load 'sql
(add-hook 'sql-interactive-mode-hook #'syd-repl-mode))
(provide 'syd-lang-sql)