Function: eshell-write-history
eshell-write-history is a byte-compiled function defined in
em-hist.el.gz.
Signature
(eshell-write-history &optional FILENAME APPEND)
Documentation
Writes the buffer's eshell-history-ring to a history file.
The name of the file is given by the variable
eshell-history-file-name. The original contents of the file are
lost if eshell-history-ring is not empty. If
eshell-history-file-name is nil this function does nothing.
Useful within process sentinels.
See also eshell-read-history.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/em-hist.el.gz
(defun eshell-write-history (&optional filename append)
"Writes the buffer's `eshell-history-ring' to a history file.
The name of the file is given by the variable
`eshell-history-file-name'. The original contents of the file are
lost if `eshell-history-ring' is not empty. If
`eshell-history-file-name' is nil this function does nothing.
Useful within process sentinels.
See also `eshell-read-history'."
(let* ((file (or filename eshell-history-file-name))
(resolved-file (if (stringp file) (file-truename file))))
(cond
((or (null file)
(equal file "")
(null eshell-history-ring)
(ring-empty-p eshell-history-ring))
nil)
((not (file-writable-p resolved-file))
(message "Cannot write history file %s" resolved-file))
(t
(let* ((ring eshell-history-ring)
(index (ring-length ring)))
;; Write it all out into a buffer first. Much faster, but
;; messier, than writing it one line at a time.
(with-temp-buffer
(while (> index 0)
(setq index (1- index))
(let ((start (point)))
;; Remove properties before inserting, to avoid trouble
;; with read-only strings (Bug#28700).
(insert (substring-no-properties (ring-ref ring index)) ?\n)
(subst-char-in-region start (1- (point)) ?\n ?\177)))
(eshell-with-private-file-modes
(write-region (point-min) (point-max) resolved-file append
'no-message))))))))