doomemacs/modules/lang/julia/config.el

138 lines
5.3 KiB
EmacsLisp
Raw Normal View History

;;; lang/julia/config.el -*- lexical-binding: t; -*-
2016-04-12 15:33:06 -04:00
(use-package! julia-mode
2016-04-12 15:33:06 -04:00
:interpreter "julia"
2016-05-24 22:09:50 -04:00
:config
2022-09-15 14:28:12 -05:00
(unless (modulep! +snail)
(set-repl-handler! 'julia-mode #'+julia/open-repl))
(when (modulep! +lsp)
(add-hook 'julia-mode-local-vars-hook #'lsp! 'append))
(when (modulep! +tree-sitter)
(add-hook 'julia-mode-local-vars-hook #'tree-sitter! 'append))
2020-04-08 17:34:53 -04:00
;; Borrow matlab.el's fontification of math operators. From
2021-01-13 01:13:38 -05:00
;; <https://web.archive.org/web/20170326183805/https://ogbe.net/emacsconfig.html>
(dolist (mode '(julia-mode ess-julia-mode))
(font-lock-add-keywords
mode
`((,(let ((OR "\\|"))
2020-04-08 17:34:53 -04:00
(concat "\\(" ; stolen `matlab.el' operators first
2020-08-18 21:26:41 -03:00
;; `:` defines a symbol in Julia and must not be highlighted
;; as an operator. The only operators that start with `:` are
;; `:<` and `::`. This must be defined before `<`.
"[:<]:" OR
"[<>]=?" OR
"\\.[/*^']" OR
"===" OR
"==" OR
"=>" OR
"\\<xor\\>" OR
2020-04-08 17:34:53 -04:00
"[-+*\\/^&|$]=?" OR ; this has to come before next (updating operators)
"[-^&|*+\\/~]" OR
;; Julia variables and names can have `!`. Thus, `!` must be
;; highlighted as a single operator only in some
;; circumstances. However, full support can only be
;; implemented by a full parser. Thus, here, we will handle
;; only the simple cases.
"[[:space:]]!=?=?" OR "^!=?=?" OR
;; The other math operators that starts with `!`.
;; more extra julia operators follow
"[%$]" OR
;; bitwise operators
">>>" OR ">>" OR "<<" OR
">>>=" OR ">>" OR "<<" OR
"\\)"))
1 font-lock-type-face)))))
2020-04-08 17:34:53 -04:00
(use-package! julia-repl
2020-04-08 17:43:42 -04:00
:preface (defvar +julia-repl-start-hook nil)
:hook (julia-mode . julia-repl-mode)
:hook (+julia-repl-start . +julia-override-repl-escape-char-h)
:hook (+julia-repl-start . julia-repl-use-emacsclient)
2020-04-08 17:34:53 -04:00
:config
(set-popup-rule! "^\\*julia.*\\*$" :ttl nil)
(when (modulep! :ui workspaces)
2020-04-08 17:34:53 -04:00
(defadvice! +julia--namespace-repl-buffer-to-workspace-a (&optional executable-key suffix)
"Name for a Julia REPL inferior buffer. Uses workspace name for doom emacs"
:override #'julia-repl--inferior-buffer-name
(concat julia-repl-inferior-buffer-name-base ":" (+workspace-current-name))))
2020-04-08 17:43:42 -04:00
(defadvice! +julia--run-start-hook-a (inferior-buffer)
"Run `+julia-repl-start-hook' before displaying the REPL."
:after #'julia-repl--setup-term
(with-current-buffer inferior-buffer
2020-04-08 17:43:42 -04:00
(run-hooks '+julia-repl-start-hook)))
(defun +julia-override-repl-escape-char-h ()
"Use C-c instead of C-x for escaping."
(term-set-escape-char ?\C-c)))
2020-04-08 17:34:53 -04:00
(use-package! lsp-julia
:when (modulep! +lsp)
:unless (modulep! :tools lsp +eglot)
:after lsp-mode
:preface (setq lsp-julia-default-environment nil)
:init
;; If no environment is set, then auto-detect one in ~/.julia/environments/,
;; falling back to `lsp-julia-default-environment's default.
(unless lsp-julia-default-environment
(setq lsp-julia-default-environment
(or (car (last (doom-glob "~/.julia/environments/v*")))
"~/.julia/environments/v1.6"))))
(use-package! eglot-jl
:when (modulep! +lsp)
:when (modulep! :tools lsp +eglot)
:after eglot
:preface
;; Prevent auto-install of LanguageServer.jl
(setq eglot-jl-language-server-project
(or (car (last (doom-glob "~/.julia/environments/v*")))
"~/.julia/environments/v1.6"))
:init
;; Prevent timeout while installing LanguageServer.jl
(setq-hook! 'julia-mode-hook eglot-connect-timeout (max eglot-connect-timeout 60))
:config (eglot-jl-init))
2022-07-18 14:42:55 -05:00
(use-package! julia-snail
2022-09-15 14:28:12 -05:00
:when (modulep! +snail)
:when (modulep! :term vterm)
2022-07-18 14:42:55 -05:00
:hook (julia-mode . julia-snail-mode)
:config
(setq julia-snail-popup-display-eval-results :command)
(setq julia-snail-multimedia-enable t)
(setq julia-snail-popup-display-face '(:background base3 :box `(:line-width -1 :color base5)))
2022-07-18 14:42:55 -05:00
(set-popup-rule! "^\\*julia.*\\*$" :ttl nil :select nil :quit nil)
(after! julia-mode
(set-repl-handler! 'julia-mode #'+julia/open-snail-repl
:persist t
;; FIXME These aren't working as expected
:send-region #'julia-snail-send-region
:send-buffer #'julia-snail-send-buffer-file))
2022-07-18 14:42:55 -05:00
(map! (:localleader
(:map (julia-snail-mode-map)
2022-12-11 12:07:46 -06:00
"'" #'julia-snail
"a" #'julia-snail-package-activate
"r" #'julia-snail-update-module-cache
"d" #'julia-snail-doc-lookup
(:prefix ("e" . "eval")
"b" #'julia-snail-send-buffer-file
"l" #'julia-snail-send-line
"r" #'julia-snail-send-region
"e" #'julia-snail-send-dwim))
(:map (julia-snail-repl-mode-map)
2022-12-11 12:07:46 -06:00
"a" #'julia-snail-package-activate
"d" #'julia-snail-doc-lookup
"m" #'julia-snail-repl-go-back
"r" #'julia-snail-update-module-cache))))