From: plugd Date: Sat, 18 May 2024 21:35:11 +0000 (+0200) Subject: Context creation/deletion X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=c89c5c26b8b189dee352847671e6701368350717;p=lurk.git Context creation/deletion --- diff --git a/murk.el b/murk.el index 649350a..59f7606 100644 --- a/murk.el +++ b/murk.el @@ -140,7 +140,7 @@ This includes the process and the response string.") (lambda (proc string) (unless (equal "open" (string-trim string)) (murk-display-error "Disconnected from server.") - (murk-remove-contexts-for-server server) + (murk-remove-server-contexts server) (murk-render-prompt) (murk-connection-close server)))) @@ -177,7 +177,8 @@ This includes the process and the response string.") (add-to-list 'murk-connection-table (list server proc ""))) (murk-send-msg server (murk-msg nil nil "USER" murk-nick 0 "*" murk-nick)) - (murk-send-msg server (murk-msg nil nil "NICK" murk-nick))))) + (murk-send-msg server (murk-msg nil nil "NICK" murk-nick)) + (murk-add-context (list server))))) (defun murk-send-msg (server msg) (if murk-debug @@ -279,6 +280,13 @@ The head of this list is always the current context.") (defun murk-context-server (ctx) (elt ctx 0)) (defun murk-context-name (ctx) (elt ctx 1)) +(defun murk-add-context (ctx) + (add-to-list 'murk-contexts ctx)) + +(defun murk-remove-server-contexts (server) + (setq murk-contexts + (assoc-delete-all server murk-contexts))) + ;;; Buffer ;; @@ -298,8 +306,8 @@ The head of this list is always the current context.") (insert (propertize (let ((ctx (murk-current-context))) (if ctx - (concat (murk-context-name) "@" (murk-context-server ctx)) - "")) + (concat (murk-context-name) "@" (murk-context-server ctx)) + "")) 'face 'murk-context 'read-only t) (propertize murk-prompt-string @@ -573,7 +581,14 @@ The head of this list is always the current context.") " " (number-to-string port) "]"))) (murk-display-notice nil "(Modify the `murk-networks' variable to add more.)")) - +(defun murk-command-quit (params) + (let ((ctx (murk-current-context))) + (if (not ctx) + (murk-display-error "No current context.") + (let ((quit-msg (if params (string-join params " ") murk-default-quit-msg))) + (murk-send-msg + (murk-context-server ctx) + (lurk-msg nil nil "QUIT" quit-msg)))))) ;;; Command entering ;; @@ -591,7 +606,9 @@ The head of this list is always the current context.") nil))) (if (and command-row (elt command-row 2)) (funcall (elt command-row 2) params) - (murk-send-msg (murk-msg nil nil (upcase cmd-str) params))))) + (murk-send-msg + (murk-context-server (murk-current-context)) + (murk-msg nil nil (upcase cmd-str) params))))) (_ (murk-display-error "Badly formed command."))) (unless (string-empty-p string) @@ -640,6 +657,14 @@ The head of this list is always the current context.") (delete-region murk-input-marker (point-max))) (murk-enter-string line)))) +(defun murk-history-next () + (interactive) + (murk-history-cycle -1)) + +(defun murk-history-prev () + (interactive) + (murk-history-cycle +1)) + (defun murk-complete-input () (interactive) (let ((completion-ignore-case t)) @@ -677,6 +702,8 @@ The head of this list is always the current context.") (let ((map (make-sparse-keymap))) (define-key map (kbd "RET") 'murk-enter) (define-key map (kbd "TAB") 'murk-complete-input) + (define-key map (kbd "") 'murk-history-prev) + (define-key map (kbd "") 'murk-history-next) (when (fboundp 'evil-define-key*) (evil-define-key* 'motion map (kbd "TAB") 'murk-complete-input))