-
Notifications
You must be signed in to change notification settings - Fork 25
Tips and Tricks
The default workflow for Julia is to edit the code and then use julia-snail-send-buffer-file
, julia-snail-send-region
, or julia-snail-send-top-level-form
to update the Julia process running in the REPL.
You would generally start by using julia-snail-send-buffer-file
on the root file of your project, and proceed to use REPL-driven development as you see fit.
Revise is a popular tool for automatically updating the state of a Julia session. If you use it, then you no longer need to use julia-snail-send-buffer-file
, julia-snail-send-region
, or julia-snail-send-top-level-form
. Snail is compatible with Revise: xref and autocomplete will work as expected as you modify your code.
NB: Revise requires careful use of julia-snail-update-module-cache
. See the main documentation in the README for details.
(Refer to the discussion which prompted this section.)
From dahtah (suggestion ticket link):
There’s a [potentially] better way to insert unicode characters [than the default provided by julia-mode], and it’s xah-math-input. Basically, you type a (Roman) letter like "a", then shift-spc, and it substitutes the Greek equivalent, here α. Much better than \alpha then Tab, especially when you get to \varepsilon. Here’s a function that makes it work in the REPL as well:
(defun julia-snail--xah-math-substitute ()
(interactive)
(save-excursion
(backward-char 1)
(let ((newchar (xah-math-input--abbr-to-symbol (thing-at-point 'char t))))
(forward-char 1)
(vterm-send-backspace)
(vterm-send-string newchar))))
and you can add
(define-key julia-snail-repl-mode-map (kbd "S-SPC") 'julia-snail--xah-math-substitute)
in your julia-snail-mode-hook
to make it work.
Snail usually tries to stick to stock Emacs facilities. In a few cases, it checks if a particular extra package is installed, and enables a little extra functionality.
If it detects company-mode
, Snail begins loads docstrings for completion candidates and puts them in a documentation buffer. This documentation buffer can either be displayed in a window, or shown next to the completion interface using company-quickhelp.
If you find this too slow or annoying, you can turn off this behavior:
(customize-set-variable 'julia-snail-company-doc-enable nil)
If something in Snail does not fit your workflow, most of its Emacs integrations can be selectively disabled. Modify the following as desired:
(add-hook 'julia-snail-mode-hook
(lambda ()
(remove-hook 'completion-at-point-functions #'julia-snail-company-capf t)
(remove-hook 'completion-at-point-functions #'julia-snail-repl-completion-at-point t)
(remove-function (local 'eldoc-documentation-function) #'julia-snail-eldoc)
(remove-hook 'xref-backend-functions #'julia-snail-xref-backend t)))
Note
|
This section is slightly outdated. julia-snail-send-region now copies code directly into the REPL when invoked with two prefix arguments (C-u C-u ).
|
A suggestion about using the REPL a little more like a notebook:
The following function copies a region of code into the REPL like julia-snail-send-line
, as opposed to julia-snail-send-region
which uses the Snail network connection to evaluate the code.
(defun julia-snail-copy-repl-region ()
"Copy the region (requires transient-mark) to the Julia REPL and evaluate it.
This is not module-context aware."
(interactive)
(if (null (use-region-p))
(user-error "No region selected")
(let* ((block-start (region-beginning))
(block-end (region-end))
(text (s-trim (buffer-substring-no-properties block-start block-end))))
(julia-snail--send-to-repl text)
(julia-snail--flash-region (point-at-bol) (point-at-eol)))))
JuliaSyntax.jl
is the new Julia parser in 1.10. It seems to cause problems when manually loaded in 1.9 and earlier, so please read the discussion here for tips on enabling it.