-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharei-module.el
90 lines (74 loc) · 2.93 KB
/
arei-module.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
;;; arei-module.el --- Module Operations for Arei -*- lexical-binding: t; -*-
;; Copyright © 2023, 2024 Andrew Tropin <[email protected]>
;; Copyright © 2024 Nikita Domnitskii
;; Author: Andrew Tropin <[email protected]>
;; 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:
;; Module Operations for Arei
;;; Code:
(require 'arei-evaluation)
(require 'arei-syntax)
(defun arei--get-modules ()
(read (arei--get-expression-value
"(map (lambda (m) (format #f \"~a\" (module-name m)))
((@ (ares reflection modules) all-modules)))")))
(defun arei--get-module-filename (module)
(let ((value
(arei--get-expression-value
(format "((@ (ares reflection modules) module-filename)
(resolve-module '%s))"
module))))
(unless (string= value "#f")
(read value))))
(defun arei-goto-module (module)
"Go to module source file if it is available."
(interactive
(list
(completing-read "Module: " (arei--get-modules) nil t)))
(let ((filename (arei--get-module-filename module)))
(if filename
(find-file filename)
(message "This module doesn't have corresponding filename. (Or \
we couldn't figure it out)"))))
(defun arei--process-module-response-callback (module)
(lambda (response)
(let ((status (arei-nrepl-dict-get response "status"))
(value (arei-nrepl-dict-get response "value")))
(when (equal '("done") status)
(if (string= "module-not-found" value)
(message "%s: Module not found. Please make sure it's on \
load-path or create it manually." module)
(message "%s: Module reloaded." module)))
(when (member "interrupted" status)
(message "%s: Module reloading was interrupted, probably
because it takes too much time, check if there are any top-level
forms causing infinite recursions,expensive computations or
something like that."
module)))))
(defun arei-reload-module ()
(interactive)
(let* ((module (arei-current-module))
(response
(arei--eval
(format "\
(let ((m (resolve-module '%s #:ensure #f)))
(if m
(begin
(module-clear! m)
(reload-module m))
'module-not-found))
" module)
(arei--process-module-response-callback module))))))
(defvar-keymap arei-module-map
"M-r" #'arei-reload-module
"M-m" #'arei-goto-module)
(provide 'arei-module)