Julia

This file holds my Julia configuration. Currently a work in progress, so not much commentary.

(use-package julia-mode
  :ensure t
  :config
  (setq julia-indent-offset 4)
  ;; add some extra highlighting
  (font-lock-add-keywords
   'julia-mode
   '(("\\<\\(pi\\|π\\|im\\|^>>\\)\\>"
      1 font-lock-constant-face)))
  ;; add hook to lang mode to enable the repl mode
  (defun do.julia.repl/mode-hooks ()
    (highlight-symbol-mode)
    (julia-repl-mode)
    (julia-img-view-minor-mode))
  (add-hook 'julia-mode-hook 'do.julia.repl/mode-hooks))

(use-package julia-repl
  :after julia-mode
  :ensure t
  :commands (julia-repl julia-repl--executable-record)
  :init
  ;; add some generic hooks for the repl mode
  (defun do.julia.repl/hooks ()
    (setq global-hl-line-mode nil)
    (setq show-trailing-whitespace nil))
  (add-hook 'julia-repl-hook #'do.julia.repl/hooks)
  ;; start julia with `run-julia'
  (defun run-julia (arg)
    "Run the julia REPL. When called with a prefix argument ARG,
  run it with ARG threads. If C-u was typed, but no prefix
  argument given, run with $(nproc) threads."
    (interactive "P")
    (let ((nthreads (cond ((and (listp arg) (equal (length arg) 1))
                           (string-to-number (car (split-string (shell-command-to-string "nproc") "\n"))))
                          ((numberp arg) arg)
                          (t 1)))
          (envvar "JULIA_NUM_THREADS"))
      (if (equal nthreads 1)
          (julia-repl)
        (setenv envvar (number-to-string nthreads))
        (julia-repl)
        (setenv envvar nil)))))

;; use-package for julia-img-view
(use-package julia-img-view
  :load-path "~/Dropbox/code/julia-img-view"
  :after julia-repl
  :config (julia-img-view-setup))

Add LSP support by abusing the eglot-jl package. we actually never use eglot, we just use the facilities from the eglot-jl package to set up an emacs-lsp client.

<2020-08-22 Sat> Disabling this because it is a huge hack

(use-package eglot-jl
  :ensure t
  :commands eglot-jl--ls-invocation
  :hook (julia-mode . lsp)
  :init
  ;; define a new lsp client using the eglot/julia-repl dance
  (lsp-register-client (make-lsp-client
                        :new-connection (lsp-stdio-connection #'(lambda () (eglot-jl--ls-invocation t)))
                        :major-modes '(julia-mode)
                        :server-id 'julia-ls))
  (setq eglot-jl-default-environment "~/.julia/environments/v1.3"))