about summary refs log tree commit diff
path: root/tools/emacs-pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/emacs-pkgs')
-rw-r--r--tools/emacs-pkgs/dottime/dottime.el3
-rw-r--r--tools/emacs-pkgs/nix-util/nix-util.el40
2 files changed, 39 insertions, 4 deletions
diff --git a/tools/emacs-pkgs/dottime/dottime.el b/tools/emacs-pkgs/dottime/dottime.el
index 3500b1c9f489..2446f6488f32 100644
--- a/tools/emacs-pkgs/dottime/dottime.el
+++ b/tools/emacs-pkgs/dottime/dottime.el
@@ -67,14 +67,13 @@
   ;; This will never display offsets in the chat window, as those are
   ;; always visible in the modeline anyways.
   (when (featurep 'telega)
-    (require 'telega)
     (defun telega-ins--dottime-advice (orig timestamp)
       (let* ((dtime (decode-time timestamp t))
              (current-ts (time-to-seconds (current-time)))
              (ctime (decode-time current-ts))
              (today00 (telega--time-at00 current-ts ctime)))
         (if (> timestamp today00)
-            (telega-ins-fmt "%02d·%02d" (nth 2 dtime) (nth 1 dtime))
+            (telega-ins (format "%02d·%02d" (nth 2 dtime) (nth 1 dtime)))
           (funcall orig timestamp))))
 
     (advice-add 'telega-ins--date :around #'telega-ins--dottime-advice)))
diff --git a/tools/emacs-pkgs/nix-util/nix-util.el b/tools/emacs-pkgs/nix-util/nix-util.el
index 533e7e6f34c9..4b9dd31a022e 100644
--- a/tools/emacs-pkgs/nix-util/nix-util.el
+++ b/tools/emacs-pkgs/nix-util/nix-util.el
@@ -9,11 +9,13 @@
 ;;; Commentary:
 ;;
 ;; This package adds some functionality that I find useful when
-;; working in Nix buffers.
+;; working in Nix buffers or programs installed from Nix.
 
 (require 'json)
 (require 'map)
 
+(defvar nix-depot-path "/home/tazjin/depot")
+
 (defun nix/prefetch-github (owner repo) ; TODO(tazjin): support different branches
   "Fetch the master branch of a GitHub repository and insert the
   call to `fetchFromGitHub' at point."
@@ -38,7 +40,7 @@
                   ("finished\n"
                    (let* ((json-string (with-current-buffer outbuf
                                          (buffer-string)))
-                          (result (json-parse-string json-string)))
+                          (result (json-read-from-string json-string)))
                      (with-current-buffer buffer
                        (goto-char point)
                        (map-let (("rev" rev) ("sha256" sha256)) result
@@ -64,4 +66,38 @@
                   :stderr errbuf
                   :sentinel prefetch-handler)))
 
+(defun nix/sly-from-depot (attribute)
+  "Start a Sly REPL configured with a Lisp matching a derivation
+  from my 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 "let depot = import <depot> {}; in depot.nix.buildLisp.sbclWith [ depot.%s ]" attribute))
+         ;; TODO(tazjin): use <depot>
+         (command (list "nix-build" "--no-out-link" "-I" (format "depot=%s" nix-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)