-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ueval.el
113 lines (91 loc) · 3.3 KB
/
ueval.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
;;; ueval.el --- Universal Evaluation Utilities -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Shen, Jen-Chieh
;; Author: Shen, Jen-Chieh <jcs090218@gmail.com>
;; Maintainer: Shen, Jen-Chieh <jcs090218@gmail.com>
;; URL: https://github.com/jcs-elpa/ueval
;; Version: 0.1.0
;; Package-Requires: ((emacs "26.1"))
;; Keywords: convenience eval
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Universal Evaluation Utilities.
;;
;;; Code:
(defgroup ueval nil
"Universal Evaluation Utilities."
:prefix "ueval-"
:group 'ueval)
;;
;;; Util
(defun ueval--fboundp-apply (fnc &rest args)
"Call FNC with ARGS if exists."
(when (fboundp fnc) (apply fnc args)))
;;
;;; Extensions
(declare-function sly-connected-p "ext:sly.el")
(declare-function sly-eval-buffer "ext:sly.el")
(declare-function sly-eval-defun "ext:sly.el")
(declare-function sly-eval-last-expression "ext:sly.el")
(declare-function sly-eval-region "ext:sly.el")
(defun ueval--sly-p ()
"Return non-nil; use `sly' evaluations instead."
(when (and (featurep 'sly)
(memq major-mode '(lisp-mode)))
(ueval--fboundp-apply #'sly-connected-p)))
(declare-function cider-connected-p "ext:cider.el")
(declare-function cider-eval-buffer "ext:cider.el")
(declare-function cider-eval-defun-at-point "ext:cider.el")
(declare-function cider-eval-sexp-at-point "ext:cider.el")
(declare-function cider-eval-region "ext:cider.el")
(defun ueval--cider-p ()
"Return non-nil; use `cider' evaluations instead."
(when (and (featurep 'cider)
(memq major-mode '(clojure-mode clojurescript-mode)))
(ueval--fboundp-apply #'cider-connected-p)))
;;
;;; Core
;;;###autoload
(defun ueval-buffer ()
"Universal `eval-buffer'."
(interactive)
(call-interactively
(cond ((ueval--sly-p) #'sly-eval-buffer)
((ueval--cider-p) #'cider-eval-buffer)
(t #'eval-buffer))))
;;;###autoload
(defun ueval-defun ()
"Universal `eval-defun' command."
(interactive)
(call-interactively
(cond ((ueval--sly-p) #'sly-eval-defun)
((ueval--cider-p) #'cider-eval-defun-at-point)
(t #'eval-defun))))
;;;###autoload
(defun ueval-expression ()
"Universal `eval-expression' command."
(interactive)
(call-interactively
(cond ((ueval--sly-p) #'sly-eval-last-expression)
((ueval--cider-p) #'cider-eval-sexp-at-point)
(t #'eval-expression))))
;;;###autoload
(defun ueval-region ()
"Universal `eval-region' command."
(interactive)
(call-interactively
(cond ((ueval--sly-p) #'sly-eval-region)
((ueval--cider-p) #'cider-eval-region)
(t #'eval-region))))
(provide 'ueval)
;;; ueval.el ends here