Skip to content

Commit

Permalink
wrap comint-send-input to get term-like indentation and history
Browse files Browse the repository at this point in the history
  • Loading branch information
dellison committed Jan 25, 2019
1 parent c4ab0fe commit 423cd83
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions julia-repl-comint.el
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,48 @@ probably be using `julia-repl-send-region-or-line'."
(delete-backward-char 1)))))


(defun julia-repl-comint-maybe-send-input ()
"Send the input to the julia process (or add a newline and indent if
it's an incomplete julia expression)."
(interactive)
(when completion-in-region-mode
(completion-in-region-mode -1))
(let ((proc (get-buffer-process (current-buffer))))
(if (not proc) (user-error "No Julia process is running!")
(widen)
(let* ((pmark (process-mark proc))
(intxt (if (>= (point) (marker-position pmark))
(progn (if comint-eol-on-send
(if comint-use-prompt-regexp
(end-of-line)
(goto-char (field-end))))
(buffer-substring pmark (point)))
(let ((copy (funcall comint-get-old-input)))
(goto-char pmark)
(insert copy)
copy)))
(input (if (not (eq comint-input-autoexpand 'input))
;; Just whatever's already there.
intxt
;; Expand and leave it visible in buffer.
(comint-replace-by-expanded-history t pmark)
(buffer-substring pmark (point))))
(jl-call (format "Base.parse_input_line(\"%s\")" input))
(result (julia-repl-comint--result-as-string jl-call))
(is-incomplete-expression (or (string-match-p "Expr(:incomplete" result)
(string-match-p "Expr(:continue" result))))
(if (or (= (length input) 0) (not is-incomplete-expression)
(string-match-p "^[\];\?]" input))
(comint-send-input)
(insert "\n "))))))

(defvar julia-repl-inferior-julia-mode-map
(let ((keymap (copy-keymap comint-mode-map)))
(define-key keymap (kbd "]") #'julia-repl-comint-r-square-bracket)
(define-key keymap (kbd "?") #'julia-repl-comint-question-mark)
(define-key keymap (kbd ";") #'julia-repl-comint-semicolon)
(define-key keymap (kbd "DEL") #'julia-repl-comint-backspace)
(define-key keymap (kbd "RET") #'julia-repl-comint-maybe-send-input)
keymap)
"Key bindings for the Julia REPL running in the comint buffer.")

Expand Down

0 comments on commit 423cd83

Please sign in to comment.