4
4
5
5
; ; Author: Antoine R. Dumont <eniotna.t AT gmail.com>
6
6
; ; Maintainer: Antoine R. Dumont <eniotna.t AT gmail.com>
7
- ; ; Version: 0.0.4
7
+ ; ; Version: 0.0.5
8
8
; ; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1") (deferred "0.3.2"))
9
9
; ; Keywords: purescript psci repl major mode
10
10
; ; URL: https://github.com/ardumont/emacs-psci
38
38
; ; to purescript-mode:
39
39
; ; (add-hook 'purescript-mode-hook 'inferior-psci-mode)
40
40
41
- ; ; To activate psci directly from a purescript-mode buffer, you
42
- ; ; could use repl-toggle (available on melpa):
41
+ ; ; To come back and forth between a purescript-mode buffer and
42
+ ; ; repl, you could use repl-toggle (available on melpa):
43
43
; ; (require 'repl-toggle)
44
44
; ; (add-to-list 'rtog/mode-repl-alist '(purescript-mode . psci))
45
45
55
55
(require 'f )
56
56
(require 'deferred )
57
57
58
+ ; ; constants or variables
59
+
58
60
(defvar psci/buffer-name " psci"
59
61
" Buffer name of the psci buffer." )
60
62
61
- (defun psci/process-name (buffer-name )
62
- " Compute the buffer's process name based on BUFFER-NAME."
63
- (format " *%s * " buffer-name))
64
-
65
63
(defvar psci/file-path " psci"
66
64
" Path to the program used by `psci' function." )
67
65
68
66
(defvar psci/arguments '()
69
67
" Commandline arguments to pass to `psci' function." )
70
68
71
- (defvar psci-mode-map
72
- (let ((map (nconc (make-sparse-keymap ) comint-mode-map)))
73
- (define-key map " \t " 'completion-at-point )
74
- map)
75
- " Basic mode map for `psci' ." )
76
-
77
69
(defvar psci/prompt " > "
78
70
" The psci prompt." )
79
71
72
+ (defvar psci/project-module-file " .psci"
73
+ " The default file referencing the purescript modules to load at psci startup." )
74
+
75
+ (defvar psci/--modules-folder " .psci_modules"
76
+ " The modules folder psci uses as cache." )
77
+
78
+ ; ; private functions
79
+
80
+ (defun psci/--project-root! ()
81
+ " Determine the project's root folder."
82
+ (->> psci/project-module-file
83
+ (locate-dominating-file default-directory)
84
+ expand-file-name))
85
+
86
+ (defun psci/--process-name (buffer-name )
87
+ " Compute the buffer's process name based on BUFFER-NAME."
88
+ (format " *%s * " buffer-name))
89
+
90
+ (defun psci/--file-content (filename )
91
+ " Load the FILENAME's content as a string.
92
+ When FILENAME is nil or not a real file, returns nil."
93
+ (when (and filename (file-exists-p filename))
94
+ (with-temp-buffer
95
+ (insert-file-contents filename)
96
+ (buffer-substring-no-properties (point-min ) (point-max )))))
97
+
98
+ (defun psci/--project-psci-file (project-root-folder )
99
+ " Compute the project's psci file from the PROJECT-ROOT-FOLDER.
100
+ Returns nil if no .psci file is found."
101
+ (let ((psci-module-file (expand-file-name psci/project-module-file project-root-folder)))
102
+ (when (file-exists-p psci-module-file)
103
+ psci-module-file)))
104
+
105
+ (defun psci/--project-module-files! ()
106
+ " Compulse the list of modules for the current project.
107
+ Assumes the location of the modules is the project root folder."
108
+ (let* ((parent-root-folder (psci/--project-root!))
109
+ (psci-module-file (psci/--project-psci-file parent-root-folder)))
110
+ (when psci-module-file
111
+ (->> psci-module-file
112
+ psci/--file-content
113
+ (s-split " \n " )
114
+ (--map (s-concat " ./" (cadr (s-split " :m " it))))
115
+ (-filter 'file-exists-p )
116
+ nreverse ))))
117
+
118
+ (defun psci/--compute-modules-folder (project-root-folder )
119
+ " Compute the psci modules folder from PROJECT-ROOT-FOLDER."
120
+ (concat project-root-folder psci/--modules-folder))
121
+
122
+ (defun psci/--run-psci-command! (command )
123
+ " Run psci COMMAND as string."
124
+ (-when-let (process (get-buffer-process (psci/--process-name psci/buffer-name)))
125
+ (comint-simple-send process command)
126
+ (process-send-eof process)))
127
+
128
+ (defun psci/--load-file! (filename )
129
+ " Load the purescript FILENAME inside the current running session."
130
+ (psci/--run-psci-command! (format " :m %s " filename)))
131
+
132
+ (defun psci/--compute-module-name! ()
133
+ " Compute the current file's module name."
134
+ (save-excursion
135
+ (goto-char (point-min ))
136
+ (let ((regexp " ^module \\ \( [a-zA-Z0-9\\ \. ]+\\ \) " ))
137
+ (search-forward-regexp regexp)
138
+ (match-string 1 ))))
139
+
140
+ ; ; public functions
141
+
142
+ ;;;### autoload
80
143
(defun psci ()
81
144
" Run an inferior instance of `psci' inside Emacs."
82
145
(interactive )
87
150
(pop-to-buffer-same-window
88
151
(if (or buffer (not (derived-mode-p 'psci-mode ))
89
152
(comint-check-proc (current-buffer )))
90
- (get-buffer-create (or buffer (psci/process-name psci/buffer-name)))
153
+ (get-buffer-create (or buffer (psci/-- process-name psci/buffer-name)))
91
154
(current-buffer )))
92
155
; ; create the comint process if there is no buffer.
93
156
(unless buffer
96
159
psci-program psci/arguments)
97
160
(psci-mode))))
98
161
162
+ (defvar psci-mode-map
163
+ (let ((map (nconc (make-sparse-keymap ) comint-mode-map)))
164
+ (define-key map " \t " 'completion-at-point )
165
+ map)
166
+ " Basic mode map for `psci' ." )
167
+
99
168
;;;### autoload
100
169
(define-derived-mode psci-mode comint-mode " psci"
101
170
" Major mode for `run-psci' .
115
184
(set (make-local-variable 'comment-start ) " -- " )
116
185
(set (make-local-variable 'comment-use-syntax ) t ))
117
186
118
- (defun psci/--run-psci-command! (command )
119
- " Run psci COMMAND as string."
120
- (-when-let (process (get-buffer-process (psci/process-name psci/buffer-name)))
121
- (comint-simple-send process command)
122
- (process-send-eof process)))
123
-
124
- ; ; (defun psci/load-region! (region-start region-end)
125
- ; ; "Run purescript code between REGION-START and REGION-END."
126
- ; ; (interactive "r")
127
- ; ; (-when-let (process (get-buffer-process (psci/process-name psci/buffer-name)))
128
- ; ; (comint-send-region process region-start region-end)
129
- ; ; (process-send-eof process)))
130
-
131
- (defun psci/--load-file! (filename )
132
- " Load the purescript FILENAME inside the current running session."
133
- (psci/--run-psci-command! (format " :m %s " filename)))
134
-
135
187
;;;### autoload
136
188
(defun psci/load-current-file! ()
137
189
" Load the current file in the psci repl."
145
197
(lambda ()
146
198
(call-interactively 'psci/reset! )))))))
147
199
148
- (defun psci/--compute-module-name! ()
149
- " Compute the current file's module name."
150
- (save-excursion
151
- (goto-char (point-min ))
152
- (let ((regexp " ^module \\ \( [a-zA-Z0-9\\ \. ]+\\ \) " ))
153
- (search-forward-regexp regexp)
154
- (match-string 1 ))))
155
-
156
200
;;;### autoload
157
201
(defun psci/load-module! ()
158
202
" Load the module inside the repl session."
159
203
(interactive )
160
204
(-when-let (module-name (psci/--compute-module-name!))
161
205
(psci/--run-psci-command! (format " :i %s " module-name))))
162
206
163
- (defvar psci/project-module-file " .psci"
164
- " The default file referencing the purescript modules to load at psci startup." )
165
-
166
- (defun psci/--file-content (filename )
167
- " Load the FILENAME's content as a string.
168
- When FILENAME is nil or not a real file, returns nil."
169
- (when (and filename (file-exists-p filename))
170
- (with-temp-buffer
171
- (insert-file-contents filename)
172
- (buffer-substring-no-properties (point-min ) (point-max )))))
173
-
174
- (defun psci/--symbol (sym n )
175
- " Compute the repetition of a symbol SYM N times as a string."
176
- (--> n
177
- (-repeat it sym)
178
- (s-join " " it)))
179
-
180
- (defun psci/--project-psci-file (project-root-folder )
181
- " Compute the project's psci file from the PROJECT-ROOT-FOLDER.
182
- Returns nil if no .psci file is found."
183
- (let ((psci-module-file (expand-file-name psci/project-module-file project-root-folder)))
184
- (when (file-exists-p psci-module-file)
185
- psci-module-file)))
186
-
187
- (defun psci/--project-module-files! ()
188
- " Compulse the list of modules for the current project.
189
- Assumes the location of the modules is the project root folder."
190
- (let* ((parent-root-folder (psci/--project-root!))
191
- (psci-module-file (psci/--project-psci-file parent-root-folder)))
192
- (when psci-module-file
193
- (->> psci-module-file
194
- psci/--file-content
195
- (s-split " \n " )
196
- (--map (s-concat " ./" (cadr (s-split " :m " it))))
197
- (-filter 'file-exists-p )
198
- nreverse ))))
199
-
200
- (defvar psci/--modules-folder " .psci_modules"
201
- " The modules folder psci uses as cache." )
202
-
203
- (defun psci/--compute-modules-folder (project-root-folder )
204
- " Compute the psci modules folder from PROJECT-ROOT-FOLDER."
205
- (concat project-root-folder psci/--modules-folder))
206
-
207
207
;;;### autoload
208
208
(defun psci/load-project-modules! ()
209
209
" Load the modules needed for the repl session.
@@ -224,11 +224,11 @@ We chose to load the .psci file's content (the purescript doc proposes its use).
224
224
(interactive )
225
225
(psci/--run-psci-command! " :r" ))
226
226
227
- ( defun psci/--project-root! ()
228
- " Determine the project's root folder. "
229
- (-> > psci/project-module-file
230
- ( locate-dominating-file default-directory )
231
- expand-file-name ))
227
+ ;;;### autoload
228
+ ( defun psci/quit! ()
229
+ " Quit the psci session. "
230
+ ( interactive )
231
+ (psci/--run-psci-command! " :q " ))
232
232
233
233
(defvar inferior-psci-mode-map
234
234
(let ((map (make-sparse-keymap )))
@@ -245,7 +245,7 @@ We chose to load the .psci file's content (the purescript doc proposes its use).
245
245
:prefix " psci/" )
246
246
247
247
;;;### autoload
248
- (define-minor-mode inferior-psci-mode " Extend the bindings ."
248
+ (define-minor-mode inferior-psci-mode " psci minor mode to define default bindings ."
249
249
:lighter " ip"
250
250
:keymap inferior-psci-mode-map
251
251
:group 'psci )
0 commit comments