Skip to content

Commit 577473f

Browse files
committed
Merge pull request #2 from ardumont/0.0.5
0.0.5
2 parents ca5f576 + 9427faf commit 577473f

File tree

3 files changed

+130
-113
lines changed

3 files changed

+130
-113
lines changed

README.org

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Default bindings available from a purescript buffer:
134134
| C-c M-n | M-x psci/load-module! | Equivalent of `:i your.current.module.name` - Import <module> for use in PSCI |
135135
| C-c C-r | M-x psci/load-project-modules! | Load or reload files defined in the project file .psci |
136136
| N/A | M-x psci/reset! | Equivalent of `:r` - Reset |
137+
| N/A | M-x psci/quit! | Equivalent of `:q` - Quit |
137138
| C-c C-z | | Provided you use the previous setup, this will switch back and forth between repl and buffer |
138139
|-------------+--------------------------------+----------------------------------------------------------------------------------------------|
139140

psci.el

+89-89
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; Author: Antoine R. Dumont <eniotna.t AT gmail.com>
66
;; Maintainer: Antoine R. Dumont <eniotna.t AT gmail.com>
7-
;; Version: 0.0.4
7+
;; Version: 0.0.5
88
;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1") (deferred "0.3.2"))
99
;; Keywords: purescript psci repl major mode
1010
;; URL: https://github.com/ardumont/emacs-psci
@@ -38,8 +38,8 @@
3838
;; to purescript-mode:
3939
;; (add-hook 'purescript-mode-hook 'inferior-psci-mode)
4040

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):
4343
;; (require 'repl-toggle)
4444
;; (add-to-list 'rtog/mode-repl-alist '(purescript-mode . psci))
4545

@@ -55,28 +55,91 @@
5555
(require 'f)
5656
(require 'deferred)
5757

58+
;; constants or variables
59+
5860
(defvar psci/buffer-name "psci"
5961
"Buffer name of the psci buffer.")
6062

61-
(defun psci/process-name (buffer-name)
62-
"Compute the buffer's process name based on BUFFER-NAME."
63-
(format "*%s*" buffer-name))
64-
6563
(defvar psci/file-path "psci"
6664
"Path to the program used by `psci' function.")
6765

6866
(defvar psci/arguments '()
6967
"Commandline arguments to pass to `psci' function.")
7068

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-
7769
(defvar psci/prompt "> "
7870
"The psci prompt.")
7971

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
80143
(defun psci ()
81144
"Run an inferior instance of `psci' inside Emacs."
82145
(interactive)
@@ -87,7 +150,7 @@
87150
(pop-to-buffer-same-window
88151
(if (or buffer (not (derived-mode-p 'psci-mode))
89152
(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)))
91154
(current-buffer)))
92155
;; create the comint process if there is no buffer.
93156
(unless buffer
@@ -96,6 +159,12 @@
96159
psci-program psci/arguments)
97160
(psci-mode))))
98161

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+
99168
;;;###autoload
100169
(define-derived-mode psci-mode comint-mode "psci"
101170
"Major mode for `run-psci'.
@@ -115,23 +184,6 @@
115184
(set (make-local-variable 'comment-start) "-- ")
116185
(set (make-local-variable 'comment-use-syntax) t))
117186

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-
135187
;;;###autoload
136188
(defun psci/load-current-file! ()
137189
"Load the current file in the psci repl."
@@ -145,65 +197,13 @@
145197
(lambda ()
146198
(call-interactively 'psci/reset!)))))))
147199

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-
156200
;;;###autoload
157201
(defun psci/load-module! ()
158202
"Load the module inside the repl session."
159203
(interactive)
160204
(-when-let (module-name (psci/--compute-module-name!))
161205
(psci/--run-psci-command! (format ":i %s" module-name))))
162206

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-
207207
;;;###autoload
208208
(defun psci/load-project-modules! ()
209209
"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).
224224
(interactive)
225225
(psci/--run-psci-command! ":r"))
226226

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"))
232232

233233
(defvar inferior-psci-mode-map
234234
(let ((map (make-sparse-keymap)))
@@ -245,7 +245,7 @@ We chose to load the .psci file's content (the purescript doc proposes its use).
245245
:prefix "psci/")
246246

247247
;;;###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."
249249
:lighter " ip"
250250
:keymap inferior-psci-mode-map
251251
:group 'psci)

todo.org

+40-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
#+title: backlog
22
#+author: ardumont
33

4-
* DONE 0.0.1 [100%]
5-
CLOSED: [2014-10-29 Wed 16:37]
4+
* TODO 0.0.6 [0%]
5+
- [ ] Update version
6+
- [ ] Make psci's default completion work
7+
* DONE 0.0.5 [100%]
8+
CLOSED: [2014-10-30 Thu 18:17]
69
- [X] Prepare backlog
7-
- [X] First implementation
8-
- [X] Add some documentation
9-
- [X] Ensure everything is ok [100%]
10-
- [X] Fix prompt regexp
11-
- [X] Ensure the psci-mode-map is loaded
12-
- [X] Load file in the current session
13-
- [X] Load module in the current session
14-
- [X] Add purescript-mode-hook function to extend bindings to load file or module
15-
- [X] Permit the loading of dependencies modules
16-
- [X] Send the reset command
17-
* DONE 0.0.2 [100%]
18-
CLOSED: [2014-10-29 Wed 18:03]
19-
- [X] Run the psci command from the folder containing the .psci file
20-
- [X] Improve the modules (re)loading by removing existing files (.psci_modules/node_modules folder)
21-
- [X] Improve the module (re)loading by removing existings files (inside .psci_modules folder)
22-
- [X] Create melpa recipe https://github.com/ardumont/melpa/blob/add-new-recipe-psci/recipes/psci
23-
* DONE 0.0.3 [100%]
24-
CLOSED: [2014-10-29 Wed 18:54]
10+
- [X] Improve mode description header
2511
- [X] Update version
26-
- [X] Add to marmalade - https://marmalade-repo.org/packages/psci
27-
- [X] Add to el-get - https://github.com/ardumont/el-get/blob/add-psci-recipe/recipes/psci.rcp
28-
- [X] Update documentation regarding installation steps
29-
- [X] Update documentation regarding usage
12+
- [X] Reorganize code for a better readability
13+
- [X] Reorganize var at the beginning of the buffer
14+
- [X] Add missing autoload property on psci function
15+
- [X] Remove dead code
16+
- [X] Reorganize private functions at the beginning of the buffer
17+
- [X] Improve psci minor mode's dosctring description
18+
- [X] Add quit session command
19+
- [X] Update documentation about quit command
3020
* DONE 0.0.4 [100%]
3121
CLOSED: [2014-10-29 Wed 20:08]
3222
- [X] Update version
@@ -40,3 +30,29 @@ CLOSED: [2014-10-29 Wed 20:08]
4030
- [X] Update documentation about the minor-mode activation and setup
4131
- [X] Avoid version function and var. Use directly the package information.
4232
- [X] Update call to setq default-directory
33+
* DONE 0.0.3 [100%]
34+
CLOSED: [2014-10-29 Wed 18:54]
35+
- [X] Update version
36+
- [X] Add to marmalade - https://marmalade-repo.org/packages/psci
37+
- [X] Add to el-get - https://github.com/ardumont/el-get/blob/add-psci-recipe/recipes/psci.rcp
38+
- [X] Update documentation regarding installation steps
39+
- [X] Update documentation regarding usage
40+
* DONE 0.0.2 [100%]
41+
CLOSED: [2014-10-29 Wed 18:03]
42+
- [X] Run the psci command from the folder containing the .psci file
43+
- [X] Improve the modules (re)loading by removing existing files (.psci_modules/node_modules folder)
44+
- [X] Improve the module (re)loading by removing existings files (inside .psci_modules folder)
45+
- [X] Create melpa recipe https://github.com/ardumont/melpa/blob/add-new-recipe-psci/recipes/psci
46+
* DONE 0.0.1 [100%]
47+
CLOSED: [2014-10-29 Wed 16:37]
48+
- [X] Prepare backlog
49+
- [X] First implementation
50+
- [X] Add some documentation
51+
- [X] Ensure everything is ok [100%]
52+
- [X] Fix prompt regexp
53+
- [X] Ensure the psci-mode-map is loaded
54+
- [X] Load file in the current session
55+
- [X] Load module in the current session
56+
- [X] Add purescript-mode-hook function to extend bindings to load file or module
57+
- [X] Permit the loading of dependencies modules
58+
- [X] Send the reset command

0 commit comments

Comments
 (0)