~abcdw/rde

c5f3671d2e45d76d0318745762c56753a334c600 — Andrew Tropin 3 months ago 2d38b21
rde: clojure: Add feature-clojure.
1 files changed, 87 insertions(+), 0 deletions(-)

A rde/features/clojure.scm
A rde/features/clojure.scm => rde/features/clojure.scm +87 -0
@@ 0,0 1,87 @@
(define-module (rde features clojure)
  #:use-module (rde features)
  #:use-module (rde features emacs)
  #:use-module (rde features predicates)
  #:use-module (gnu services)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu packages clojure)
  #:use-module (gnu packages java)
  #:use-module (gnu packages emacs-xyz)
  #:use-module (guix gexp)

  #:export (feature-clojure))

;; https://github.com/jpe90/emacs-clj-deps-new

(define* (feature-clojure
          #:key
          (clojure-tools-cli clojure-tools-cli)
          (clojure-lsp #f))
  "Setup and configure environment for Clojure. "
  (ensure-pred file-like? clojure-tools-cli)
  (ensure-pred file-like? clojure-lsp)

  (define (get-home-services config)
    (define emacs-f-name 'clojure)
    (define clojure-lsp-binary
      (if (any-package? clojure-lsp)
          (file-append clojure-lsp "/bin/clojure-lsp")
          clojure-lsp))
    (list
     (unless (get-value 'openjdk config)
         (simple-service
          'clojure-add-packages
          home-profile-service-type
          (list
           ;; for go-to-definition
           ;; MAYBE: Add as a dependency to cider?
           (@ (gnu packages compression) unzip)
           clojure-tools
           (list openjdk17 "jdk"))))

     ;; https://github.com/DogLooksGood/meomacs/blob/master/programming.org#fix-clojure-syntax-highlighting
     (when (get-value 'emacs config)
       (elisp-configuration-service
        emacs-f-name
        `((defun rde--clojure-disable-eglot-parts-in-favor-of-cider ()
            (setq-local eglot-stay-out-of '(eldoc flymake)))
          (add-hook 'clojure-mode-hook
                    'rde--clojure-disable-eglot-parts-in-favor-of-cider)

          (with-eval-after-load
           'consult-imenu
           (add-to-list
            'consult-imenu-config
            ;; https://github.com/clojure-lsp/clojure-lsp/blob/13487d1eb0d06596565f76b8f6d76d00b7e9f03b/cli/integration-test/integration/initialize_test.clj#L62
            '(clojure-mode
              :toplevel "Variable"
              :types ((?f "Function"  font-lock-function-name-face)
                      (?m "Macro"     font-lock-function-name-face)
                      (?M "Method"    font-lock-function-name-face)
                      (?e "Event"     font-lock-function-name-face)
                      (?n "Namespace" font-lock-constant-face)
                      (?k "Keyword"   font-lock-keyword-face)
                      (?c "Class"     font-lock-type-face)
                      (?t "Type"      font-lock-type-face)
                      (?v "Variable"  font-lock-variable-name-face)))))
          (with-eval-after-load
           'eglot
           (add-to-list
            'eglot-server-programs
            '(((clojure-mode :language-id "clojure")
               (clojurec-mode :language-id "clojure")
               (clojurescript-mode :language-id "clojurescript"))
              . (,clojure-lsp-binary))))
          (with-eval-after-load
           'clojure-mode
           (customize-set-variable 'clojure-align-forms-automatically t)))
        #:elisp-packages
        (list emacs-cider emacs-clojure-mode
              (get-value 'emacs-eglot config emacs-eglot)
              emacs-flymake-kondor emacs-html-to-hiccup)))))

  (feature
   (name 'clojure)
   (values `((clojure . #t)))
   (home-services-getter get-home-services)))