2017-02-13 16:57:08 -05:00
|
|
|
;;; feature/repl/config.el
|
|
|
|
|
|
|
|
;; + Running inline code using `quickrun'
|
|
|
|
;; + REPLs using `repl-toggle'
|
|
|
|
|
|
|
|
(defvar doom-repl-buffer nil
|
|
|
|
"The current REPL buffer.")
|
|
|
|
|
|
|
|
(defvar +eval-builders (make-hash-table :test 'equal)
|
|
|
|
"A hash-table of plists, containing functions for building source code. Used
|
|
|
|
by `+eval/build', and filled with the `:build' setting")
|
|
|
|
|
|
|
|
;; remove ellipsis when printing sexp in message buffer
|
|
|
|
(setq eval-expression-print-length nil
|
|
|
|
eval-expression-print-level nil)
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-setting! :repl (mode command)
|
2017-02-28 12:12:09 -05:00
|
|
|
"Define a REPL for a mode. Takes the same arguements as `rtog/add-repl'."
|
2017-02-27 21:28:40 -05:00
|
|
|
`(after! repl-toggle
|
|
|
|
(rtog/add-repl ',mode ',command)))
|
2017-02-13 16:57:08 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-setting! :build (name mode pred-fn &optional build-fn)
|
2017-02-13 16:57:08 -05:00
|
|
|
"Define a build command function (BUILD-FN) for major-mode MODE, called NAME
|
2017-02-19 18:40:52 -05:00
|
|
|
-- a symbol -- PRED-FN is a predicate function that determines this builder's
|
2017-02-13 16:57:08 -05:00
|
|
|
suitability for the current buffer."
|
2017-02-19 18:40:52 -05:00
|
|
|
(unless build-fn
|
|
|
|
(setq build-fn pred-fn
|
|
|
|
pred-fn nil))
|
2017-02-13 16:57:08 -05:00
|
|
|
`(puthash ',(cons name mode)
|
|
|
|
(list :predicate ,pred-fn :fn ,build-fn)
|
|
|
|
+eval-builders))
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-setting! :eval (mode command)
|
2017-02-19 18:40:52 -05:00
|
|
|
"Define a code evaluator for `quickrun'.
|
|
|
|
|
|
|
|
1. If MODE is a string and COMMAND is the string, MODE is a file regexp and
|
|
|
|
COMMAND is a string key for an entry in `quickrun-file-alist'.
|
|
|
|
2. If MODE is not a string and COMMAND is a string, MODE is a major-mode symbol
|
|
|
|
and COMMAND is a key; they will be registered in
|
|
|
|
`quickrun--major-mode-alist'.
|
|
|
|
3. If MODE is not a string and COMMAND is a list, use `quickrun-add-command'. e.g.
|
|
|
|
(quickrun-add-command MODE COMMAND :mode MODE)"
|
|
|
|
(if (stringp command)
|
2017-02-23 00:06:12 -05:00
|
|
|
`(after! quickrun
|
2017-02-27 21:22:10 -05:00
|
|
|
(push ',(cons mode command)
|
2017-02-19 18:40:52 -05:00
|
|
|
,(if (stringp mode)
|
|
|
|
'quickrun-file-alist
|
|
|
|
'quickrun--major-mode-alist)))
|
2017-02-23 00:06:12 -05:00
|
|
|
`(after! quickrun
|
2017-02-19 18:40:52 -05:00
|
|
|
(quickrun-add-command
|
|
|
|
,(symbol-name mode)
|
|
|
|
',command :mode ',mode))))
|
2017-02-13 16:57:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Packages
|
|
|
|
;;
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! quickrun
|
2017-02-13 16:57:08 -05:00
|
|
|
:commands (quickrun
|
|
|
|
quickrun-region
|
|
|
|
quickrun-with-arg
|
|
|
|
quickrun-shell
|
|
|
|
quickrun-compile-only
|
|
|
|
quickrun-replace-region)
|
2017-02-28 12:12:09 -05:00
|
|
|
:init
|
|
|
|
(add-hook 'quickrun/mode-hook 'linum-mode)
|
2017-02-13 16:57:08 -05:00
|
|
|
:config
|
2017-02-23 00:06:12 -05:00
|
|
|
(set! :popup "*quickrun*" :size 10)
|
2017-02-13 16:57:08 -05:00
|
|
|
|
|
|
|
;; don't auto-focus quickrun windows. Shackle handles that for us.
|
|
|
|
(setq quickrun-focus-p nil)
|
|
|
|
|
|
|
|
(defun +repl*quickrun-close-popup (&optional _ _ _ _)
|
2017-02-28 12:12:09 -05:00
|
|
|
"Allows us to silently re-run quickrun from within the quickrun buffer."
|
2017-02-13 16:57:08 -05:00
|
|
|
(awhen (get-buffer-window quickrun/buffer-name)
|
|
|
|
(let (message-log-max)
|
|
|
|
(quickrun/kill-running-process)
|
|
|
|
(message ""))
|
2017-02-19 18:40:52 -05:00
|
|
|
(doom/popup-close it)))
|
2017-02-13 16:57:08 -05:00
|
|
|
|
|
|
|
(defun +repl|quickrun-scroll-to-bof ()
|
2017-02-28 12:12:09 -05:00
|
|
|
"Ensures window is scrolled to BOF on invocation."
|
2017-02-13 16:57:08 -05:00
|
|
|
(with-selected-window (get-buffer-window quickrun/buffer-name)
|
|
|
|
(goto-char (point-min))))
|
|
|
|
|
|
|
|
;;; Popup hacks
|
|
|
|
(advice-add 'quickrun :before '+repl*quickrun-close-popup)
|
|
|
|
(advice-add 'quickrun-region :before '+repl*quickrun-close-popup)
|
|
|
|
;; Ensures window is scrolled to BOF
|
|
|
|
(add-hook 'quickrun-after-run-hook '+repl|quickrun-scroll-to-bof))
|
|
|
|
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! repl-toggle
|
2017-02-13 16:57:08 -05:00
|
|
|
:commands rtog/toggle-repl
|
|
|
|
:preface (defvar rtog/mode-repl-alist nil)
|
|
|
|
:config
|
2017-02-23 00:06:12 -05:00
|
|
|
(set! :popup
|
2017-02-19 18:40:52 -05:00
|
|
|
'(:custom (lambda (b &rest _)
|
|
|
|
(when (and (featurep 'repl-toggle)
|
|
|
|
(string-prefix-p "*" (buffer-name (get-buffer b))))
|
|
|
|
(buffer-local-value 'repl-toggle-mode b))))
|
2017-02-28 12:12:09 -05:00
|
|
|
:size 16)
|
2017-02-13 16:57:08 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(map! :map repl-toggle-mode-map
|
2017-02-13 16:57:08 -05:00
|
|
|
:ei "C-n" 'comint-next-input
|
|
|
|
:ei "C-p" 'comint-previous-input
|
|
|
|
:ei "<down>" 'comint-next-input
|
|
|
|
:ei "<up>" 'comint-previous-input))
|
|
|
|
|