From 6d41f9e0a90bf2894f83602f0dc45f1a7bdcadc2 Mon Sep 17 00:00:00 2001 From: elgusy Date: Sun, 14 Oct 2018 14:34:07 +0200 Subject: [PATCH 1/2] Checks if it obelisk a project --- dante.el | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/dante.el b/dante.el index 78b35a6..ad39913 100644 --- a/dante.el +++ b/dante.el @@ -88,6 +88,9 @@ will be in different GHCi sessions." (put 'dante-target 'safe-local-variable #'stringp) +;; A set for saving obelisk projects' root directories. +(setq obelisk-projects-dirs (make-hash-table :test 'equal)) + (defun dante-project-root () "Get the root directory for the project. If `dante-project-root' is set as a variable, return that, @@ -95,7 +98,29 @@ otherwise look for a .cabal file, or use the current dir." (file-name-as-directory (or dante-project-root (set (make-local-variable 'dante-project-root) - (file-name-directory (or (dante-cabal-find-file) (dante-buffer-file-name))))))) + (file-name-directory (or (obelisk-project-root) + (dante-cabal-find-file) + (dante-buffer-file-name))))))) + +(defun obelisk-project-root () + "Checks if a source file is a 'ob init' project's file stucture. In case it is, returns project's root + directory, also saves that directory in `obelisk-projects-dirs' set data structure so that `dante-repl-by-file' + can check faster is the project it is an obelisk project " + (let* ((file-dir-as-list (--filter (not (string= "" it)) (split-string (file-name-directory default-directory) "/"))) + (obelisk-folder-stucture? (--any? (-contains? file-dir-as-list it) '("backend" "common" "frontend")))) + (when obelisk-folder-stucture? + (let* ((obelisk-root-folder (--take-while (-none? (lambda (a) (string= it a)) '("backend" "common" "frontend")) + file-dir-as-list)) + (project-root (string-join (-concat '("") obelisk-root-folder `("")) "/"))) + (if (gethash project-root obelisk-projects-dirs nil) + project-root + (when (-all? (lambda (folder-name) + (-> (-concat '("") obelisk-root-folder `(,folder-name "")) + (string-join "/") + (file-directory-p))) + '("backend" "common" "config" "frontend" "static")) + (puthash project-root t obelisk-projects-dirs) + project-root)))))) (defun dante-repl-by-file (root files cmdline) "Return if ROOT / file exists for any file in FILES, return CMDLINE." @@ -103,6 +128,7 @@ otherwise look for a .cabal file, or use the current dir." (defcustom dante-repl-command-line-methods-alist `((styx . ,(lambda (root) (dante-repl-by-file root '("styx.yaml") '("styx" "repl" dante-target)))) + (obelisk . ,(lambda (root) (when (gethash root obelisk-projects-dirs nil) '("ob" "repl")))) (nix . ,(lambda (root) (dante-repl-by-file root '("shell.nix" "default.nix") '("nix-shell" "--pure" "--run" (concat "cabal repl " (or dante-target "") " --builddir=dist/dante"))))) (impure-nix From 055d8a883ad89e5a08bc33e94cb139e5fb74fc1c Mon Sep 17 00:00:00 2001 From: elgusy Date: Mon, 15 Oct 2018 19:39:16 +0200 Subject: [PATCH 2/2] better check for a specific .obelisk/impl dir --- dante.el | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dante.el b/dante.el index ad39913..a57dd04 100644 --- a/dante.el +++ b/dante.el @@ -114,11 +114,7 @@ otherwise look for a .cabal file, or use the current dir." (project-root (string-join (-concat '("") obelisk-root-folder `("")) "/"))) (if (gethash project-root obelisk-projects-dirs nil) project-root - (when (-all? (lambda (folder-name) - (-> (-concat '("") obelisk-root-folder `(,folder-name "")) - (string-join "/") - (file-directory-p))) - '("backend" "common" "config" "frontend" "static")) + (when (file-directory-p (concat project-root ".obelisk/impl")) (puthash project-root t obelisk-projects-dirs) project-root))))))