Function: term-write-input-ring

term-write-input-ring is a byte-compiled function defined in term.el.gz.

Signature

(term-write-input-ring)

Documentation

Write the buffer's term-input-ring to a history file.

The name of the file is given by the variable term-input-ring-file-name. The original contents of the file are lost if term-input-ring is not empty. If term-input-ring-file-name is nil this function does nothing.

Useful within process sentinels.

See also term-read-input-ring.

Source Code

;; Defined in /usr/src/emacs/lisp/term.el.gz
(defun term-write-input-ring ()
  "Write the buffer's `term-input-ring' to a history file.
The name of the file is given by the variable `term-input-ring-file-name'.
The original contents of the file are lost if `term-input-ring' is not empty.
If `term-input-ring-file-name' is nil this function does nothing.

Useful within process sentinels.

See also `term-read-input-ring'."
  (cond ((or (null term-input-ring-file-name)
	     (equal term-input-ring-file-name "")
	     (null term-input-ring) (ring-empty-p term-input-ring))
	 nil)
	((not (file-writable-p term-input-ring-file-name))
	 (message "Cannot write history file %s" term-input-ring-file-name))
	(t
	 (let* ((history-buf (get-buffer-create " *Temp Input History*"))
		(ring term-input-ring)
		(file term-input-ring-file-name)
		(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-current-buffer history-buf
	     (erase-buffer)
	     (while (> index 0)
	       (setq index (1- index))
	       (insert (ring-ref ring index) ?\n))
	     (write-region (buffer-string) nil file nil 'no-message)
	     (kill-buffer nil))))))