Skip to content

Commit b37d02b

Browse files
committed
- [X] Reorganize private functions at the beginning of the buffer
1 parent 70c5552 commit b37d02b

File tree

2 files changed

+57
-51
lines changed

2 files changed

+57
-51
lines changed

psci.el

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
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

@@ -73,6 +75,8 @@
7375
(defvar psci/--modules-folder ".psci_modules"
7476
"The modules folder psci uses as cache.")
7577

78+
;; private functions
79+
7680
(defun psci/--project-root! ()
7781
"Determine the project's root folder."
7882
(->> psci/project-module-file
@@ -83,6 +87,58 @@
8387
"Compute the buffer's process name based on BUFFER-NAME."
8488
(format "*%s*" buffer-name))
8589

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+
86142
;;;###autoload
87143
(defun psci ()
88144
"Run an inferior instance of `psci' inside Emacs."
@@ -128,16 +184,6 @@
128184
(set (make-local-variable 'comment-start) "-- ")
129185
(set (make-local-variable 'comment-use-syntax) t))
130186

131-
(defun psci/--run-psci-command! (command)
132-
"Run psci COMMAND as string."
133-
(-when-let (process (get-buffer-process (psci/--process-name psci/buffer-name)))
134-
(comint-simple-send process command)
135-
(process-send-eof process)))
136-
137-
(defun psci/--load-file! (filename)
138-
"Load the purescript FILENAME inside the current running session."
139-
(psci/--run-psci-command! (format ":m %s" filename)))
140-
141187
;;;###autoload
142188
(defun psci/load-current-file! ()
143189
"Load the current file in the psci repl."
@@ -151,53 +197,13 @@
151197
(lambda ()
152198
(call-interactively 'psci/reset!)))))))
153199

154-
(defun psci/--compute-module-name! ()
155-
"Compute the current file's module name."
156-
(save-excursion
157-
(goto-char (point-min))
158-
(let ((regexp "^module \\\([a-zA-Z0-9\\\.]+\\\) "))
159-
(search-forward-regexp regexp)
160-
(match-string 1))))
161-
162200
;;;###autoload
163201
(defun psci/load-module! ()
164202
"Load the module inside the repl session."
165203
(interactive)
166204
(-when-let (module-name (psci/--compute-module-name!))
167205
(psci/--run-psci-command! (format ":i %s" module-name))))
168206

169-
(defun psci/--file-content (filename)
170-
"Load the FILENAME's content as a string.
171-
When FILENAME is nil or not a real file, returns nil."
172-
(when (and filename (file-exists-p filename))
173-
(with-temp-buffer
174-
(insert-file-contents filename)
175-
(buffer-substring-no-properties (point-min) (point-max)))))
176-
177-
(defun psci/--project-psci-file (project-root-folder)
178-
"Compute the project's psci file from the PROJECT-ROOT-FOLDER.
179-
Returns nil if no .psci file is found."
180-
(let ((psci-module-file (expand-file-name psci/project-module-file project-root-folder)))
181-
(when (file-exists-p psci-module-file)
182-
psci-module-file)))
183-
184-
(defun psci/--project-module-files! ()
185-
"Compulse the list of modules for the current project.
186-
Assumes the location of the modules is the project root folder."
187-
(let* ((parent-root-folder (psci/--project-root!))
188-
(psci-module-file (psci/--project-psci-file parent-root-folder)))
189-
(when psci-module-file
190-
(->> psci-module-file
191-
psci/--file-content
192-
(s-split "\n")
193-
(--map (s-concat "./" (cadr (s-split ":m " it))))
194-
(-filter 'file-exists-p)
195-
nreverse))))
196-
197-
(defun psci/--compute-modules-folder (project-root-folder)
198-
"Compute the psci modules folder from PROJECT-ROOT-FOLDER."
199-
(concat project-root-folder psci/--modules-folder))
200-
201207
;;;###autoload
202208
(defun psci/load-project-modules! ()
203209
"Load the modules needed for the repl session.

todo.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- [X] Reorganize var at the beginning of the buffer
1010
- [X] Add missing autoload property on psci function
1111
- [X] Remove dead code
12-
- [ ] Reorganize private functions at the beginning of the buffer
12+
- [X] Reorganize private functions at the beginning of the buffer
1313
- [ ] Rename functions according to fully compliant emacs conventions?
1414
- [ ] Add quit session command
1515
- [ ] Make psci's default completion work

0 commit comments

Comments
 (0)