comparison lisp/eshell/em-hist.el @ 43322:80c00f33bf18

(eshell-hist-initialize): When in the minibuffer, use the global value of `eshell-history-ring', and never save it to disk, or ask to save it to disk. This allows users of session.el to control whether its global state should be persisted or not. (eshell-add-command-to-history): Don't write Eshell's history out to disk, let the governing mode control that upon exit. (eshell-add-input-to-history): New function, with most of the code from eshell-add-to-history. (eshell-add-command-to-history): New function, to record in eshell-history the commands run via eshell-command. (eshell-add-to-history): Call eshell-add-command-to-history to do most of the work.
author John Wiegley <johnw@newartisans.com>
date Sat, 16 Feb 2002 07:11:05 +0000
parents 67b464da13ec
children 5f44c387c856
comparison
equal deleted inserted replaced
43321:358616bbe6a1 43322:80c00f33bf18
214 (when (eshell-using-module 'eshell-cmpl) 214 (when (eshell-using-module 'eshell-cmpl)
215 (make-local-hook 'pcomplete-try-first-hook) 215 (make-local-hook 'pcomplete-try-first-hook)
216 (add-hook 'pcomplete-try-first-hook 216 (add-hook 'pcomplete-try-first-hook
217 'eshell-complete-history-reference nil t)) 217 'eshell-complete-history-reference nil t))
218 218
219 (if (eshell-using-module 'eshell-rebind) 219 (if (and (eshell-using-module 'eshell-rebind)
220 (not eshell-non-interactive-p))
220 (let ((rebind-alist (symbol-value 'eshell-rebind-keys-alist))) 221 (let ((rebind-alist (symbol-value 'eshell-rebind-keys-alist)))
221 (make-local-variable 'eshell-rebind-keys-alist) 222 (make-local-variable 'eshell-rebind-keys-alist)
222 (set 'eshell-rebind-keys-alist 223 (set 'eshell-rebind-keys-alist
223 (append rebind-alist eshell-hist-rebind-keys-alist)) 224 (append rebind-alist eshell-hist-rebind-keys-alist))
224 (set (make-local-variable 'search-invisible) t) 225 (set (make-local-variable 'search-invisible) t)
268 (or eshell-history-file-name 269 (or eshell-history-file-name
269 (setq eshell-history-file-name (getenv "HISTFILE"))) 270 (setq eshell-history-file-name (getenv "HISTFILE")))
270 271
271 (make-local-variable 'eshell-history-index) 272 (make-local-variable 'eshell-history-index)
272 (make-local-variable 'eshell-save-history-index) 273 (make-local-variable 'eshell-save-history-index)
273 (make-local-variable 'eshell-history-ring) 274
274 (if eshell-history-file-name 275 (if (minibuffer-window-active-p (selected-window))
275 (eshell-read-history nil t)) 276 (set (make-local-variable 'eshell-ask-to-save-history) nil)
277 (set (make-local-variable 'eshell-history-ring) nil)
278 (if eshell-history-file-name
279 (eshell-read-history nil t))
280
281 (make-local-hook 'eshell-exit-hook)
282 (add-hook 'eshell-exit-hook 'eshell-write-history nil t))
283
276 (unless eshell-history-ring 284 (unless eshell-history-ring
277 (setq eshell-history-ring (make-ring eshell-history-size))) 285 (setq eshell-history-ring (make-ring eshell-history-size)))
278 286
279 (make-local-hook 'eshell-exit-hook) 287 (make-local-hook 'eshell-exit-hook)
280 (add-hook 'eshell-exit-hook 'eshell-write-history nil t) 288 (add-hook 'eshell-exit-hook 'eshell-write-history nil t)
358 366
359 (defun eshell-get-history (index &optional ring) 367 (defun eshell-get-history (index &optional ring)
360 "Get an input line from the history ring." 368 "Get an input line from the history ring."
361 (ring-ref (or ring eshell-history-ring) index)) 369 (ring-ref (or ring eshell-history-ring) index))
362 370
363 (defun eshell-add-to-history () 371 (defun eshell-add-input-to-history (input)
364 "Add INPUT to the history ring. 372 "Add the string INPUT to the history ring.
365 The input is entered into the input history ring, if the value of 373 Input is entered into the input history ring, if the value of
366 variable `eshell-input-filter' returns non-nil when called on the 374 variable `eshell-input-filter' returns non-nil when called on the
367 input." 375 input."
376 (if (and (funcall eshell-input-filter input)
377 (or (null eshell-hist-ignoredups)
378 (not (ring-p eshell-history-ring))
379 (ring-empty-p eshell-history-ring)
380 (not (string-equal (eshell-get-history 0) input))))
381 (eshell-put-history input))
382 (setq eshell-save-history-index eshell-history-index)
383 (setq eshell-history-index nil))
384
385 (defun eshell-add-command-to-history ()
386 "Add the command entered at `eshell-command's prompt to the history ring.
387 The command is added to the input history ring, if the value of
388 variable `eshell-input-filter' returns non-nil when called on the
389 command.
390
391 This function is supposed to be called from the minibuffer, presumably
392 as a minibuffer-exit-hook."
393 (eshell-add-input-to-history
394 (buffer-substring (minibuffer-prompt-end) (point-max))))
395
396 (defun eshell-add-to-history ()
397 "Add last Eshell command to the history ring.
398 The command is entered into the input history ring, if the value of
399 variable `eshell-input-filter' returns non-nil when called on the
400 command."
368 (when (> (1- eshell-last-input-end) eshell-last-input-start) 401 (when (> (1- eshell-last-input-end) eshell-last-input-start)
369 (let ((input (buffer-substring eshell-last-input-start 402 (let ((input (buffer-substring eshell-last-input-start
370 (1- eshell-last-input-end)))) 403 (1- eshell-last-input-end))))
371 (if (and (funcall eshell-input-filter input) 404 (eshell-add-input-to-history input))))
372 (or (null eshell-hist-ignoredups)
373 (not (ring-p eshell-history-ring))
374 (ring-empty-p eshell-history-ring)
375 (not (string-equal (eshell-get-history 0) input))))
376 (eshell-put-history input))
377 (setq eshell-save-history-index eshell-history-index)
378 (setq eshell-history-index nil))))
379 405
380 (defun eshell-read-history (&optional filename silent) 406 (defun eshell-read-history (&optional filename silent)
381 "Sets the buffer's `eshell-history-ring' from a history file. 407 "Sets the buffer's `eshell-history-ring' from a history file.
382 The name of the file is given by the variable 408 The name of the file is given by the variable
383 `eshell-history-file-name'. The history ring is of size 409 `eshell-history-file-name'. The history ring is of size