2019-04-21 19:59:44 -04:00
|
|
|
;;; tools/eval/autoload/settings.el -*- lexical-binding: t; -*-
|
2018-06-15 16:07:24 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; REPLs
|
|
|
|
|
|
|
|
(defvar +eval-repls nil
|
|
|
|
"An alist mapping major modes to plists that describe REPLs. Used by
|
2019-02-18 01:56:38 -05:00
|
|
|
`+eval/open-repl-other-window' and filled with the `:repl' setting.")
|
2018-06-15 16:07:24 +02:00
|
|
|
|
|
|
|
;;;###autodef
|
2019-10-23 21:39:19 -04:00
|
|
|
(defun set-repl-handler! (modes command &rest plist)
|
2018-08-15 09:24:53 +02:00
|
|
|
"Defines a REPL for MODES.
|
|
|
|
|
|
|
|
MODES is either a single major mode symbol or a list of them. COMMAND is a
|
|
|
|
function that creates and returns the REPL buffer.
|
|
|
|
|
|
|
|
COMMAND can either be a function that takes no arguments, or an interactive
|
2019-10-08 17:40:39 -04:00
|
|
|
command that will be called interactively. COMMANDS must return either the repl
|
2019-10-23 21:39:19 -04:00
|
|
|
buffer or a function that takes no arguments and returns the repl buffer.
|
|
|
|
|
|
|
|
PLIST is a property list that map special attributes to this repl. These are
|
|
|
|
recognized:
|
|
|
|
|
|
|
|
:persist BOOL
|
|
|
|
If non-nil, this REPL won't be killed when its window is closed."
|
2019-10-08 17:40:39 -04:00
|
|
|
(declare (indent defun))
|
2018-07-14 20:18:02 +02:00
|
|
|
(dolist (mode (doom-enlist modes))
|
2019-10-23 21:39:19 -04:00
|
|
|
(setf (alist-get mode +eval-repls)
|
|
|
|
(cons command plist))))
|
2018-06-15 16:07:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Evaluation
|
|
|
|
|
2018-09-10 22:57:26 -04:00
|
|
|
;;;###autoload
|
2018-06-15 16:07:24 +02:00
|
|
|
(defvar +eval-runners nil
|
|
|
|
"Alist mapping major modes to interactive runner functions.")
|
|
|
|
|
|
|
|
;;;###autodef
|
|
|
|
(defun set-eval-handler! (mode command)
|
|
|
|
"Define a code evaluator for major mode MODE with `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 (for `quickrun--language-alist'), and will be registered
|
|
|
|
in `quickrun--major-mode-alist'.
|
|
|
|
3. If MODE is not a string and COMMAND is an alist, see `quickrun-add-command':
|
|
|
|
(quickrun-add-command MODE COMMAND :mode MODE).
|
|
|
|
4. If MODE is not a string and COMMANd is a symbol, add it to
|
|
|
|
`+eval-runners', which is used by `+eval/region'."
|
2018-06-22 01:30:27 +02:00
|
|
|
(declare (indent defun))
|
2018-06-15 16:07:24 +02:00
|
|
|
(cond ((symbolp command)
|
|
|
|
(push (cons mode command) +eval-runners))
|
|
|
|
((stringp command)
|
|
|
|
(after! quickrun
|
|
|
|
(push (cons mode command)
|
|
|
|
(if (stringp mode)
|
|
|
|
quickrun-file-alist
|
|
|
|
quickrun--major-mode-alist))))
|
|
|
|
((listp command)
|
|
|
|
(after! quickrun
|
|
|
|
(quickrun-add-command
|
2018-10-07 00:36:34 -04:00
|
|
|
(or (cdr (assq mode quickrun--major-mode-alist))
|
|
|
|
(string-remove-suffix "-mode" (symbol-name mode)))
|
2018-06-15 16:07:24 +02:00
|
|
|
command :mode mode)))))
|