refactor(tools/emacs-pkgs): move sly-from-depot to tvl.el
The function is depot specific and thus uses tvl-depot-path, so it belongs in `tvl.el`. Since non-sly-users won't need it, we tie its definition to loading the sly package. Change-Id: I8b104deab455d218d3df6a800e35cc104220a841 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4960 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
5f3918ba6b
commit
88eff2080c
2 changed files with 36 additions and 35 deletions
|
@ -5,14 +5,13 @@
|
||||||
;;
|
;;
|
||||||
;; Author: Vincent Ambo <tazjin@google.com>
|
;; Author: Vincent Ambo <tazjin@google.com>
|
||||||
;; Version: 1.0
|
;; Version: 1.0
|
||||||
;; Package-Requires: (cl json map s)
|
;; Package-Requires: (json map s)
|
||||||
;;
|
;;
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This package adds some functionality that I find useful when
|
;; This package adds some functionality that I find useful when
|
||||||
;; working in Nix buffers or programs installed from Nix.
|
;; working in Nix buffers or programs installed from Nix.
|
||||||
|
|
||||||
(require 'cl)
|
|
||||||
(require 'json)
|
(require 'json)
|
||||||
(require 'map)
|
(require 'map)
|
||||||
(require 's)
|
(require 's)
|
||||||
|
@ -67,36 +66,4 @@
|
||||||
:stderr errbuf
|
:stderr errbuf
|
||||||
:sentinel prefetch-handler)))
|
:sentinel prefetch-handler)))
|
||||||
|
|
||||||
(defun nix/sly-from-depot (attribute)
|
|
||||||
"Start a Sly REPL configured with a Lisp matching a derivation
|
|
||||||
from the depot.
|
|
||||||
|
|
||||||
The derivation invokes nix.buildLisp.sbclWith and is built
|
|
||||||
asynchronously. The build output is included in the error
|
|
||||||
thrown on build failures."
|
|
||||||
|
|
||||||
(interactive "sAttribute: ")
|
|
||||||
(lexical-let* ((outbuf (get-buffer-create (format "*depot-out/%s*" attribute)))
|
|
||||||
(errbuf (get-buffer-create (format "*depot-errors/%s*" attribute)))
|
|
||||||
(expression (format "(import <depot> {}).%s.repl" attribute))
|
|
||||||
(command (list "nix-build" "--no-out-link" "-I" (format "depot=%s" tvl-depot-path) "-E" expression)))
|
|
||||||
(message "Acquiring Lisp for <depot>.%s" attribute)
|
|
||||||
(make-process :name (format "depot-nix-build/%s" attribute)
|
|
||||||
:buffer outbuf
|
|
||||||
:stderr errbuf
|
|
||||||
:command command
|
|
||||||
:sentinel
|
|
||||||
(lambda (process event)
|
|
||||||
(unwind-protect
|
|
||||||
(pcase event
|
|
||||||
("finished\n"
|
|
||||||
(let* ((outpath (s-trim (with-current-buffer outbuf (buffer-string))))
|
|
||||||
(lisp-path (s-concat outpath "/bin/sbcl")))
|
|
||||||
(message "Acquired Lisp for <depot>.%s at %s" attribute lisp-path)
|
|
||||||
(sly lisp-path)))
|
|
||||||
(_ (with-current-buffer errbuf
|
|
||||||
(error "Failed to build '%s':\n%s" attribute (buffer-string)))))
|
|
||||||
(kill-buffer outbuf)
|
|
||||||
(kill-buffer errbuf))))))
|
|
||||||
|
|
||||||
(provide 'nix-util)
|
(provide 'nix-util)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
;;
|
;;
|
||||||
;; Author: Griffin Smith <grfn@gws.fyi>
|
;; Author: Griffin Smith <grfn@gws.fyi>
|
||||||
;; Version: 0.0.1
|
;; Version: 0.0.1
|
||||||
;; Package-Requires: (s dash magit)
|
;; Package-Requires: (cl s magit)
|
||||||
;;
|
;;
|
||||||
;; This file is not part of GNU Emacs.
|
;; This file is not part of GNU Emacs.
|
||||||
;;
|
;;
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
(require 'magit)
|
(require 'magit)
|
||||||
(require 's)
|
(require 's)
|
||||||
|
(require 'cl) ; TODO(tazjin): replace lexical-let* with non-deprecated alternative
|
||||||
|
|
||||||
(defgroup tvl nil
|
(defgroup tvl nil
|
||||||
"Customisation options for TVL functionality.")
|
"Customisation options for TVL functionality.")
|
||||||
|
@ -184,5 +185,38 @@ passes. This is potentially dangerous, use with care."
|
||||||
(interactive)
|
(interactive)
|
||||||
(magit-status-setup-buffer tvl-depot-path))
|
(magit-status-setup-buffer tvl-depot-path))
|
||||||
|
|
||||||
|
(eval-after-load 'sly
|
||||||
|
'(defun tvl-sly-from-depot (attribute)
|
||||||
|
"Start a Sly REPL configured with a Lisp matching a derivation
|
||||||
|
from the depot.
|
||||||
|
|
||||||
|
The derivation invokes nix.buildLisp.sbclWith and is built
|
||||||
|
asynchronously. The build output is included in the error
|
||||||
|
thrown on build failures."
|
||||||
|
|
||||||
|
(interactive "sAttribute: ")
|
||||||
|
(lexical-let* ((outbuf (get-buffer-create (format "*depot-out/%s*" attribute)))
|
||||||
|
(errbuf (get-buffer-create (format "*depot-errors/%s*" attribute)))
|
||||||
|
(expression (format "(import <depot> {}).%s.repl" attribute))
|
||||||
|
(command (list "nix-build" "--no-out-link" "-I" (format "depot=%s" tvl-depot-path) "-E" expression)))
|
||||||
|
(message "Acquiring Lisp for <depot>.%s" attribute)
|
||||||
|
(make-process :name (format "depot-nix-build/%s" attribute)
|
||||||
|
:buffer outbuf
|
||||||
|
:stderr errbuf
|
||||||
|
:command command
|
||||||
|
:sentinel
|
||||||
|
(lambda (process event)
|
||||||
|
(unwind-protect
|
||||||
|
(pcase event
|
||||||
|
("finished\n"
|
||||||
|
(let* ((outpath (s-trim (with-current-buffer outbuf (buffer-string))))
|
||||||
|
(lisp-path (s-concat outpath "/bin/sbcl")))
|
||||||
|
(message "Acquired Lisp for <depot>.%s at %s" attribute lisp-path)
|
||||||
|
(sly lisp-path)))
|
||||||
|
(_ (with-current-buffer errbuf
|
||||||
|
(error "Failed to build '%s':\n%s" attribute (buffer-string)))))
|
||||||
|
(kill-buffer outbuf)
|
||||||
|
(kill-buffer errbuf)))))))
|
||||||
|
|
||||||
(provide 'tvl)
|
(provide 'tvl)
|
||||||
;;; tvl.el ends here
|
;;; tvl.el ends here
|
||||||
|
|
Loading…
Reference in a new issue