diff --git a/README.org b/README.org index f5de9d9..9826c7b 100644 --- a/README.org +++ b/README.org @@ -134,6 +134,7 @@ Default bindings available from a purescript buffer: | C-c M-n | M-x psci/load-module! | Equivalent of `:i your.current.module.name` - Import for use in PSCI | | C-c C-r | M-x psci/load-project-modules! | Load or reload files defined in the project file .psci | | N/A | M-x psci/reset! | Equivalent of `:r` - Reset | +| N/A | M-x psci/quit! | Equivalent of `:q` - Quit | | C-c C-z | | Provided you use the previous setup, this will switch back and forth between repl and buffer | |-------------+--------------------------------+----------------------------------------------------------------------------------------------| diff --git a/psci.el b/psci.el index 61a18fe..d2cbe8b 100644 --- a/psci.el +++ b/psci.el @@ -4,7 +4,7 @@ ;; Author: Antoine R. Dumont ;; Maintainer: Antoine R. Dumont -;; Version: 0.0.4 +;; Version: 0.0.5 ;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1") (deferred "0.3.2")) ;; Keywords: purescript psci repl major mode ;; URL: https://github.com/ardumont/emacs-psci @@ -38,8 +38,8 @@ ;; to purescript-mode: ;; (add-hook 'purescript-mode-hook 'inferior-psci-mode) -;; To activate psci directly from a purescript-mode buffer, you -;; could use repl-toggle (available on melpa): +;; To come back and forth between a purescript-mode buffer and +;; repl, you could use repl-toggle (available on melpa): ;; (require 'repl-toggle) ;; (add-to-list 'rtog/mode-repl-alist '(purescript-mode . psci)) @@ -55,28 +55,91 @@ (require 'f) (require 'deferred) +;; constants or variables + (defvar psci/buffer-name "psci" "Buffer name of the psci buffer.") -(defun psci/process-name (buffer-name) - "Compute the buffer's process name based on BUFFER-NAME." - (format "*%s*" buffer-name)) - (defvar psci/file-path "psci" "Path to the program used by `psci' function.") (defvar psci/arguments '() "Commandline arguments to pass to `psci' function.") -(defvar psci-mode-map - (let ((map (nconc (make-sparse-keymap) comint-mode-map))) - (define-key map "\t" 'completion-at-point) - map) - "Basic mode map for `psci'.") - (defvar psci/prompt "> " "The psci prompt.") +(defvar psci/project-module-file ".psci" + "The default file referencing the purescript modules to load at psci startup.") + +(defvar psci/--modules-folder ".psci_modules" + "The modules folder psci uses as cache.") + +;; private functions + +(defun psci/--project-root! () + "Determine the project's root folder." + (->> psci/project-module-file + (locate-dominating-file default-directory) + expand-file-name)) + +(defun psci/--process-name (buffer-name) + "Compute the buffer's process name based on BUFFER-NAME." + (format "*%s*" buffer-name)) + +(defun psci/--file-content (filename) + "Load the FILENAME's content as a string. +When FILENAME is nil or not a real file, returns nil." + (when (and filename (file-exists-p filename)) + (with-temp-buffer + (insert-file-contents filename) + (buffer-substring-no-properties (point-min) (point-max))))) + +(defun psci/--project-psci-file (project-root-folder) + "Compute the project's psci file from the PROJECT-ROOT-FOLDER. +Returns nil if no .psci file is found." + (let ((psci-module-file (expand-file-name psci/project-module-file project-root-folder))) + (when (file-exists-p psci-module-file) + psci-module-file))) + +(defun psci/--project-module-files! () + "Compulse the list of modules for the current project. +Assumes the location of the modules is the project root folder." + (let* ((parent-root-folder (psci/--project-root!)) + (psci-module-file (psci/--project-psci-file parent-root-folder))) + (when psci-module-file + (->> psci-module-file + psci/--file-content + (s-split "\n") + (--map (s-concat "./" (cadr (s-split ":m " it)))) + (-filter 'file-exists-p) + nreverse)))) + +(defun psci/--compute-modules-folder (project-root-folder) + "Compute the psci modules folder from PROJECT-ROOT-FOLDER." + (concat project-root-folder psci/--modules-folder)) + +(defun psci/--run-psci-command! (command) + "Run psci COMMAND as string." + (-when-let (process (get-buffer-process (psci/--process-name psci/buffer-name))) + (comint-simple-send process command) + (process-send-eof process))) + +(defun psci/--load-file! (filename) + "Load the purescript FILENAME inside the current running session." + (psci/--run-psci-command! (format ":m %s" filename))) + +(defun psci/--compute-module-name! () + "Compute the current file's module name." + (save-excursion + (goto-char (point-min)) + (let ((regexp "^module \\\([a-zA-Z0-9\\\.]+\\\) ")) + (search-forward-regexp regexp) + (match-string 1)))) + +;; public functions + +;;;###autoload (defun psci () "Run an inferior instance of `psci' inside Emacs." (interactive) @@ -87,7 +150,7 @@ (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))) + (get-buffer-create (or buffer (psci/--process-name psci/buffer-name))) (current-buffer))) ;; create the comint process if there is no buffer. (unless buffer @@ -96,6 +159,12 @@ psci-program psci/arguments) (psci-mode)))) +(defvar psci-mode-map + (let ((map (nconc (make-sparse-keymap) comint-mode-map))) + (define-key map "\t" 'completion-at-point) + map) + "Basic mode map for `psci'.") + ;;;###autoload (define-derived-mode psci-mode comint-mode "psci" "Major mode for `run-psci'. @@ -115,23 +184,6 @@ (set (make-local-variable 'comment-start) "-- ") (set (make-local-variable 'comment-use-syntax) t)) -(defun psci/--run-psci-command! (command) - "Run psci COMMAND as string." - (-when-let (process (get-buffer-process (psci/process-name psci/buffer-name))) - (comint-simple-send process command) - (process-send-eof process))) - -;; (defun psci/load-region! (region-start region-end) -;; "Run purescript code between REGION-START and REGION-END." -;; (interactive "r") -;; (-when-let (process (get-buffer-process (psci/process-name psci/buffer-name))) -;; (comint-send-region process region-start region-end) -;; (process-send-eof process))) - -(defun psci/--load-file! (filename) - "Load the purescript FILENAME inside the current running session." - (psci/--run-psci-command! (format ":m %s" filename))) - ;;;###autoload (defun psci/load-current-file! () "Load the current file in the psci repl." @@ -145,14 +197,6 @@ (lambda () (call-interactively 'psci/reset!))))))) -(defun psci/--compute-module-name! () - "Compute the current file's module name." - (save-excursion - (goto-char (point-min)) - (let ((regexp "^module \\\([a-zA-Z0-9\\\.]+\\\) ")) - (search-forward-regexp regexp) - (match-string 1)))) - ;;;###autoload (defun psci/load-module! () "Load the module inside the repl session." @@ -160,50 +204,6 @@ (-when-let (module-name (psci/--compute-module-name!)) (psci/--run-psci-command! (format ":i %s" module-name)))) -(defvar psci/project-module-file ".psci" - "The default file referencing the purescript modules to load at psci startup.") - -(defun psci/--file-content (filename) - "Load the FILENAME's content as a string. -When FILENAME is nil or not a real file, returns nil." - (when (and filename (file-exists-p filename)) - (with-temp-buffer - (insert-file-contents filename) - (buffer-substring-no-properties (point-min) (point-max))))) - -(defun psci/--symbol (sym n) - "Compute the repetition of a symbol SYM N times as a string." - (--> n - (-repeat it sym) - (s-join "" it))) - -(defun psci/--project-psci-file (project-root-folder) - "Compute the project's psci file from the PROJECT-ROOT-FOLDER. -Returns nil if no .psci file is found." - (let ((psci-module-file (expand-file-name psci/project-module-file project-root-folder))) - (when (file-exists-p psci-module-file) - psci-module-file))) - -(defun psci/--project-module-files! () - "Compulse the list of modules for the current project. -Assumes the location of the modules is the project root folder." - (let* ((parent-root-folder (psci/--project-root!)) - (psci-module-file (psci/--project-psci-file parent-root-folder))) - (when psci-module-file - (->> psci-module-file - psci/--file-content - (s-split "\n") - (--map (s-concat "./" (cadr (s-split ":m " it)))) - (-filter 'file-exists-p) - nreverse)))) - -(defvar psci/--modules-folder ".psci_modules" - "The modules folder psci uses as cache.") - -(defun psci/--compute-modules-folder (project-root-folder) - "Compute the psci modules folder from PROJECT-ROOT-FOLDER." - (concat project-root-folder psci/--modules-folder)) - ;;;###autoload (defun psci/load-project-modules! () "Load the modules needed for the repl session. @@ -224,11 +224,11 @@ We chose to load the .psci file's content (the purescript doc proposes its use). (interactive) (psci/--run-psci-command! ":r")) -(defun psci/--project-root! () - "Determine the project's root folder." - (->> psci/project-module-file - (locate-dominating-file default-directory) - expand-file-name)) +;;;###autoload +(defun psci/quit! () + "Quit the psci session." + (interactive) + (psci/--run-psci-command! ":q")) (defvar inferior-psci-mode-map (let ((map (make-sparse-keymap))) @@ -245,7 +245,7 @@ We chose to load the .psci file's content (the purescript doc proposes its use). :prefix "psci/") ;;;###autoload -(define-minor-mode inferior-psci-mode "Extend the bindings ." +(define-minor-mode inferior-psci-mode "psci minor mode to define default bindings." :lighter " ip" :keymap inferior-psci-mode-map :group 'psci) diff --git a/todo.org b/todo.org index ecc17b7..628e6e9 100644 --- a/todo.org +++ b/todo.org @@ -1,32 +1,22 @@ #+title: backlog #+author: ardumont -* DONE 0.0.1 [100%] -CLOSED: [2014-10-29 Wed 16:37] +* TODO 0.0.6 [0%] +- [ ] Update version +- [ ] Make psci's default completion work +* DONE 0.0.5 [100%] +CLOSED: [2014-10-30 Thu 18:17] - [X] Prepare backlog -- [X] First implementation -- [X] Add some documentation -- [X] Ensure everything is ok [100%] - - [X] Fix prompt regexp - - [X] Ensure the psci-mode-map is loaded -- [X] Load file in the current session -- [X] Load module in the current session -- [X] Add purescript-mode-hook function to extend bindings to load file or module -- [X] Permit the loading of dependencies modules -- [X] Send the reset command -* DONE 0.0.2 [100%] -CLOSED: [2014-10-29 Wed 18:03] -- [X] Run the psci command from the folder containing the .psci file -- [X] Improve the modules (re)loading by removing existing files (.psci_modules/node_modules folder) -- [X] Improve the module (re)loading by removing existings files (inside .psci_modules folder) -- [X] Create melpa recipe https://github.com/ardumont/melpa/blob/add-new-recipe-psci/recipes/psci -* DONE 0.0.3 [100%] -CLOSED: [2014-10-29 Wed 18:54] +- [X] Improve mode description header - [X] Update version -- [X] Add to marmalade - https://marmalade-repo.org/packages/psci -- [X] Add to el-get - https://github.com/ardumont/el-get/blob/add-psci-recipe/recipes/psci.rcp -- [X] Update documentation regarding installation steps -- [X] Update documentation regarding usage +- [X] Reorganize code for a better readability + - [X] Reorganize var at the beginning of the buffer + - [X] Add missing autoload property on psci function + - [X] Remove dead code + - [X] Reorganize private functions at the beginning of the buffer + - [X] Improve psci minor mode's dosctring description +- [X] Add quit session command +- [X] Update documentation about quit command * DONE 0.0.4 [100%] CLOSED: [2014-10-29 Wed 20:08] - [X] Update version @@ -40,3 +30,29 @@ CLOSED: [2014-10-29 Wed 20:08] - [X] Update documentation about the minor-mode activation and setup - [X] Avoid version function and var. Use directly the package information. - [X] Update call to setq default-directory +* DONE 0.0.3 [100%] +CLOSED: [2014-10-29 Wed 18:54] +- [X] Update version +- [X] Add to marmalade - https://marmalade-repo.org/packages/psci +- [X] Add to el-get - https://github.com/ardumont/el-get/blob/add-psci-recipe/recipes/psci.rcp +- [X] Update documentation regarding installation steps +- [X] Update documentation regarding usage +* DONE 0.0.2 [100%] +CLOSED: [2014-10-29 Wed 18:03] +- [X] Run the psci command from the folder containing the .psci file +- [X] Improve the modules (re)loading by removing existing files (.psci_modules/node_modules folder) +- [X] Improve the module (re)loading by removing existings files (inside .psci_modules folder) +- [X] Create melpa recipe https://github.com/ardumont/melpa/blob/add-new-recipe-psci/recipes/psci +* DONE 0.0.1 [100%] +CLOSED: [2014-10-29 Wed 16:37] +- [X] Prepare backlog +- [X] First implementation +- [X] Add some documentation +- [X] Ensure everything is ok [100%] + - [X] Fix prompt regexp + - [X] Ensure the psci-mode-map is loaded +- [X] Load file in the current session +- [X] Load module in the current session +- [X] Add purescript-mode-hook function to extend bindings to load file or module +- [X] Permit the loading of dependencies modules +- [X] Send the reset command