Skip to content

Commit

Permalink
- [X] M-x psci errors if there is no .psci file. - CLOSE #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ardumont committed Jan 14, 2015
1 parent cd364ed commit a82bcec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
48 changes: 28 additions & 20 deletions psci.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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)))
Expand Down
11 changes: 7 additions & 4 deletions todo.org
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a82bcec

Please sign in to comment.