2017-06-08 11:47:56 +02:00
|
|
|
;;; feature/eval/autoload/eval.el -*- lexical-binding: t; -*-
|
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)
|
2017-10-03 02:49:08 +02:00
|
|
|
(cond ((assq major-mode +eval-runners)
|
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-10-03 02:49:08 +02:00
|
|
|
"Evaluate a region between BEG and END and display the output."
|
2017-02-13 16:57:08 -05:00
|
|
|
(interactive "r")
|
|
|
|
(let ((load-file-name buffer-file-name))
|
2017-12-10 14:49:52 -05:00
|
|
|
(if-let* ((runner (cdr (assq major-mode +eval-runners))))
|
2017-05-07 02:27:54 +02:00
|
|
|
(funcall runner beg end)
|
|
|
|
(quickrun-region beg end))))
|
2017-02-13 16:57:08 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2017-03-04 18:28:51 -05:00
|
|
|
(defun +eval/region-and-replace (beg end)
|
2017-10-03 02:49:08 +02:00
|
|
|
"Evaluation a region between BEG and END, and replace it with the result."
|
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))))
|
|
|
|
|