From 385d191529708b4c9fa4e6fae885d36e8d3b55e2 Mon Sep 17 00:00:00 2001 From: Erik Post Date: Sat, 28 Mar 2015 16:18:41 +0100 Subject: [PATCH 01/29] Recent psci versions use 'import' instead of ':i'. --- psci.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psci.el b/psci.el index 5940c9e..7f1c368 100644 --- a/psci.el +++ b/psci.el @@ -210,7 +210,7 @@ Relies on .psci file for determining the project's root folder." "Load the module inside the repl session." (interactive) (-when-let (module-name (psci/--compute-module-name!)) - (psci/--run-psci-command! (format ":i %s" module-name)))) + (psci/--run-psci-command! (format "import %s" module-name)))) ;;;###autoload (defun psci/load-project-modules! () From b61b76b24bd8a0844f1c2ba84307db0b5cb473b7 Mon Sep 17 00:00:00 2001 From: "U-TURNER-NT\\bsermons" Date: Tue, 1 Dec 2015 14:54:26 -0600 Subject: [PATCH 02/29] Updates for 0.9.x --- psci.el | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/psci.el b/psci.el index 7f1c368..5019fc2 100644 --- a/psci.el +++ b/psci.el @@ -63,7 +63,7 @@ (defvar psci/file-path "psci" "Path to the program used by `psci' function.") -(defvar psci/arguments '() +(defvar psci/arguments '("src/**/*.purs" "bower_components/purescript-*/src/**/*.purs") "Commandline arguments to pass to `psci' function.") (defvar psci/prompt "> " @@ -84,9 +84,9 @@ (defun psci/--project-root! () "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))) + (if (fboundp 'projectile-project-root) + (projectile-project-root) + (file-name-directory (buffer-file-name)))) (defun psci/--process-name (buffer-name) "Compute the buffer's process name based on BUFFER-NAME." @@ -114,11 +114,9 @@ Assumes the location of the modules is the project root folder." (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)))) + psci/--file-content + (s-split "\n") + nreverse)))) (defun psci/--compute-modules-folder (project-root-folder) "Compute the psci modules folder from PROJECT-ROOT-FOLDER." @@ -127,12 +125,7 @@ Assumes the location of the modules is the project root 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))) + (comint-simple-send process command))) (defun psci/--compute-module-name! () "Compute the current file's module name." @@ -154,7 +147,7 @@ Relies on .psci file for determining the project's root folder." (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 + (pop-to-buffer (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))) @@ -163,7 +156,7 @@ Relies on .psci file for determining the project's root folder." (unless buffer (setq default-directory (psci/--project-root!)) (apply 'make-comint-in-buffer psci/buffer-name buffer - psci-program psci/arguments) + psci-program nil psci/arguments) (psci-mode))) (psci/log "No .psci file so we cannot determine the root project folder. Please, add one."))) @@ -178,6 +171,7 @@ Relies on .psci file for determining the project's root folder." "Major mode for `run-psci'. \\" + (require 'purescript-font-lock) (set (make-local-variable 'comint-prompt-regexp) (concat "^" (regexp-quote psci/prompt))) (set (make-local-variable 'paragraph-separate) "\\'") ;; so commands like M-{ and M-} work. (set (make-local-variable 'paragraph-start) comint-prompt-regexp) @@ -196,14 +190,9 @@ Relies on .psci file for determining the project's root folder." (defun psci/load-current-file! () "Load the current file in the psci repl." (interactive) - (lexical-let ((archive-folder (psci/--compute-modules-folder (psci/--project-root!))) - (module-name (psci/--compute-module-name!))) - (when module-name - (deferred:$ - (deferred:process-shell (format "rm -rf %s/node_modules/%s" archive-folder module-name)) - (deferred:nextc it - (lambda () - (call-interactively 'psci/reset!))))))) + (save-buffer) + (call-interactively 'psci/reset!) + (call-interactively 'psci/load-module!)) ;;;###autoload (defun psci/load-module! () @@ -223,20 +212,20 @@ We chose to load the .psci file's content (the purescript doc proposes its use). (deferred:nextc it (lambda () (call-interactively 'psci/reset!))) ;; flush in-memory version (deferred:nextc it ;; at last reload all files (lambda () - (-when-let (modules (psci/--project-module-files!)) - (mapc #'psci/--load-file! modules))))))) + (-when-let (commands (psci/--project-module-files!)) + (mapc #'psci/--run-psci-command! commands))))))) ;;;###autoload (defun psci/reset! () "Reset the current status of the repl session." (interactive) - (psci/--run-psci-command! ":r")) + (psci/--run-psci-command! ":reset")) ;;;###autoload (defun psci/quit! () "Quit the psci session." (interactive) - (psci/--run-psci-command! ":q")) + (psci/--run-psci-command! ":quit")) (defvar inferior-psci-mode-map (let ((map (make-sparse-keymap))) From d68698e8226639928832ffbab0e36df157df3602 Mon Sep 17 00:00:00 2001 From: Brian Sermons Date: Sun, 17 Jul 2016 10:49:19 -0500 Subject: [PATCH 03/29] Make arguments configurable. --- psci.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/psci.el b/psci.el index 5019fc2..5306528 100644 --- a/psci.el +++ b/psci.el @@ -63,8 +63,10 @@ (defvar psci/file-path "psci" "Path to the program used by `psci' function.") -(defvar psci/arguments '("src/**/*.purs" "bower_components/purescript-*/src/**/*.purs") - "Commandline arguments to pass to `psci' function.") +(defcustom psci/arguments '("src/**/*.purs" "bower_components/purescript-*/src/**/*.purs") + "Commandline arguments to pass to `psci' function." + :group 'psci + :type '(repeat string)) (defvar psci/prompt "> " "The psci prompt.") From e5386104b4f85ea261a416e5d356b9c952bea43b Mon Sep 17 00:00:00 2001 From: Brian Sermons Date: Sun, 17 Jul 2016 11:24:57 -0500 Subject: [PATCH 04/29] Remove unnecessary code. --- psci.el | 45 +-------------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/psci.el b/psci.el index 5306528..20f113e 100644 --- a/psci.el +++ b/psci.el @@ -71,12 +71,6 @@ (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/log (msg) @@ -102,28 +96,6 @@ When FILENAME is nil or not a real file, returns nil." (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") - 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))) @@ -203,20 +175,6 @@ Relies on .psci file for determining the project's root folder." (-when-let (module-name (psci/--compute-module-name!)) (psci/--run-psci-command! (format "import %s" module-name)))) -;;;###autoload -(defun psci/load-project-modules! () - "Load the modules needed for the repl session. -We chose to load the .psci file's content (the purescript doc proposes its use)." - (interactive) - (lexical-let ((archive-folder (psci/--compute-modules-folder (psci/--project-root!)))) - (deferred:$ - (deferred:process-shell "rm -rf " (shell-quote-argument (format "%s/node_modules/*" archive-folder))) ;; clean compiled version - (deferred:nextc it (lambda () (call-interactively 'psci/reset!))) ;; flush in-memory version - (deferred:nextc it ;; at last reload all files - (lambda () - (-when-let (commands (psci/--project-module-files!)) - (mapc #'psci/--run-psci-command! commands))))))) - ;;;###autoload (defun psci/reset! () "Reset the current status of the repl session." @@ -232,14 +190,13 @@ We chose to load the .psci file's content (the purescript doc proposes its use). (defvar inferior-psci-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c C-l") 'psci/load-current-file!) - (define-key map (kbd "C-c C-r") 'psci/load-project-modules!) (define-key map (kbd "C-c M-n") 'psci/load-module!) map) "Basic mode map for `inferior-psci-mode'.") (defgroup psci nil "psci customisation group." :tag "psci" - :version "0.0.4" + :version "0.0.9" :group 'purescript :prefix "psci/") From 02a0ae39b689ec0f4338069e42eb05e9ecdcf3c1 Mon Sep 17 00:00:00 2001 From: Brian Sermons Date: Sun, 17 Jul 2016 12:03:23 -0500 Subject: [PATCH 05/29] Remove deferred requirement. --- psci.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/psci.el b/psci.el index 20f113e..6fbb63b 100644 --- a/psci.el +++ b/psci.el @@ -5,7 +5,7 @@ ;; Author: Antoine R. Dumont ;; Maintainer: Antoine R. Dumont ;; Version: 0.0.6 -;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1") (deferred "0.3.2")) +;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1")) ;; Keywords: purescript psci repl major mode ;; URL: https://github.com/ardumont/emacs-psci @@ -53,7 +53,6 @@ (require 'purescript-mode) (require 's) (require 'f) -(require 'deferred) ;; constants or variables From ec88b193b7878d8bc6a52344a3a0e08d5235d8a7 Mon Sep 17 00:00:00 2001 From: Brian Sermons Date: Sun, 17 Jul 2016 12:19:39 -0500 Subject: [PATCH 06/29] Revert group version --- psci.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psci.el b/psci.el index 6fbb63b..3f70b5b 100644 --- a/psci.el +++ b/psci.el @@ -195,7 +195,7 @@ Relies on .psci file for determining the project's root folder." (defgroup psci nil "psci customisation group." :tag "psci" - :version "0.0.9" + :version "0.0.4" :group 'purescript :prefix "psci/") From d6afc5acd8dbae77f147d8b55a294cbc054a223e Mon Sep 17 00:00:00 2001 From: Dave Aitken Date: Wed, 9 Aug 2017 23:55:26 +0100 Subject: [PATCH 07/29] Include psc-package sources list in arguments too if being used --- psci.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/psci.el b/psci.el index 3f70b5b..59f57a8 100644 --- a/psci.el +++ b/psci.el @@ -128,8 +128,12 @@ Relies on .psci file for determining the project's root folder." ;; 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 nil psci/arguments) + (let ((full-arg-list (if (file-exists-p "psc-package.json") + (let ((psc-package-sources (split-string (shell-command-to-string "psc-package sources")))) + (append psci/arguments psc-package-sources)) + psci/arguments))) + (apply 'make-comint-in-buffer psci/buffer-name buffer + psci-program nil full-arg-list)) (psci-mode))) (psci/log "No .psci file so we cannot determine the root project folder. Please, add one."))) From b6d6081286b4aa128e6d81a200ebb5113aa0c195 Mon Sep 17 00:00:00 2001 From: Dave Aitken Date: Fri, 18 Aug 2017 20:58:38 +0100 Subject: [PATCH 08/29] Extract out a psc-package sources function --- psci.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/psci.el b/psci.el index 59f57a8..95bf211 100644 --- a/psci.el +++ b/psci.el @@ -108,6 +108,10 @@ When FILENAME is nil or not a real file, returns nil." (search-forward-regexp regexp) (match-string 1)))) +(defun psci/--get-psc-package-sources! () + (when (file-exists-p "psc-package.json") + (split-string (shell-command-to-string "psc-package sources")))) + ;; public functions ;;;###autoload @@ -128,9 +132,8 @@ Relies on .psci file for determining the project's root folder." ;; create the comint process if there is no buffer. (unless buffer (setq default-directory (psci/--project-root!)) - (let ((full-arg-list (if (file-exists-p "psc-package.json") - (let ((psc-package-sources (split-string (shell-command-to-string "psc-package sources")))) - (append psci/arguments psc-package-sources)) + (let ((full-arg-list (-if-let (psc-package-sources (psci/--get-psc-package-sources!)) + (append psci/arguments psc-package-sources) psci/arguments))) (apply 'make-comint-in-buffer psci/buffer-name buffer psci-program nil full-arg-list)) From a55ffb5e4ce98472bc89e7fd44c7bdf966046a3d Mon Sep 17 00:00:00 2001 From: Dave Aitken Date: Sat, 19 Aug 2017 17:19:39 +0100 Subject: [PATCH 09/29] Point to `purs` binary and add `repl` arg rather than use `psci` --- psci.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/psci.el b/psci.el index 95bf211..5541a8c 100644 --- a/psci.el +++ b/psci.el @@ -59,8 +59,10 @@ (defvar psci/buffer-name "psci" "Buffer name of the psci buffer.") -(defvar psci/file-path "psci" - "Path to the program used by `psci' function.") +(defcustom psci/purs-path "purs" + "Path to the `purs' binary" + :group 'psci + :type 'string) (defcustom psci/arguments '("src/**/*.purs" "bower_components/purescript-*/src/**/*.purs") "Commandline arguments to pass to `psci' function." @@ -120,7 +122,7 @@ When FILENAME is nil or not a real file, returns nil." Relies on .psci file for determining the project's root folder." (interactive) (-if-let (project-root-folder (psci/--project-root!)) - (let* ((psci-program psci/file-path) + (let* ((psci-program psci/purs-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. @@ -136,7 +138,7 @@ Relies on .psci file for determining the project's root folder." (append psci/arguments psc-package-sources) psci/arguments))) (apply 'make-comint-in-buffer psci/buffer-name buffer - psci-program nil full-arg-list)) + psci-program nil "repl" full-arg-list)) (psci-mode))) (psci/log "No .psci file so we cannot determine the root project folder. Please, add one."))) From 63790ecb63d5109d2a230a14267dcb041678def8 Mon Sep 17 00:00:00 2001 From: kRITZCREEK Date: Wed, 11 Oct 2017 01:09:51 +0200 Subject: [PATCH 10/29] allows the user to specify a working dir for startup This is the same as how we do it in psc-ide-emacs --- psci.el | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/psci.el b/psci.el index 5541a8c..e38541b 100644 --- a/psci.el +++ b/psci.el @@ -117,30 +117,29 @@ When FILENAME is nil or not a real file, returns nil." ;; public functions ;;;###autoload -(defun psci () +(defun psci (project-root-folder) "Run an inferior instance of `psci' inside Emacs. Relies on .psci file for determining the project's root folder." - (interactive) - (-if-let (project-root-folder (psci/--project-root!)) - (let* ((psci-program psci/purs-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 - (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!)) - (let ((full-arg-list (-if-let (psc-package-sources (psci/--get-psc-package-sources!)) - (append psci/arguments psc-package-sources) - psci/arguments))) - (apply 'make-comint-in-buffer psci/buffer-name buffer - psci-program nil "repl" full-arg-list)) - (psci-mode))) - (psci/log "No .psci file so we cannot determine the root project folder. Please, add one."))) + (interactive (list (read-directory-name "Project root? " + (psci/--project-root!)))) + (let* ((psci-program psci/purs-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 + (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 project-root-folder) + (let ((full-arg-list (-if-let (psc-package-sources (psci/--get-psc-package-sources!)) + (append psci/arguments psc-package-sources) + psci/arguments))) + (apply 'make-comint-in-buffer psci/buffer-name buffer + psci-program nil "repl" full-arg-list)) + (psci-mode)))) (defvar psci-mode-map (let ((map (nconc (make-sparse-keymap) comint-mode-map))) From c3de520da4816a516048932de10e87c8b4c98a08 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 18 Apr 2018 18:55:37 +0700 Subject: [PATCH 11/29] Fix root detection when projectile fails projectile-project-root raises, so we need to check if projcetile can recognize a project with projectile-project-p --- psci.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psci.el b/psci.el index e38541b..ddc783f 100644 --- a/psci.el +++ b/psci.el @@ -81,7 +81,7 @@ (defun psci/--project-root! () "Determine the project's root folder. Beware, can return nil if no .psci file is found." - (if (fboundp 'projectile-project-root) + (if (and (fboundp 'projectile-project-root) (projectile-project-p)) (projectile-project-root) (file-name-directory (buffer-file-name)))) From ca192cdcbfcb535faa691e971e91bd2bade70406 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 12:58:59 +1300 Subject: [PATCH 12/29] Fix URL --- README.org | 2 +- psci.el | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index dd71a7e..9ec5bb5 100644 --- a/README.org +++ b/README.org @@ -178,7 +178,7 @@ Also, I prefer code that is understandable (ymmv) and doc-stringified. Issues, there will be. -Open issues [[https://github.com/ardumont/emacs-psci/issues][on the tracker]], I'll do my best to answer. +Open issues [[https://github.com/purescript-emacs/emacs-psci/issues][on the tracker]], I'll do my best to answer. Just, be sure to be clear, complete and concise about what your trouble is. diff --git a/psci.el b/psci.el index ddc783f..0548309 100644 --- a/psci.el +++ b/psci.el @@ -7,7 +7,7 @@ ;; Version: 0.0.6 ;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1")) ;; Keywords: purescript psci repl major mode -;; URL: https://github.com/ardumont/emacs-psci +;; URL: https://github.com/purescript-emacs/emacs-psci ;; This file is NOT part of GNU Emacs. @@ -44,7 +44,7 @@ ;; (add-to-list 'rtog/mode-repl-alist '(purescript-mode . psci)) ;; More informations: https://ardumont/emacs-psci -;; Issue tracker: https://github.com/ardumont/emacs-psci/issues +;; Issue tracker: https://github.com/purescript-emacs/emacs-psci/issues ;;; Code: From 43141a801da35e2f0acf5c1b15e0ac4e92f56650 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:00:54 +1300 Subject: [PATCH 13/29] Fix keywords --- psci.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psci.el b/psci.el index 0548309..9fde852 100644 --- a/psci.el +++ b/psci.el @@ -6,7 +6,7 @@ ;; Maintainer: Antoine R. Dumont ;; Version: 0.0.6 ;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1")) -;; Keywords: purescript psci repl major mode +;; Keywords: languages purescript psci repl ;; URL: https://github.com/purescript-emacs/emacs-psci ;; This file is NOT part of GNU Emacs. From 2b210b40cd3232cda377db8ed422981e6801165c Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:01:31 +1300 Subject: [PATCH 14/29] Remove risky call to (buffer-file-name) when default-directory is safer The latter is always set, but the first returns nil in non-file-backed buffers, which would lead to an error from `file-name-directory`. --- psci.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psci.el b/psci.el index 9fde852..6952f0c 100644 --- a/psci.el +++ b/psci.el @@ -83,7 +83,7 @@ Beware, can return nil if no .psci file is found." (if (and (fboundp 'projectile-project-root) (projectile-project-p)) (projectile-project-root) - (file-name-directory (buffer-file-name)))) + default-directory)) (defun psci/--process-name (buffer-name) "Compute the buffer's process name based on BUFFER-NAME." From a57ee43c2ac2b53d5f3bd9855eaf98e827587645 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:02:42 +1300 Subject: [PATCH 15/29] Add support for Spago, and define custom vars for helper program paths --- psci.el | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/psci.el b/psci.el index 6952f0c..f84df38 100644 --- a/psci.el +++ b/psci.el @@ -64,6 +64,16 @@ :group 'psci :type 'string) +(defcustom psci/psc-package-path "psc-package" + "Path to the `psc-package' binary." + :group 'psci + :type 'string) + +(defcustom psci/spago-path "spago" + "Path to the `spago' binary." + :group 'psci + :type 'string) + (defcustom psci/arguments '("src/**/*.purs" "bower_components/purescript-*/src/**/*.purs") "Commandline arguments to pass to `psci' function." :group 'psci @@ -111,8 +121,19 @@ When FILENAME is nil or not a real file, returns nil." (match-string 1)))) (defun psci/--get-psc-package-sources! () - (when (file-exists-p "psc-package.json") - (split-string (shell-command-to-string "psc-package sources")))) + (cond + ((file-exists-p "psc-package.json") + (process-lines (psci/--executable-find-relative psci/psc-package-path) "sources")) + ((file-exists-p "spago.dhall") + (process-lines (psci/--executable-find-relative psci/spago-path) "sources")))) + +(defun psci/--executable-find-relative (path) + "If PATH is a relative path to an executable, return its full path. +Otherwise, just return PATH." + (let ((relative (expand-file-name path))) + (if (file-executable-p relative) + relative + path))) ;; public functions @@ -122,7 +143,9 @@ When FILENAME is nil or not a real file, returns nil." Relies on .psci file for determining the project's root folder." (interactive (list (read-directory-name "Project root? " (psci/--project-root!)))) - (let* ((psci-program psci/purs-path) + (let* ((default-directory project-root-folder) + (psci-program psci/purs-path) + (extra-sources (psci/--get-psc-package-sources!)) (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. @@ -133,10 +156,7 @@ Relies on .psci file for determining the project's root folder." (current-buffer))) ;; create the comint process if there is no buffer. (unless buffer - (setq default-directory project-root-folder) - (let ((full-arg-list (-if-let (psc-package-sources (psci/--get-psc-package-sources!)) - (append psci/arguments psc-package-sources) - psci/arguments))) + (let ((full-arg-list (append psci/arguments extra-sources))) (apply 'make-comint-in-buffer psci/buffer-name buffer psci-program nil "repl" full-arg-list)) (psci-mode)))) From eab9076e9e6197ba7882283bc09565be5fc35a8a Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:10:32 +1300 Subject: [PATCH 16/29] Remove unused "f" dependency --- psci.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/psci.el b/psci.el index f84df38..dd39607 100644 --- a/psci.el +++ b/psci.el @@ -5,7 +5,7 @@ ;; Author: Antoine R. Dumont ;; Maintainer: Antoine R. Dumont ;; Version: 0.0.6 -;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0") (f "0.17.1")) +;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0")) ;; Keywords: languages purescript psci repl ;; URL: https://github.com/purescript-emacs/emacs-psci @@ -52,7 +52,6 @@ (require 'dash) (require 'purescript-mode) (require 's) -(require 'f) ;; constants or variables From ac011fa3f0e33ba046747fe79363d9a2496604c1 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:12:58 +1300 Subject: [PATCH 17/29] Require Emacs 24.4, for process-lines --- psci.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psci.el b/psci.el index dd39607..4ec017a 100644 --- a/psci.el +++ b/psci.el @@ -5,7 +5,7 @@ ;; Author: Antoine R. Dumont ;; Maintainer: Antoine R. Dumont ;; Version: 0.0.6 -;; Package-Requires: ((purescript-mode "13.10") (dash "2.9.0") (s "1.9.0")) +;; Package-Requires: ((emacs "24.4") (purescript-mode "13.10") (dash "2.9.0") (s "1.9.0")) ;; Keywords: languages purescript psci repl ;; URL: https://github.com/purescript-emacs/emacs-psci From 60c962e47afdeaaf4e04483338d956d06c4cc310 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:13:50 +1300 Subject: [PATCH 18/29] Prefer setq-local where possible --- psci.el | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/psci.el b/psci.el index 4ec017a..fab0e39 100644 --- a/psci.el +++ b/psci.el @@ -172,19 +172,19 @@ Relies on .psci file for determining the project's root folder." \\" (require 'purescript-font-lock) - (set (make-local-variable 'comint-prompt-regexp) (concat "^" (regexp-quote psci/prompt))) - (set (make-local-variable 'paragraph-separate) "\\'") ;; so commands like M-{ and M-} work. - (set (make-local-variable 'paragraph-start) comint-prompt-regexp) - (set (make-local-variable 'comint-input-sender-no-newline) nil) - (set (make-local-variable 'comint-input-sender) 'comint-simple-send) - (set (make-local-variable 'comint-get-old-input) 'comint-get-old-input-default) - (set (make-local-variable 'comint-process-echoes) nil) - (set (make-local-variable 'comint-prompt-read-only) t) ;; read-only prompt - (set (make-local-variable 'comint-eol-on-send) t) - (set (make-local-variable 'comint-input-filter-functions) nil) - (set (make-local-variable 'font-lock-defaults) '(purescript-font-lock-keywords t)) - (set (make-local-variable 'comment-start) "-- ") - (set (make-local-variable 'comment-use-syntax) t)) + (setq-local comint-prompt-regexp (concat "^" (regexp-quote psci/prompt))) + (setq-local paragraph-separate "\\'") ;; so commands like M-{ and M-} work. + (setq-local paragraph-start comint-prompt-regexp) + (setq-local comint-input-sender-no-newline nil) + (setq-local comint-input-sender 'comint-simple-send) + (setq-local comint-get-old-input 'comint-get-old-input-default) + (setq-local comint-process-echoes nil) + (setq-local comint-prompt-read-only t) ;; read-only prompt + (setq-local comint-eol-on-send t) + (setq-local comint-input-filter-functions nil) + (setq-local font-lock-defaults '(purescript-font-lock-keywords t)) + (setq-local comment-start "-- ") + (setq-local comment-use-syntax t)) ;;;###autoload (defun psci/load-current-file! () From 7f4770a592803d4726c3fd663abecb7d5a42f2d5 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:15:07 +1300 Subject: [PATCH 19/29] Remove unused log function --- psci.el | 4 ---- 1 file changed, 4 deletions(-) diff --git a/psci.el b/psci.el index fab0e39..3c6e693 100644 --- a/psci.el +++ b/psci.el @@ -83,10 +83,6 @@ ;; 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. Beware, can return nil if no .psci file is found." From 869e7314bbfd726f5a87380abf982796684aaa70 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:16:01 +1300 Subject: [PATCH 20/29] Fix checkdoc warnings --- psci.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/psci.el b/psci.el index 3c6e693..a26fff8 100644 --- a/psci.el +++ b/psci.el @@ -59,22 +59,22 @@ "Buffer name of the psci buffer.") (defcustom psci/purs-path "purs" - "Path to the `purs' binary" + "Path to the \"purs\" binary." :group 'psci :type 'string) (defcustom psci/psc-package-path "psc-package" - "Path to the `psc-package' binary." + "Path to the \"psc-package\" binary." :group 'psci :type 'string) (defcustom psci/spago-path "spago" - "Path to the `spago' binary." + "Path to the \"spago\" binary." :group 'psci :type 'string) (defcustom psci/arguments '("src/**/*.purs" "bower_components/purescript-*/src/**/*.purs") - "Commandline arguments to pass to `psci' function." + "Command-line arguments to pass to `psci' function." :group 'psci :type '(repeat string)) @@ -95,7 +95,7 @@ Beware, can return nil if no .psci file is found." (format "*%s*" buffer-name)) (defun psci/--file-content (filename) - "Load the FILENAME's content as a string. + "Load 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 @@ -116,6 +116,7 @@ When FILENAME is nil or not a real file, returns nil." (match-string 1)))) (defun psci/--get-psc-package-sources! () + "Find extra source path globs using purescript package tools,if they appear to be used." (cond ((file-exists-p "psc-package.json") (process-lines (psci/--executable-find-relative psci/psc-package-path) "sources")) @@ -134,8 +135,10 @@ Otherwise, just return PATH." ;;;###autoload (defun psci (project-root-folder) - "Run an inferior instance of `psci' inside Emacs. -Relies on .psci file for determining the project's root folder." + "Run an inferior instance of \"psci\" inside Emacs, in PROJECT-ROOT-FOLDER. +If not supplied, the root folder will be guessed using +`projectile-project-root' (if available), otherwise it will +default to the current buffer's directory." (interactive (list (read-directory-name "Project root? " (psci/--project-root!)))) (let* ((default-directory project-root-folder) From 35f156d24f42399c3f8d2e991880caf0997bf230 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:17:08 +1300 Subject: [PATCH 21/29] Rename private functions to use a well-formed symbol prefix --- psci.el | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/psci.el b/psci.el index a26fff8..63f9d99 100644 --- a/psci.el +++ b/psci.el @@ -83,18 +83,18 @@ ;; private functions -(defun psci/--project-root! () +(defun psci--project-root! () "Determine the project's root folder. Beware, can return nil if no .psci file is found." (if (and (fboundp 'projectile-project-root) (projectile-project-p)) (projectile-project-root) default-directory)) -(defun psci/--process-name (buffer-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) +(defun psci--file-content (filename) "Load FILENAME's content as a string. When FILENAME is nil or not a real file, returns nil." (when (and filename (file-exists-p filename)) @@ -102,12 +102,12 @@ When FILENAME is nil or not a real file, returns nil." (insert-file-contents filename) (buffer-substring-no-properties (point-min) (point-max))))) -(defun psci/--run-psci-command! (command) +(defun psci--run-psci-command! (command) "Run psci COMMAND as string." - (-when-let (process (get-buffer-process (psci/--process-name psci/buffer-name))) + (-when-let (process (get-buffer-process (psci--process-name psci/buffer-name))) (comint-simple-send process command))) -(defun psci/--compute-module-name! () +(defun psci--compute-module-name! () "Compute the current file's module name." (save-excursion (goto-char (point-min)) @@ -115,15 +115,15 @@ When FILENAME is nil or not a real file, returns nil." (search-forward-regexp regexp) (match-string 1)))) -(defun psci/--get-psc-package-sources! () +(defun psci--get-psc-package-sources! () "Find extra source path globs using purescript package tools,if they appear to be used." (cond ((file-exists-p "psc-package.json") - (process-lines (psci/--executable-find-relative psci/psc-package-path) "sources")) + (process-lines (psci--executable-find-relative psci/psc-package-path) "sources")) ((file-exists-p "spago.dhall") - (process-lines (psci/--executable-find-relative psci/spago-path) "sources")))) + (process-lines (psci--executable-find-relative psci/spago-path) "sources")))) -(defun psci/--executable-find-relative (path) +(defun psci--executable-find-relative (path) "If PATH is a relative path to an executable, return its full path. Otherwise, just return PATH." (let ((relative (expand-file-name path))) @@ -140,17 +140,17 @@ If not supplied, the root folder will be guessed using `projectile-project-root' (if available), otherwise it will default to the current buffer's directory." (interactive (list (read-directory-name "Project root? " - (psci/--project-root!)))) + (psci--project-root!)))) (let* ((default-directory project-root-folder) (psci-program psci/purs-path) - (extra-sources (psci/--get-psc-package-sources!)) + (extra-sources (psci--get-psc-package-sources!)) (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 (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 @@ -197,20 +197,20 @@ default to the current buffer's directory." (defun psci/load-module! () "Load the module inside the repl session." (interactive) - (-when-let (module-name (psci/--compute-module-name!)) - (psci/--run-psci-command! (format "import %s" module-name)))) + (-when-let (module-name (psci--compute-module-name!)) + (psci--run-psci-command! (format "import %s" module-name)))) ;;;###autoload (defun psci/reset! () "Reset the current status of the repl session." (interactive) - (psci/--run-psci-command! ":reset")) + (psci--run-psci-command! ":reset")) ;;;###autoload (defun psci/quit! () "Quit the psci session." (interactive) - (psci/--run-psci-command! ":quit")) + (psci--run-psci-command! ":quit")) (defvar inferior-psci-mode-map (let ((map (make-sparse-keymap))) From 666ebe9f16ec935dfda1577d60b41519f68508a0 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:21:16 +1300 Subject: [PATCH 22/29] Remove unused dependency on "s" --- psci.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/psci.el b/psci.el index 63f9d99..7f19643 100644 --- a/psci.el +++ b/psci.el @@ -5,7 +5,7 @@ ;; Author: Antoine R. Dumont ;; Maintainer: Antoine R. Dumont ;; Version: 0.0.6 -;; Package-Requires: ((emacs "24.4") (purescript-mode "13.10") (dash "2.9.0") (s "1.9.0")) +;; Package-Requires: ((emacs "24.4") (purescript-mode "13.10") (dash "2.9.0")) ;; Keywords: languages purescript psci repl ;; URL: https://github.com/purescript-emacs/emacs-psci @@ -51,7 +51,6 @@ (require 'comint) (require 'dash) (require 'purescript-mode) -(require 's) ;; constants or variables From 7cc6a35b390ddea6776e313287a6503c54b53b2b Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:22:17 +1300 Subject: [PATCH 23/29] Require purescript-font-lock at the top level, not in a function --- psci.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/psci.el b/psci.el index 7f19643..6072bbb 100644 --- a/psci.el +++ b/psci.el @@ -50,7 +50,7 @@ (require 'comint) (require 'dash) -(require 'purescript-mode) +(require 'purescript-font-lock) ;; constants or variables @@ -169,7 +169,6 @@ default to the current buffer's directory." "Major mode for `run-psci'. \\" - (require 'purescript-font-lock) (setq-local comint-prompt-regexp (concat "^" (regexp-quote psci/prompt))) (setq-local paragraph-separate "\\'") ;; so commands like M-{ and M-} work. (setq-local paragraph-start comint-prompt-regexp) From 3c10918a3a1d1dc613c222801deb465d4fbb2143 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Fri, 8 Mar 2019 13:24:58 +1300 Subject: [PATCH 24/29] Use the conventional ":" instead of "?" in prompt --- psci.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psci.el b/psci.el index 6072bbb..0d7dc2b 100644 --- a/psci.el +++ b/psci.el @@ -138,7 +138,7 @@ Otherwise, just return PATH." If not supplied, the root folder will be guessed using `projectile-project-root' (if available), otherwise it will default to the current buffer's directory." - (interactive (list (read-directory-name "Project root? " + (interactive (list (read-directory-name "Project root: " (psci--project-root!)))) (let* ((default-directory project-root-folder) (psci-program psci/purs-path) From 23b745b20358d86d48dc96c53a2052a96ce0e6f4 Mon Sep 17 00:00:00 2001 From: vlatkoB Date: Thu, 24 Oct 2019 20:08:33 +0200 Subject: [PATCH 25/29] Fix for #8, #25 and #26 --- psci.el | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/psci.el b/psci.el index 0d7dc2b..8a929ae 100644 --- a/psci.el +++ b/psci.el @@ -164,6 +164,37 @@ default to the current buffer's directory." map) "Basic mode map for `psci'.") +(defun psci-completion-preoutput-filter (string) + (setq psci-completion-captured-output (concat psci-completion-captured-output string)) + "") + +(defun psci-tidy-completion-output (response) + (let* ((response-lines (split-string response "\n" t nil)) + (response-lines-without-prompt (nbutlast response-lines))) + response-lines-without-prompt)) + + +(defun psci-tab-completion () + (let* ((line (thing-at-point 'line t)) + (command (format ":complete %s" line))) + (-when-let (process (get-buffer-process (psci--process-name psci/buffer-name))) + (add-hook 'comint-preoutput-filter-functions 'psci-completion-preoutput-filter nil t) + (comint-simple-send process command) + (accept-process-output process) + (remove-hook 'comint-preoutput-filter-functions 'psci-completion-preoutput-filter t) + (let ((response psci-completion-captured-output)) + (setq psci-completion-captured-output "") + (when (not (string-prefix-p "Unrecognized directive." response)) + (save-excursion + (let* ((end (point)) + (start (+ (re-search-backward comint-prompt-regexp) + (length psci/prompt))) + (results (psci-tidy-completion-output response))) + (list start end results)))))))) + +(defvar psci-dynamic-complete-functions + '(psci-tab-completion)) + ;;;###autoload (define-derived-mode psci-mode comint-mode "psci" "Major mode for `run-psci'. @@ -181,7 +212,10 @@ default to the current buffer's directory." (setq-local comint-input-filter-functions nil) (setq-local font-lock-defaults '(purescript-font-lock-keywords t)) (setq-local comment-start "-- ") - (setq-local comment-use-syntax t)) + (setq-local comment-use-syntax t) + (setq-local comment-use-syntax t) + (setq-local comint-dynamic-complete-functions psci-dynamic-complete-functions) + (setq-local psci-completion-captured-output "")) ;;;###autoload (defun psci/load-current-file! () @@ -202,7 +236,7 @@ default to the current buffer's directory." (defun psci/reset! () "Reset the current status of the repl session." (interactive) - (psci--run-psci-command! ":reset")) + (psci--run-psci-command! ":clear")) ;;;###autoload (defun psci/quit! () From 309ebeb0cbfe32a1c54c520457cf4c89a84ae5c2 Mon Sep 17 00:00:00 2001 From: Gavin Jaeger-Freeborn Date: Thu, 2 Feb 2023 12:16:15 -0800 Subject: [PATCH 26/29] Add project.el support as an alternative to projectile --- README.org | 2 +- psci.el | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index 9ec5bb5..d82135b 100644 --- a/README.org +++ b/README.org @@ -121,7 +121,7 @@ M-x el-get-install RET psci RET M-x psci #+end_src -This will open a psci repl within emacs from your current project root folder (using [[https://github.com/bbatsov/projectile][projectile]] to determine that). +This will open a psci repl within emacs from your current project root folder (using [[https://github.com/bbatsov/projectile][projectile]] or project.el to determine that). ** Setup diff --git a/psci.el b/psci.el index 8a929ae..d99a6ef 100644 --- a/psci.el +++ b/psci.el @@ -85,9 +85,13 @@ (defun psci--project-root! () "Determine the project's root folder. Beware, can return nil if no .psci file is found." - (if (and (fboundp 'projectile-project-root) (projectile-project-p)) - (projectile-project-root) - default-directory)) + (cond + ((and (fboundp 'projectile-project-root) (projectile-project-p)) + (projectile-project-root)) + ((fboundp 'project-root) + (project-root (project-current t))) + (t + default-directory))) (defun psci--process-name (buffer-name) "Compute the buffer's process name based on BUFFER-NAME." @@ -136,8 +140,9 @@ Otherwise, just return PATH." (defun psci (project-root-folder) "Run an inferior instance of \"psci\" inside Emacs, in PROJECT-ROOT-FOLDER. If not supplied, the root folder will be guessed using -`projectile-project-root' (if available), otherwise it will -default to the current buffer's directory." +`projectile-project-root', or `project-root' from project.el (if +available), otherwise it will default to the current buffer's +directory." (interactive (list (read-directory-name "Project root: " (psci--project-root!)))) (let* ((default-directory project-root-folder) From 8a7481b81551c3ab095917292c704679f474869a Mon Sep 17 00:00:00 2001 From: Arte Ebrahimi Date: Sun, 26 Nov 2023 23:09:34 -0800 Subject: [PATCH 27/29] look for spago.yaml and add --quiet flag (#32) --- psci.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/psci.el b/psci.el index d99a6ef..12045e5 100644 --- a/psci.el +++ b/psci.el @@ -123,8 +123,8 @@ When FILENAME is nil or not a real file, returns nil." (cond ((file-exists-p "psc-package.json") (process-lines (psci--executable-find-relative psci/psc-package-path) "sources")) - ((file-exists-p "spago.dhall") - (process-lines (psci--executable-find-relative psci/spago-path) "sources")))) + ((or (file-exists-p "spago.dhall") (file-exists-p "spago.yaml")) + (process-lines (psci--executable-find-relative psci/spago-path) "sources" "--quiet")))) (defun psci--executable-find-relative (path) "If PATH is a relative path to an executable, return its full path. From 2cc15af3703329a85289c73814d3ff34c9034a8f Mon Sep 17 00:00:00 2001 From: James Leslie Date: Sun, 17 Dec 2023 11:05:20 +0000 Subject: [PATCH 28/29] Use inheritenv to find non-global spago (#33) Currently, spago could only be detected if it was installed globally. This commit utilised inheritenv to allow spago to be found in the user's environment also. This is useful for when someone is developing with spago in an ephermeral shell, as provided by nix. Add inheritenv to package requires list Fix linebreak in package requires Bump emacs dependency to version 25.1 --- psci.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/psci.el b/psci.el index 12045e5..ce1c2c8 100644 --- a/psci.el +++ b/psci.el @@ -5,7 +5,7 @@ ;; Author: Antoine R. Dumont ;; Maintainer: Antoine R. Dumont ;; Version: 0.0.6 -;; Package-Requires: ((emacs "24.4") (purescript-mode "13.10") (dash "2.9.0")) +;; Package-Requires: ((emacs "25.1") (purescript-mode "13.10") (dash "2.9.0") (inheritenv "0.2")) ;; Keywords: languages purescript psci repl ;; URL: https://github.com/purescript-emacs/emacs-psci @@ -51,6 +51,7 @@ (require 'comint) (require 'dash) (require 'purescript-font-lock) +(require 'inheritenv) ;; constants or variables @@ -122,9 +123,9 @@ When FILENAME is nil or not a real file, returns nil." "Find extra source path globs using purescript package tools,if they appear to be used." (cond ((file-exists-p "psc-package.json") - (process-lines (psci--executable-find-relative psci/psc-package-path) "sources")) + (inheritenv (process-lines (psci--executable-find-relative psci/psc-package-path) "sources"))) ((or (file-exists-p "spago.dhall") (file-exists-p "spago.yaml")) - (process-lines (psci--executable-find-relative psci/spago-path) "sources" "--quiet")))) + (inheritenv (process-lines (psci--executable-find-relative psci/spago-path) "sources"))))) (defun psci--executable-find-relative (path) "If PATH is a relative path to an executable, return its full path. From ef31045295f29485fc697892fba53390fe193595 Mon Sep 17 00:00:00 2001 From: James Leslie Date: Tue, 19 Dec 2023 00:52:39 +0000 Subject: [PATCH 29/29] Filter sources given to psci (#34) The new version of spago returns an empty string as a source, which messes psci up. This commit applies a filter to the sources, preventing bad sources from being given to psci. --- psci.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/psci.el b/psci.el index ce1c2c8..e377ab0 100644 --- a/psci.el +++ b/psci.el @@ -119,13 +119,18 @@ When FILENAME is nil or not a real file, returns nil." (search-forward-regexp regexp) (match-string 1)))) +(defun psci--cleanup-sources-filter-predicate! (source) + "Predicate to see if SOURCE is suitable to be given to the psci repl." + (not (string-empty-p source))) + (defun psci--get-psc-package-sources! () "Find extra source path globs using purescript package tools,if they appear to be used." - (cond - ((file-exists-p "psc-package.json") - (inheritenv (process-lines (psci--executable-find-relative psci/psc-package-path) "sources"))) - ((or (file-exists-p "spago.dhall") (file-exists-p "spago.yaml")) - (inheritenv (process-lines (psci--executable-find-relative psci/spago-path) "sources"))))) + (-filter 'psci--cleanup-sources-filter-predicate! + (cond + ((file-exists-p "psc-package.json") + (inheritenv (process-lines (psci--executable-find-relative psci/psc-package-path) "sources"))) + ((or (file-exists-p "spago.dhall") (file-exists-p "spago.yaml")) + (inheritenv (process-lines (psci--executable-find-relative psci/spago-path) "sources")))))) (defun psci--executable-find-relative (path) "If PATH is a relative path to an executable, return its full path.