Last active
October 27, 2019 11:33
-
-
Save ManasJayanth/8c373087faee63ba4832a39892b34215 to your computer and use it in GitHub Desktop.
Esy mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun load-esy-env () | |
"Loads esy env" | |
(let* ((env-json-str (shell-command-to-string "esy command-env --json")) | |
(json-key-type 'string) | |
(env-pairs (json-read-from-string env-json-str))) | |
(progn | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(make-local-variable 'process-environment) | |
(setq process-environment (copy-sequence process-environment)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(make-local-variable 'exec-path) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(dolist (e env-pairs) | |
(let ((var (car e))) | |
(setenv var (cdr e)) | |
(message "%s was updated" var) | |
(if (equal var "PATH") | |
(setq exec-path (split-string (cdr e) ":"))) nil)) | |
(make-local-variable 'merlin-command) | |
(setq merlin-command (executable-find "ocamlmerlin")) | |
(make-local-variable 'refmt-command) | |
(setq refmt-command (executable-find "refmt")) | |
(message "it is an esy project") | |
)) | |
) | |
(add-hook 'reason-mode-hook (lambda () | |
(let ((is-esy-project-ready (let* ((json-object-type 'hash-table) | |
(json-array-type 'list) | |
(json-key-type 'string) | |
(json-false 'nil) | |
(json-str (shell-command-to-string | |
"esy status")) | |
(json (json-read-from-string | |
json-str)) | |
(is-esy-project-ready (gethash | |
"isProjectReadyForDev" | |
json))) | |
is-esy-project-ready))) | |
(if is-esy-project-ready (load-esy-env) | |
(message "Not an esy project"))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment