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

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

[nongnu] elpa/idris-mode cd734fdc7a 1/6: Compute file path to repl histo


From: ELPA Syncer
Subject: [nongnu] elpa/idris-mode cd734fdc7a 1/6: Compute file path to repl history file at runtime if
Date: Fri, 11 Nov 2022 07:58:54 -0500 (EST)

branch: elpa/idris-mode
commit cd734fdc7a19ba6ecef896f37950b8697a8f35af
Author: Marek L <nospam.keram@gmail.com>
Commit: Marek L <nospam.keram@gmail.com>

    Compute file path to repl history file at runtime if
    
    it is not specified by user using `idris-repl-history-file` variable.
    
    Why:
    Previously the `idris-repl-history-file` used as default hardcoded path
    `~/.idris/idris-history.eld`. However the Idris 2 uses/creates
     `~/.idris2` directory, meaning if an user with only Idris 2 installed
    tries to exit Emacs he is prompted with error:
    
    ```
    History file not writable: ~/.idris/idris-history.eld" while saving the
    history. Continue? (y or n)
    ```
    
    This change also allows users with both Idris and Idris2 installed
    switch between them just by changing the interpreter variable
    and have separate repl histories for both version.
---
 idris-repl.el     | 19 ++++++++++++++-----
 idris-settings.el |  6 ++++--
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/idris-repl.el b/idris-repl.el
index bf081eb9c4..fc6d1f6192 100644
--- a/idris-repl.el
+++ b/idris-repl.el
@@ -216,7 +216,7 @@ Invokes `idris-repl-mode-hook'."
   (set (make-local-variable 'indent-tabs-mode) nil)
   (add-hook 'idris-event-hooks 'idris-repl-event-hook-function)
   (add-hook 'kill-buffer-hook 'idris-repl-remove-event-hook-function nil t)
-  (when idris-repl-history-file
+  (when (idris-repl-history-file-f)
     (idris-repl-safe-load-history)
     (add-hook 'kill-buffer-hook
               'idris-repl-safe-save-history nil t))
@@ -534,22 +534,31 @@ The handler will use qeuery to ask the use if the error 
should be ingored."
          nil
        (signal (car err) (cdr err))))))
 
+(defun idris-repl-history-file-f ()
+  "Return repl history file.
+
+Use `idris-repl-history-file' if set or fallback
+ to filepath computed from the `idris-interpreter-path'."
+  (or idris-repl-history-file
+      ;; We should use `file-name-concat' but it is only in Emacs version 28+
+      (concat "~/." (file-name-nondirectory idris-interpreter-path) 
"/idris-history.eld")))
+
 (defun idris-repl-read-history-filename ()
   (read-file-name "Use Idris REPL history from file: "
-                  idris-repl-history-file))
+                  (idris-repl-history-file-f)))
 
 (defun idris-repl-load-history (&optional filename)
   "Set the current Idris REPL history.
 It can be read either from FILENAME or `idris-repl-history-file' or
 from a user defined filename."
   (interactive (list (idris-repl-read-history-filename)))
-  (let ((file (or filename idris-repl-history-file)))
+  (let ((file (or filename (idris-repl-history-file-f))))
     (setq idris-repl-input-history (idris-repl-read-history file))))
 
 (defun idris-repl-read-history (&optional filename)
   "Read and return the history from FILENAME.
 The default value for FILENAME is `idris-repl-history-file'."
-  (let ((file (or filename idris-repl-history-file)))
+  (let ((file (or filename (idris-repl-history-file-f))))
     (cond ((not (file-readable-p file)) '())
           (t (with-temp-buffer
                (insert-file-contents file)
@@ -561,7 +570,7 @@ When Idris is setup to always load the old history and one 
uses only
 one instance of idris all the time, there is no need to merge the
 files and this function is sufficient."
   (interactive (list (idris-repl-read-history-filename)))
-  (let ((file (or filename idris-repl-history-file))
+  (let ((file (or filename (idris-repl-history-file-f)))
         (hist (or history idris-repl-input-history)))
     (unless (file-writable-p file)
       (error (format "History file not writable: %s" file)))
diff --git a/idris-settings.el b/idris-settings.el
index 4519321c5b..bc427f9a85 100644
--- a/idris-settings.el
+++ b/idris-settings.el
@@ -295,8 +295,10 @@ Set to `nil' for no banner."
   "Face for the result of an evaluation in the Idris REPL."
   :group 'idris-repl)
 
-(defcustom idris-repl-history-file "~/.idris/idris-history.eld"
-  "File to save the persistent REPL history to."
+(defcustom idris-repl-history-file nil
+  "File to save the persistent REPL history to.
+
+Defaults to ~/.[:IDRIS_EXECUTABLE_NAME:]/idris-history.eld"
   :type 'string
   :group 'idris-repl)
 



reply via email to

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