From d0aadfe2997e1d561aacffb6a3d1f554af439811 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Mon, 5 Jul 2021 22:58:28 +0200 Subject: [PATCH] Added history cycling. --- lurk.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lurk.el b/lurk.el index b22ca85..0c9c31b 100644 --- a/lurk.el +++ b/lurk.el @@ -738,15 +738,42 @@ portion of the source component of the message, as LURK doesn't use this.") (lurk-display-message lurk-nick lurk-current-context string)) (lurk-display-error "No current context."))))) +(defvar lurk-history nil + "Commands and messages sent in current session.") + + (defun lurk-enter () "Enter current contents of line after prompt." (interactive) (with-current-buffer "*lurk*" (let ((line (buffer-substring lurk-input-marker (point-max)))) + (push line lurk-history) + (setq lurk-history-index nil) (let ((inhibit-read-only t)) (delete-region lurk-input-marker (point-max))) (lurk-enter-string line)))) +(defvar lurk-history-index nil) + +(defun lurk-history-cycle (delta) + (when lurk-history + (with-current-buffer "*lurk*" + (if lurk-history-index + (setq lurk-history-index + (max 0 + (min (- (length lurk-history) 1) + (+ delta lurk-history-index)))) + (setq lurk-history-index 0)) + (delete-region lurk-input-marker (point-max)) + (insert (elt lurk-history lurk-history-index))))) + +(defun lurk-history-next () + (interactive) + (lurk-history-cycle -1)) + +(defun lurk-history-prev () + (interactive) + (lurk-history-cycle +1)) ;;; Interactive functions ;; @@ -779,6 +806,7 @@ portion of the source component of the message, as LURK doesn't use this.") (unless (string-prefix-p "/" (buffer-substring start end)) (completion-in-region start end (lurk-get-context-users lurk-current-context)))))) + ;;; Mode ;; @@ -789,8 +817,16 @@ portion of the source component of the message, as LURK doesn't use this.") (define-key map (kbd "C-c C-z") 'lurk-toggle-zoom) (define-key map (kbd "") 'lurk-cycle-contexts-forward) (define-key map (kbd "") 'lurk-cycle-contexts-reverse) + (define-key map (kbd "") 'lurk-history-prev) + (define-key map (kbd "") 'lurk-history-next) + ;; (when (fboundp 'evil-define-key*) + ;; (evil-define-key* 'insert map + ;; (kbd "") 'lurk-history-prev + ;; (kbd "") 'lurk-history-next)) map)) +(defvar lurk-mode-map) + (define-derived-mode lurk-mode text-mode "lurk" "Major mode for LURK.") -- 2.20.1