diff options
Diffstat (limited to 'lisp/erc/erc-ring.el')
-rw-r--r-- | lisp/erc/erc-ring.el | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/lisp/erc/erc-ring.el b/lisp/erc/erc-ring.el index 71a9f8ef3da..666fd585926 100644 --- a/lisp/erc/erc-ring.el +++ b/lisp/erc/erc-ring.el @@ -1,4 +1,4 @@ -;; erc-ring.el -- Command history handling for erc using ring.el +;;; erc-ring.el --- Command history handling for erc using ring.el -*- lexical-binding: t; -*- ;; Copyright (C) 2001-2004, 2006-2021 Free Software Foundation, Inc. @@ -46,12 +46,12 @@ (define-erc-module ring nil "Stores input in a ring so that previous commands and messages can be recalled using M-p and M-n." - ((add-hook 'erc-pre-send-functions 'erc-add-to-input-ring) - (define-key erc-mode-map "\M-p" 'erc-previous-command) - (define-key erc-mode-map "\M-n" 'erc-next-command)) - ((remove-hook 'erc-pre-send-functions 'erc-add-to-input-ring) - (define-key erc-mode-map "\M-p" 'undefined) - (define-key erc-mode-map "\M-n" 'undefined))) + ((add-hook 'erc-pre-send-functions #'erc-add-to-input-ring) + (define-key erc-mode-map "\M-p" #'erc-previous-command) + (define-key erc-mode-map "\M-n" #'erc-next-command)) + ((remove-hook 'erc-pre-send-functions #'erc-add-to-input-ring) + (define-key erc-mode-map "\M-p" #'undefined) + (define-key erc-mode-map "\M-n" #'undefined))) (defvar-local erc-input-ring nil "Input ring for erc.") @@ -69,10 +69,13 @@ Call this function when setting up the mode." (setq erc-input-ring (make-ring comint-input-ring-size))) (setq erc-input-ring-index nil)) -(defun erc-add-to-input-ring (state) - "Add string S to the input ring and reset history position." +(defun erc-add-to-input-ring (state-or-string) + "Add STATE-OR-STRING to input ring and reset history position. +STATE-OR-STRING should be a string or an erc-input object." (unless erc-input-ring (erc-input-ring-setup)) - (ring-insert erc-input-ring (erc-input-string state)) + (ring-insert erc-input-ring (if (erc-input-p state-or-string) + (erc-input-string state-or-string) + state-or-string)) ; string (setq erc-input-ring-index nil)) (defun erc-clear-input-ring () @@ -101,11 +104,10 @@ containing a password." ;; area, push it on the history ring before moving back through ;; the input history, so it will be there when we return to the ;; front. - (if (null erc-input-ring-index) - (when (> (point-max) erc-input-marker) - (erc-add-to-input-ring (buffer-substring erc-input-marker - (point-max))) - (setq erc-input-ring-index 0))) + (when (and (null erc-input-ring-index) + (> (point-max) erc-input-marker)) + (erc-add-to-input-ring (erc-user-input)) + (setq erc-input-ring-index 0)) (setq erc-input-ring-index (if erc-input-ring-index (ring-plus1 erc-input-ring-index |