2017-03-04 18:28:51 -05:00
|
|
|
;;; feature/eval/autoload/eval.el
|
2017-02-13 16:57:08 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2017-03-04 18:28:51 -05:00
|
|
|
(defun +eval/buffer ()
|
2017-02-13 16:57:08 -05:00
|
|
|
"Evaluate the whole buffer."
|
|
|
|
(interactive)
|
|
|
|
(cond ((eq major-mode 'emacs-lisp-mode)
|
2017-03-04 18:28:51 -05:00
|
|
|
(+eval/region (point-min) (point-max)))
|
2017-02-13 16:57:08 -05:00
|
|
|
(t (quickrun))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2017-03-04 18:28:51 -05:00
|
|
|
(defun +eval/region (beg end)
|
2017-02-13 16:57:08 -05:00
|
|
|
"Evaluate a region and, if large enough, prints its output to a popup buffer (if an
|
|
|
|
elisp buffer). Otherwise forward the region to Quickrun."
|
|
|
|
(interactive "r")
|
|
|
|
(let ((load-file-name buffer-file-name))
|
|
|
|
(cond ((eq major-mode 'emacs-lisp-mode)
|
|
|
|
(require 'pp)
|
|
|
|
(let ((result (eval (read (buffer-substring-no-properties beg end))))
|
|
|
|
lines)
|
|
|
|
(let ((buf (get-buffer-create "*eval*")))
|
|
|
|
(with-current-buffer buf
|
|
|
|
;; FIXME messy!
|
|
|
|
(read-only-mode -1)
|
|
|
|
(setq-local scroll-margin 0)
|
|
|
|
(erase-buffer)
|
2017-03-19 22:52:17 -04:00
|
|
|
(emacs-lisp-mode)
|
2017-02-13 16:57:08 -05:00
|
|
|
(prin1 result buf)
|
|
|
|
(pp-buffer)
|
|
|
|
(read-only-mode 1)
|
|
|
|
(setq lines (count-lines (point-min) (point-max)))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(when (< lines 5)
|
|
|
|
(message "%s" (buffer-substring (point-min) (point-max)))
|
|
|
|
(kill-buffer buf)))
|
|
|
|
(unless (< lines 5)
|
|
|
|
(doom-popup-buffer buf)))))
|
|
|
|
(t (quickrun-region beg end)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2017-03-04 18:28:51 -05:00
|
|
|
(defun +eval/region-and-replace (beg end)
|
2017-02-13 16:57:08 -05:00
|
|
|
(interactive "r")
|
|
|
|
(cond ((eq major-mode 'emacs-lisp-mode)
|
|
|
|
(kill-region beg end)
|
|
|
|
(condition-case nil
|
|
|
|
(prin1 (eval (read (current-kill 0)))
|
|
|
|
(current-buffer))
|
|
|
|
(error (message "Invalid expression")
|
|
|
|
(insert (current-kill 0)))))
|
|
|
|
(t (quickrun-replace-region beg end))))
|
|
|
|
|