Skip to content

Commit a82bcec

Browse files
committed
- [X] M-x psci errors if there is no .psci file. - CLOSE #3
1 parent cd364ed commit a82bcec

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

psci.el

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,16 @@
7777

7878
;; private functions
7979

80+
(defun psci/log (msg)
81+
"Log MSG for psci."
82+
(message (format "psci - %s" msg)))
83+
8084
(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+
"Determine the project's root folder.
86+
Beware, can return nil if no .psci file is found."
87+
(-when-let (project-root (->> psci/project-module-file
88+
(locate-dominating-file default-directory)))
89+
(expand-file-name project-root)))
8590

8691
(defun psci/--process-name (buffer-name)
8792
"Compute the buffer's process name based on BUFFER-NAME."
@@ -141,23 +146,26 @@ Assumes the location of the modules is the project root folder."
141146

142147
;;;###autoload
143148
(defun psci ()
144-
"Run an inferior instance of `psci' inside Emacs."
149+
"Run an inferior instance of `psci' inside Emacs.
150+
Relies on .psci file for determining the project's root folder."
145151
(interactive)
146-
(let* ((psci-program psci/file-path)
147-
(buffer (comint-check-proc psci/buffer-name)))
148-
;; pop to the "*psci*" buffer if the process is dead, the
149-
;; buffer is missing or it's got the wrong mode.
150-
(pop-to-buffer-same-window
151-
(if (or buffer (not (derived-mode-p 'psci-mode))
152-
(comint-check-proc (current-buffer)))
153-
(get-buffer-create (or buffer (psci/--process-name psci/buffer-name)))
154-
(current-buffer)))
155-
;; create the comint process if there is no buffer.
156-
(unless buffer
157-
(setq default-directory (psci/--project-root!))
158-
(apply 'make-comint-in-buffer psci/buffer-name buffer
159-
psci-program psci/arguments)
160-
(psci-mode))))
152+
(-if-let (project-root-folder (psci/--project-root!))
153+
(let* ((psci-program psci/file-path)
154+
(buffer (comint-check-proc psci/buffer-name)))
155+
;; pop to the "*psci*" buffer if the process is dead, the
156+
;; buffer is missing or it's got the wrong mode.
157+
(pop-to-buffer-same-window
158+
(if (or buffer (not (derived-mode-p 'psci-mode))
159+
(comint-check-proc (current-buffer)))
160+
(get-buffer-create (or buffer (psci/--process-name psci/buffer-name)))
161+
(current-buffer)))
162+
;; create the comint process if there is no buffer.
163+
(unless buffer
164+
(setq default-directory (psci/--project-root!))
165+
(apply 'make-comint-in-buffer psci/buffer-name buffer
166+
psci-program psci/arguments)
167+
(psci-mode)))
168+
(psci/log "No .psci file so we cannot determine the root project folder. Please, add one.")))
161169

162170
(defvar psci-mode-map
163171
(let ((map (nconc (make-sparse-keymap) comint-mode-map)))

todo.org

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#+title: backlog
22
#+author: ardumont
33

4-
* IN-PROGRESS 0.0.6 [42%]
5-
- [X] Prepare backlog
6-
- [X] Update version
7-
- [X] Add TOC to the README.org (Cheers to org-toc!)
4+
* 0.0.7 [%]
85
- [ ] Add :b binding
96
- [ ] Add `:s import` binding
107
- [ ] Add `:s loaded` binding
118
- [ ] Make psci's default completion work
9+
* IN-PROGRESS 0.0.6 [80%]
10+
- [X] Prepare backlog
11+
- [X] Update version
12+
- [X] Add TOC to the README.org (Cheers to org-toc!)
13+
- [X] `M-x psci` errors if there is no .psci file. - CLOSE #3
14+
- [ ] Need better regex for `psci/--compute-module-name!` - #4
1215
* DONE 0.0.5 [100%]
1316
CLOSED: [2014-10-30 Thu 18:17]
1417
- [X] Prepare backlog

0 commit comments

Comments
 (0)