diff --git a/psci.el b/psci.el index 3417d6a..9346658 100644 --- a/psci.el +++ b/psci.el @@ -77,11 +77,16 @@ ;; private functions +(defun psci/log (msg) + "Log MSG for psci." + (message (format "psci - %s" msg))) + (defun psci/--project-root! () - "Determine the project's root folder." - (->> psci/project-module-file - (locate-dominating-file default-directory) - expand-file-name)) + "Determine the project's root folder. +Beware, can return nil if no .psci file is found." + (-when-let (project-root (->> psci/project-module-file + (locate-dominating-file default-directory))) + (expand-file-name project-root))) (defun psci/--process-name (buffer-name) "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." ;;;###autoload (defun psci () - "Run an inferior instance of `psci' inside Emacs." + "Run an inferior instance of `psci' inside Emacs. +Relies on .psci file for determining the project's root folder." (interactive) - (let* ((psci-program psci/file-path) - (buffer (comint-check-proc psci/buffer-name))) - ;; pop to the "*psci*" buffer if the process is dead, the - ;; buffer is missing or it's got the wrong mode. - (pop-to-buffer-same-window - (if (or buffer (not (derived-mode-p 'psci-mode)) - (comint-check-proc (current-buffer))) - (get-buffer-create (or buffer (psci/--process-name psci/buffer-name))) - (current-buffer))) - ;; create the comint process if there is no buffer. - (unless buffer - (setq default-directory (psci/--project-root!)) - (apply 'make-comint-in-buffer psci/buffer-name buffer - psci-program psci/arguments) - (psci-mode)))) + (-if-let (project-root-folder (psci/--project-root!)) + (let* ((psci-program psci/file-path) + (buffer (comint-check-proc psci/buffer-name))) + ;; pop to the "*psci*" buffer if the process is dead, the + ;; buffer is missing or it's got the wrong mode. + (pop-to-buffer-same-window + (if (or buffer (not (derived-mode-p 'psci-mode)) + (comint-check-proc (current-buffer))) + (get-buffer-create (or buffer (psci/--process-name psci/buffer-name))) + (current-buffer))) + ;; create the comint process if there is no buffer. + (unless buffer + (setq default-directory (psci/--project-root!)) + (apply 'make-comint-in-buffer psci/buffer-name buffer + psci-program psci/arguments) + (psci-mode))) + (psci/log "No .psci file so we cannot determine the root project folder. Please, add one."))) (defvar psci-mode-map (let ((map (nconc (make-sparse-keymap) comint-mode-map))) diff --git a/todo.org b/todo.org index 9725968..98535ea 100644 --- a/todo.org +++ b/todo.org @@ -1,14 +1,17 @@ #+title: backlog #+author: ardumont -* IN-PROGRESS 0.0.6 [42%] -- [X] Prepare backlog -- [X] Update version -- [X] Add TOC to the README.org (Cheers to org-toc!) +* 0.0.7 [%] - [ ] Add :b binding - [ ] Add `:s import` binding - [ ] Add `:s loaded` binding - [ ] Make psci's default completion work +* IN-PROGRESS 0.0.6 [80%] +- [X] Prepare backlog +- [X] Update version +- [X] Add TOC to the README.org (Cheers to org-toc!) +- [X] `M-x psci` errors if there is no .psci file. - CLOSE #3 +- [ ] Need better regex for `psci/--compute-module-name!` - #4 * DONE 0.0.5 [100%] CLOSED: [2014-10-30 Thu 18:17] - [X] Prepare backlog