diff --git a/contrib/julia-mode.el b/contrib/julia-mode.el index d3d5a2a3882af..c896870b85ee8 100644 --- a/contrib/julia-mode.el +++ b/contrib/julia-mode.el @@ -3095,6 +3095,63 @@ end")) (puthash "\\mtteight" "𝟾" julia-latexsubs) (puthash "\\mttnine" "𝟿" julia-latexsubs) +;; Code for `inferior-julia-mode' +(require 'comint) + +(defgroup julia + '() + "Julia Programming Language." + :group 'languages + :prefix "julia-") + +(defcustom julia-program "julia" + "Path to the program used by `inferior-julia'." + :type 'string + :group 'julia) + +(defcustom julia-arguments '() + "Commandline arguments to pass to `julia-program'." + :type 'string + :group 'julia) + +(defvar julia-prompt-regexp "julia>" + "Regexp for matching `inferior-julia' prompt.") + +(defvar inferior-julia-mode-map + (let ((map (nconc (make-sparse-keymap) comint-mode-map))) + ;; example definition + (define-key map (kbd "TAB") 'julia-latexsub-or-indent) + map) + "Basic mode map for `inferior-julia-mode'.") + +;;;###autoload +(defun inferior-julia () + "Run an inferior instance of `julia' inside Emacs." + (interactive) + (let ((julia-program julia-program) + (buffer (get-buffer-create "*Julia*"))) + (when (not (comint-check-proc "*Julia*")) + (apply #'make-comint-in-buffer "Julia" "*Julia*" julia-program julia-arguments)) + (pop-to-buffer-same-window "*Julia*") + (inferior-julia-mode))) + +(defun inferior-julia--initialize () + "Helper function to initialize `inferior-julia'." + (setq comint-use-prompt-regexp t)) + +(define-derived-mode inferior-julia-mode comint-mode "Julia" + "Major mode for `inferior-julia'. + +\\" + nil "Julia" + (setq comint-prompt-regexp julia-prompt-regexp) + (setq comint-prompt-read-only t) + (set (make-local-variable 'font-lock-defaults) '(julia-font-lock-keywords t)) + (set (make-local-variable 'paragraph-start) julia-prompt-regexp) + (set (make-local-variable 'indent-line-function) 'julia-indent-line)) + +(add-hook 'inferior-julia-mode-hook 'inferior-julia--initialize) + (provide 'julia-mode) ;; Local Variables: