Skip to content

Commit ea83139

Browse files
authored
Merge pull request #559 from keram/repl-history-file-f
Compute file path to repl history file at runtime if
2 parents 1adee4f + 60cf567 commit ea83139

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

idris-repl.el

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Invokes `idris-repl-mode-hook'."
219219
(set (make-local-variable 'indent-tabs-mode) nil)
220220
(add-hook 'idris-event-hooks 'idris-repl-event-hook-function)
221221
(add-hook 'kill-buffer-hook 'idris-repl-remove-event-hook-function nil t)
222-
(when idris-repl-history-file
222+
(when (idris-repl-history-file-f)
223223
(idris-repl-safe-load-history)
224224
(add-hook 'kill-buffer-hook
225225
'idris-repl-safe-save-history nil t))
@@ -537,22 +537,31 @@ The handler will use qeuery to ask the use if the error should be ingored."
537537
nil
538538
(signal (car err) (cdr err))))))
539539

540+
(defun idris-repl-history-file-f ()
541+
"Return repl history file.
542+
543+
Use `idris-repl-history-file' if set or fallback
544+
to filepath computed from the `idris-interpreter-path'."
545+
(or idris-repl-history-file
546+
;; We should use `file-name-concat' but it is only in Emacs version 28+
547+
(concat "~/." (file-name-nondirectory idris-interpreter-path) "/idris-history.eld")))
548+
540549
(defun idris-repl-read-history-filename ()
541550
(read-file-name "Use Idris REPL history from file: "
542-
idris-repl-history-file))
551+
(idris-repl-history-file-f)))
543552

544553
(defun idris-repl-load-history (&optional filename)
545554
"Set the current Idris REPL history.
546555
It can be read either from FILENAME or `idris-repl-history-file' or
547556
from a user defined filename."
548557
(interactive (list (idris-repl-read-history-filename)))
549-
(let ((file (or filename idris-repl-history-file)))
558+
(let ((file (or filename (idris-repl-history-file-f))))
550559
(setq idris-repl-input-history (idris-repl-read-history file))))
551560

552561
(defun idris-repl-read-history (&optional filename)
553562
"Read and return the history from FILENAME.
554563
The default value for FILENAME is `idris-repl-history-file'."
555-
(let ((file (or filename idris-repl-history-file)))
564+
(let ((file (or filename (idris-repl-history-file-f))))
556565
(cond ((not (file-readable-p file)) '())
557566
(t (with-temp-buffer
558567
(insert-file-contents file)
@@ -564,7 +573,7 @@ When Idris is setup to always load the old history and one uses only
564573
one instance of idris all the time, there is no need to merge the
565574
files and this function is sufficient."
566575
(interactive (list (idris-repl-read-history-filename)))
567-
(let ((file (or filename idris-repl-history-file))
576+
(let ((file (or filename (idris-repl-history-file-f)))
568577
(hist (or history idris-repl-input-history)))
569578
(unless (file-writable-p file)
570579
(error (format "History file not writable: %s" file)))

idris-settings.el

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,16 @@ Set to `nil' for no banner."
295295
"Face for the result of an evaluation in the Idris REPL."
296296
:group 'idris-repl)
297297

298-
(defcustom idris-repl-history-file "~/.idris/idris-history.eld"
299-
"File to save the persistent REPL history to."
298+
(defcustom idris-repl-history-file nil
299+
"File to save the persistent REPL history to.
300+
301+
By default we assume Idris' default configuration home is:
302+
303+
$HOME/.idris/idris-history.eld.
304+
305+
If you have installed/configured Idris differently, or are
306+
using Idris2, then you may wish to customise this variable."
307+
300308
:type 'string
301309
:group 'idris-repl)
302310

0 commit comments

Comments
 (0)