From 86d384f8728592aaacdccc7688fc1ae7314ccaa6 Mon Sep 17 00:00:00 2001 From: plugd Date: Thu, 15 Jul 2021 16:02:46 +0200 Subject: [PATCH] Shifted some procedures around. --- lurk.el | 98 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/lurk.el b/lurk.el index 675ec0e..e9c089f 100644 --- a/lurk.el +++ b/lurk.el @@ -866,34 +866,6 @@ in which case they match anything.") (lurk-display-notice nil " \x02" (elt row 0) "\x02: " (elt row 1))) (lurk-display-notice nil "Use /HELP COMMAND to display information about a specific command."))) -;;; Command entering -;; - -(defun lurk-enter-string (string) - (if (string-prefix-p "/" string) - (pcase string - ((rx (: "/" (let cmd-str (+ (not whitespace))) - (opt (+ whitespace) - (let params-str (+ anychar)) - string-end))) - (let ((command-row (assoc (upcase cmd-str) lurk-command-table #'equal)) - (params (if params-str - (split-string params-str nil t) - nil))) - (if command-row - (funcall (elt command-row 2) params) - (lurk-send-msg (lurk-msg nil nil (upcase cmd-str) params))))) - (_ - (lurk-display-error "Badly formed command."))) - (unless (string-empty-p string) - (if lurk-current-context - (progn - (lurk-send-msg (lurk-msg nil nil "PRIVMSG" - lurk-current-context - string)) - (lurk-display-message lurk-nick lurk-current-context string)) - (lurk-display-error "No current context."))))) - (defun lurk-command-debug (params) (setq lurk-debug (if params @@ -986,24 +958,41 @@ in which case they match anything.") (lurk-display-notice nil "Usage: /msg "))) +;;; Command entering +;; + +(defun lurk-enter-string (string) + (if (string-prefix-p "/" string) + (pcase string + ((rx (: "/" (let cmd-str (+ (not whitespace))) + (opt (+ whitespace) + (let params-str (+ anychar)) + string-end))) + (let ((command-row (assoc (upcase cmd-str) lurk-command-table #'equal)) + (params (if params-str + (split-string params-str nil t) + nil))) + (if command-row + (funcall (elt command-row 2) params) + (lurk-send-msg (lurk-msg nil nil (upcase cmd-str) params))))) + (_ + (lurk-display-error "Badly formed command."))) + (unless (string-empty-p string) + (if lurk-current-context + (progn + (lurk-send-msg (lurk-msg nil nil "PRIVMSG" + lurk-current-context + string)) + (lurk-display-message lurk-nick lurk-current-context string)) + (lurk-display-error "No current context."))))) + + ;;; Command history ;; (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) @@ -1018,14 +1007,6 @@ in which case they match anything.") (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 ;; @@ -1048,6 +1029,14 @@ in which case they match anything.") (lurk-zoom-in lurk-current-context)) (setq lurk-zoomed (not lurk-zoomed))) +(defun lurk-history-next () + (interactive) + (lurk-history-cycle -1)) + +(defun lurk-history-prev () + (interactive) + (lurk-history-cycle +1)) + (defun lurk-complete-input () (interactive) (let ((completion-ignore-case t)) @@ -1074,6 +1063,18 @@ in which case they match anything.") (unless (string-prefix-p "/" (buffer-substring start end)) (completion-in-region start end (lurk-get-context-users lurk-current-context))))))))) +(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)))) + + ;;; Mode ;; @@ -1097,6 +1098,7 @@ in which case they match anything.") (when (fboundp 'evil-set-initial-state) (evil-set-initial-state 'lurk-mode 'insert)) + ;;; Main start procedure ;; -- 2.20.1