emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/nix-mode c81c03b35e 403/500: nix-repl: use history file


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode c81c03b35e 403/500: nix-repl: use history file
Date: Sat, 29 Jan 2022 08:27:49 -0500 (EST)

branch: elpa/nix-mode
commit c81c03b35e10b79add7f18c7867ef76f120ab7ba
Author: Brian Leung <leungbk@mailfence.com>
Commit: Brian Leung <leungbk@mailfence.com>

    nix-repl: use history file
---
 nix-repl.el | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/nix-repl.el b/nix-repl.el
index 440b4a5962..d1fb5026d0 100644
--- a/nix-repl.el
+++ b/nix-repl.el
@@ -34,10 +34,33 @@
     (define-key map "\t" 'completion-at-point)
     map))
 
+(defun nix-repl-save-all-histories ()
+  "Call `comint-write-input-ring' for all `nix-repl-mode' buffers."
+  (dolist (buf (buffer-list))
+    (with-current-buffer buf
+      (when (eq major-mode 'nix-repl-mode)
+        (comint-write-input-ring)))))
+
 (define-derived-mode nix-repl-mode comint-mode "Nix-REPL"
   "Interactive prompt for Nix."
   (setq-local comint-prompt-regexp nix-prompt-regexp)
   (setq-local comint-prompt-read-only t)
+  (let* ((is-remote (file-remote-p default-directory))
+         (maybe-xdg-data-home (if is-remote
+                                  (shell-command-to-string "echo -n 
$XDG_DATA_HOME")
+                                (or (getenv "XDG_DATA_HOME")
+                                    "")))
+         (path-prefix (if (string-empty-p maybe-xdg-data-home)
+                          "~/.local/share"
+                        maybe-xdg-data-home))
+         (history-path (concat
+                        is-remote
+                        path-prefix
+                        "/nix/repl-history")))
+    (setq-local comint-input-ring-file-name history-path))
+  (comint-read-input-ring t)
+  (add-hook 'kill-buffer-hook #'comint-write-input-ring nil 'local)
+  (add-hook 'kill-emacs-hook #'nix-repl-save-all-histories nil 'local)
   (add-hook 'completion-at-point-functions
             #'nix-repl-completion-at-point nil 'local))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]