diff --git a/users/crumb/programs/emacs/init.el b/users/crumb/programs/emacs/init.el index 40403e4..7645798 100755 --- a/users/crumb/programs/emacs/init.el +++ b/users/crumb/programs/emacs/init.el @@ -61,4 +61,5 @@ (require 'syd-scratch) (require 'syd-smartparens) (require 'syd-tramp) +(require 'syd-tooling) (require 'syd-ui) diff --git a/users/crumb/programs/emacs/lib/syd-prelude.el b/users/crumb/programs/emacs/lib/syd-prelude.el index 8b4cd81..ff7e997 100644 --- a/users/crumb/programs/emacs/lib/syd-prelude.el +++ b/users/crumb/programs/emacs/lib/syd-prelude.el @@ -4,6 +4,10 @@ (require 'syd-constants) +(use-package dash) + +(require 'dash) + (cl-defmacro syd-define-stub (name &key (desc "implement me!") interactive) (let ((todo (format "%s: TODO: %s" name desc))) @@ -130,4 +134,35 @@ form." (prog1 (progn ,@body) (message "")))))) +(defun syd--parse-defadvice-args (arg-list) + "Parses the docstring and keywords provided to `syd-defadvice'." + (let (docstring + advice) + (when (stringp (car-safe arg-list)) + (setq docstring (pop arg-list))) + (while (and (length> arg-list 2) + (keywordp (car arg-list))) + (let ((how (pop arg-list)) + (sym (pop arg-list))) + (push (cons how sym) advice))) + ;; What's left of `arg-list' is the body of the defun. + (list docstring advice arg-list))) + +(defmacro syd-defadvice (name params &rest args) + "Define a function and add it as advice." + (declare (indent defun)) + (-let (((docstring advice body) (syd--parse-defadvice-args args))) + `(progn (defun ,name ,params + ,@(-some-> docstring list) + ,@body) + ,@(-map (lambda (arg) + (-let (((how . sym) arg)) + `(advice-add ,sym ,how #',name))) + advice)))) + +(syd-defadvice syd-lsp-install-server-a () + :override #'lsp-install-server + (user-error (concat "Ignoring a call to `lsp-install-server'" + " — tell the caller to use Nix!"))) + (provide 'syd-prelude) diff --git a/users/crumb/programs/emacs/modules/lang/syd-lang-nix.el b/users/crumb/programs/emacs/modules/lang/syd-lang-nix.el new file mode 100644 index 0000000..ea4763d --- /dev/null +++ b/users/crumb/programs/emacs/modules/lang/syd-lang-nix.el @@ -0,0 +1,8 @@ +;;; syd-lang-nix.el -*- lexical-binding: t; -*- + +(use-package nix-mode + :mode "\\.nix\\'" + :config + (add-hook 'nix-mode-hook #'lsp)) + +(provide 'syd-lang-nix) diff --git a/users/crumb/programs/emacs/modules/syd-lang.el b/users/crumb/programs/emacs/modules/syd-lang.el index 0bcf987..0b30dac 100644 --- a/users/crumb/programs/emacs/modules/syd-lang.el +++ b/users/crumb/programs/emacs/modules/syd-lang.el @@ -2,5 +2,6 @@ (file-name-concat user-emacs-directory "modules" "lang")) (require 'syd-lang-emacs-lisp) +(require 'syd-lang-nix) (provide 'syd-lang) diff --git a/users/crumb/programs/emacs/modules/syd-tooling.el b/users/crumb/programs/emacs/modules/syd-tooling.el new file mode 100644 index 0000000..fa7fda9 --- /dev/null +++ b/users/crumb/programs/emacs/modules/syd-tooling.el @@ -0,0 +1,30 @@ +;;; syd-tooling.el -*- lexical-binding: t; -*- + +(use-package lsp-mode + :init + ;; We'll bind things ourselves. + (setq lsp-keymap-prefix nil) + ;; Keep state out of my config dir. + (setq lsp-session-file (file-name-concat syd-data-dir "lsp-session") + ;; We disable `lsp-install-server', but I don't want this to be nil. + lsp-server-install-dir (file-name-concat syd-data-dir "lsp")) + ;; Disable features that have great potential to be slow. LSPs tend to be + ;; quite slow compared to non-LSP equivalents. + (setq lsp-enable-folding nil + lsp-enable-text-document-color nil) + ;; Reduce unexpected modifications to code + (setq lsp-enable-on-type-formatting nil) + ;; Make breadcrumbs opt-in; they're redundant with the modeline and imenu + (setq lsp-headerline-breadcrumb-enable nil) + :hook (lsp-mode . lsp-enable-which-key-integration) + :commands lsp + :config + (syd-defadvice syd-lsp-install-server-a () + "Override and disbale `lsp-install-server'" + :override #'lsp-install-server + (user-error (concat "Ignoring a call to `lsp-install-server'" + " — tell the caller to use Nix!"))) + (set-popup-rule! (rx line-start "*lsp-" (or "help" "install")) + :size 0.35 :quit t :select nil)) + +(provide 'syd-tooling)