#-*- mode: org -*-
#+TITLE: Emacs Setup for Julia Programming Language
#+AUTHOR: Volker Edelmann
#+EMAIL:  vedelmann@gmx.de
#+STARTUP: indent
#+OPTIONS:  toc:nil
#+OPTIONS:   ^:{}

#+begin_src emacs-lisp
  ;; -*- coding: utf-8; lexical-binding: t -*-
#+end_src


* Tree-sitter
#+begin_src emacs-lisp
  (push '(julia-mode . julia-ts-mode) major-mode-remap-alist)
#+end_src

- moving around: ts-movement
- selections:
  - expreg
  - paragraph-selections, if blank lines are used to structure the code

* Folding

*origami* funktioniert gut f"ur Julia


* Julia

#+begin_src emacs-lisp
    (use-package eglot-jl
        :commands eglot-jl-init
	:config
	(setq eglot-connect-timeout 300)
	(setq eglot-jl-julia-command julia-program)
    )
#+end_src

#+begin_src emacs-lisp
  (use-package julia-ts-mode
    :after eglot
    :init (setenv "JULIA_NUM_THREADS" "6")
    :bind (
       :map julia-ts-mode-map
  	("C-c C-z"  . julia-snail)
  	("+"        . expreg-expand)
  	("-"        . expreg-contract)
  	("="        . yas-insert-snippet)
  	;; ("<tab>"    . completion-at-point)
  	("<f3>"     .  list-flycheck-errors)
        )
    :hook
     (julia-ts-mode . julia-snail-mode)
     (julia-ts-mode . eglot-ensure)
     (julia-ts-mode . eglot-jl-init)
     (julia-ts-mode . yas-minor-mode)
    )

#+end_src


    |---------+---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------|
    | key     | command                         | description                                                                                                                            |
    |---------+---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------|
    | C-c C-z | julia-snail                     | start a REPL; flip between REPL and source                                                                                             |
    | C-c C-a | julia-snail-package-activate    | activate the project using Project.toml                                                                                                |
    | C-c C-d | julia-snail-doc-lookup          | display the docstring of the identifier at point                                                                                       |
    | C-c C-l | julia-snail-send-line           | evaluate current line in the current module (or in Main with prefix arg; or copy directly to REPL with two prefix args)                |
    | C-c C-r | julia-snail-send-region         | evaluate active region in the current module (or in Main with prefix arg; or copy directly to REPL with two prefix args)               |
    | C-c C-e | julia-snail-send-dwim           | if region active, evaluate it in current module; else if on top-level block, evaluate it in current module; else evaluate current line |
    | C-c C-c | julia-snail-send-top-level-form | evaluate end-terminated block around the point in the current module                                                                   |
    | C-M-x   | julia-snail-send-top-level-form | ditto                                                                                                                                  |
    | C-c C-R | julia-snail-update-module-cache | update module-nested include cache (mainly for Revise)                                                                                 |
    | C-c C-k | julia-snail-send-buffer-file    | include() the current buffer’s file                                                                                                    |
    |---------+---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------|

#+begin_src emacs-lisp
  (use-package julia-snail
    :after julia-ts-mode
    :custom
    (julia-snail-terminal-type :eat)
    :config
    (setq julia-snail-use-emoji-mode-lighter t)
    (setq julia-snail-popup-display-eval-results nil)
    (setq julia-snail-repl-display-eval-results t)
    (setq julia-snail-show-error-window t)
    (setq julia-snail-doc-lookup t)
    (setq julia-snail-multimedia-buffer-style :single-reuse)
    (setq julia-snail/ob-julia-mirror-output-in-repl t)
    (setq julia-snail/ob-julia-capture-io t)
    ;;   :init ;; Setup completion at point
    ;;   (add-hook 'julia-snail-mode-hook
    ;;      (lambda ()
    ;;    (remove-hook 'completion-at-point-functions #'julia-snail-repl-completion-at-point t)
    ;;    )
    ;;   )
    :bind (
           :map julia-snail-mode-map
           ("S-<return>"   . julia-snail-send-line)
           ("C-<return>"   . julia-snail-send-region)
           ("M-<return>"   . julia-snail-send-dwim)
  	 ("C-M-<return>" . julia-snail-send-buffer-file)
           ("C-M-x"        . nil)
           :map julia-snail-repl-mode-map
           ("M-o"   . ace-window)
           )
    )
#+end_src
not working (call function manually when repl is running):
   :hook
	 (julia-snail-multimedia-toggle-display-in-emacs)

** Formatting
use snail extension

** TODO Linting

** TODO Debugging

** UI

#+begin_src emacs-lisp
#+end_src

    "C-z"      '(julia-snail          :wk "REPL")


Categories not yet used:

"Debug"
   (
    ()
   )
Test"
   (
    ("t" ert "prompt")
    ("T" (ert t) "all")
    ("F" (ert :failed) "failed")
   )
"Doc"
   (
    ("i" info-lookup-symbol "info lookup")
   )