|
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.5 |
| 7 | +;; Version: 0.0.6 |
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
|
|
77 | 77 |
|
78 | 78 | ;; private functions
|
79 | 79 |
|
| 80 | +(defun psci/log (msg) |
| 81 | + "Log MSG for psci." |
| 82 | + (message (format "psci - %s" msg))) |
| 83 | + |
80 | 84 | (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))) |
85 | 90 |
|
86 | 91 | (defun psci/--process-name (buffer-name)
|
87 | 92 | "Compute the buffer's process name based on BUFFER-NAME."
|
@@ -133,31 +138,34 @@ Assumes the location of the modules is the project root folder."
|
133 | 138 | "Compute the current file's module name."
|
134 | 139 | (save-excursion
|
135 | 140 | (goto-char (point-min))
|
136 |
| - (let ((regexp "^module \\\([a-zA-Z0-9\\\.]+\\\) ")) |
| 141 | + (let ((regexp "^module\\s-+\\\([a-zA-Z0-9\\\.]+\\\)\\b")) |
137 | 142 | (search-forward-regexp regexp)
|
138 | 143 | (match-string 1))))
|
139 | 144 |
|
140 | 145 | ;; public functions
|
141 | 146 |
|
142 | 147 | ;;;###autoload
|
143 | 148 | (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." |
145 | 151 | (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."))) |
161 | 169 |
|
162 | 170 | (defvar psci-mode-map
|
163 | 171 | (let ((map (nconc (make-sparse-keymap) comint-mode-map)))
|
|
0 commit comments