Skip to content

Commit

Permalink
Work with proposed updates to julia-mode LaTeX completion
Browse files Browse the repository at this point in the history
JuliaEditorSupport/julia-emacs#100 changes
LaTeX completion in julia-mode to work by a combination of
completion-at-point-function and abbrev-mode. This is the necessary
change to give full-featured LaTeX completion with emacs-jupyter julia
buffers with the PR in its current form.
  • Loading branch information
non-Jedi committed May 11, 2023
1 parent 4551667 commit 40e6b03
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions jupyter-julia.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
(eval-when-compile (require 'subr-x))
(require 'jupyter-repl)

(declare-function julia-latexsub-or-indent "ext:julia-mode" (arg))

(cl-defmethod jupyter-indent-line (&context (major-mode julia-mode))
"Call `julia-latexsub-or-indent'."
(call-interactively #'julia-latexsub-or-indent))
(declare-function julia-mode-latexsub-completion-at-point-before
"ext:julia-mode" ())
(declare-function julia-mode-latexsub-completion-at-point-around
"ext:julia-mode" ())

(cl-defmethod jupyter-load-file-code (file &context (jupyter-lang julia))
(format "include(\"%s\");" file))
Expand Down Expand Up @@ -68,18 +67,6 @@
(not (memq (char-syntax (char-before (1- beg))) '(?w ?_))))
(setcar prefix (concat ":" (car prefix))))))))))))

(cl-defmethod jupyter-completion-post-completion (candidate
&context (jupyter-lang julia))
"Insert the unicode representation of a LaTeX completion."
(if (eq (aref candidate 0) ?\\)
(when (get-text-property 0 'annot candidate)
(search-backward candidate)
(delete-region (point) (match-end 0))
;; Alternatively use `julia-latexsub-or-indent', but I have found
;; problems with that.
(insert (string-trim (get-text-property 0 'annot candidate))))
(cl-call-next-method)))

;;; `markdown-mode'

(cl-defmethod jupyter-markdown-follow-link (link-text url _ref-label _title-text _bang
Expand Down Expand Up @@ -188,6 +175,7 @@ nil."
;;; `jupyter-repl-after-init'

(defun jupyter-julia--setup-hooks (client)
(require 'julia-mode)
(let ((jupyter-inhibit-handlers t))
(jupyter-send-execute-request client
:store-history nil
Expand All @@ -208,7 +196,18 @@ if !isdefined(Main, :__JUPY_saved_dir)
IJulia.push_posterror_hook(popdir)
IJulia.push_postexecute_hook(popdir)
end
end")))
end"))
(add-hook 'completion-at-point-functions
#'julia-mode-latexsub-completion-at-point-before nil t)
(add-hook 'completion-at-point-functions
#'julia-mode-latexsub-completion-at-point-around nil t)
(define-abbrev-table 'jupyter-julia-abbrev-table ()
"Abbrev table for IJulia kernel with jupyter."
:parents (list julia-latexsub-abbrev-table))
(setq local-abbrev-table jupyter-julia-abbrev-table)
(when julia-force-tab-complete
(setq-local tab-always-indent 'complete)
(abbrev-mode 1)))

(cl-defmethod jupyter-repl-after-init (&context (jupyter-lang julia))
(add-function
Expand Down

0 comments on commit 40e6b03

Please sign in to comment.