doomemacs/modules/feature/eval/config.el

92 lines
3.2 KiB
EmacsLisp
Raw Normal View History

;;; feature/eval/config.el -*- lexical-binding: t; -*-
2017-02-13 16:57:08 -05:00
2017-03-04 18:28:51 -05:00
;;
;; REPLs
;;
(defvar +eval-repls nil
"An alist mapping major modes to plists that describe REPLs. Used by
`+eval/open-repl' and filled with the `:repl' setting.")
2017-03-04 18:28:51 -05:00
(define-minor-mode +eval-repl-mode
"A minor mode for REPL buffers.")
2017-02-13 16:57:08 -05:00
(def-setting! :repl (mode command)
"Define a REPL for a mode. MODE is a major mode symbol and COMMAND is a
function that creates and returns the REPL buffer."
`(push (cons ,mode ,command) +eval-repls))
2017-03-04 18:28:51 -05:00
(set! :popup
'(:custom (lambda (b &rest _) (buffer-local-value '+eval-repl-mode b)))
:size 16 :noesc t)
;;
;; Evaluation
;;
;; remove ellipsis when printing sexps in message buffer
(setq eval-expression-print-length nil
eval-expression-print-level nil)
2017-02-13 16:57:08 -05:00
(defvar +eval-runners nil
"Alist mapping major modes to interactive runner functions.")
(def-setting! :eval (mode command)
2017-03-04 18:28:51 -05:00
"Define a code evaluator for major mode MODE with `quickrun'.
2017-02-19 18:40:52 -05:00
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
2017-03-04 18:28:51 -05:00
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'."
(let ((command (doom-unquote command)))
(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
,(symbol-name (doom-unquote mode))
',command :mode ,mode))))))
2017-02-13 16:57:08 -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
(unless (boundp 'display-line-numbers)
(add-hook 'quickrun--mode-hook #'nlinum-mode))
2017-02-13 16:57:08 -05:00
:config
(set! :popup "*quickrun*" :size 6 :autokill t :autoclose t)
2017-02-13 16:57:08 -05:00
2017-03-04 18:28:51 -05:00
(defun +eval*quickrun-auto-close (&rest _)
2017-02-28 12:12:09 -05:00
"Allows us to silently re-run quickrun from within the quickrun buffer."
(when-let* ((win (get-buffer-window quickrun--buffer-name)))
2017-03-04 18:28:51 -05:00
(let ((inhibit-message t))
(quickrun--kill-running-process)
2017-02-13 16:57:08 -05:00
(message ""))
2017-03-04 18:28:51 -05:00
(delete-window win)))
(advice-add #'quickrun :before #'+eval*quickrun-auto-close)
(advice-add #'quickrun-region :before #'+eval*quickrun-auto-close)
2017-02-13 16:57:08 -05:00
2017-03-04 18:28:51 -05:00
(defun +eval|quickrun-scroll-to-bof ()
2017-02-28 12:12:09 -05:00
"Ensures window is scrolled to BOF on invocation."
2017-03-04 18:28:51 -05:00
(with-selected-window (get-buffer-window quickrun--buffer-name)
(goto-char (point-min))
(doom-popup-fit-to-buffer)))
(add-hook 'quickrun-after-run-hook #'+eval|quickrun-scroll-to-bof))
2017-02-13 16:57:08 -05:00