From: plugd Date: Fri, 24 May 2024 12:23:50 +0000 (+0200) Subject: Added switchcontext command X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=44a80d963cfe3bdffc606d34d776a50fd05346a9;p=lurk.git Added switchcontext command --- diff --git a/murk.el b/murk.el index 8ea2fa3..708ed2c 100644 --- a/murk.el +++ b/murk.el @@ -365,10 +365,11 @@ The head of this list is always the current context.") murk-contexts))) (defun murk-context->string (ctx) + (concat (if (murk-network-context-p ctx) - (concat "[" (murk-context-network ctx) "]") - (concat (murk-context-channel ctx) "@" - (murk-context-network ctx)))) + "" + (concat (murk-context-channel ctx) "@")) + (murk-context-network ctx))) (defun murk-string->context (string) (if (not (string-prefix-p "#" string)) @@ -399,7 +400,8 @@ The head of this list is always the current context.") (setq murk-contexts (let* ((new-head (memq ctx murk-contexts)) (new-tail (take (- (length murk-contexts) - (length new-head))))) + (length new-head)) + murk-contexts))) (append new-head new-tail)))) (defun murk-add-context-users (ctx users) @@ -963,11 +965,12 @@ The head of this list is always the current context.") ("CONNECT" "Connect to an IRC network." murk-command-connect murk-network-completions) ("QUIT" "Disconnect from current network." murk-command-quit) ("JOIN" "Join one or more channels." murk-command-join) - ("PART" "Leave channel." murk-command-part murk-context-completions) + ("PART" "Leave channel." murk-command-part murk-channel-completions) + ("SWITCHCONTEXT" "Switch current context" murk-command-switch-context murk-context-completions) ("NICK" "Change nick." murk-command-nick) ("LIST" "Display details of one or more channels." murk-command-list) ("TOPIC" "Set/query topic for current channel." murk-command-topic) - ("USERS" "List nicks of users in current context." murk-command-users) + ("USERS" "List nicks of users in current channel." murk-command-users) ("MSG" "Send private message to user." murk-command-msg murk-nick-completions) ("ME" "Display action." murk-command-me) ("VERSION" "Request version of another user's client via CTCP." murk-command-version murk-nick-completions) @@ -981,6 +984,19 @@ The head of this list is always the current context.") (defun murk-network-completions () (mapcar (lambda (row) (car row)) murk-networks)) +(defun murk-help-completions () + (mapcar (lambda (row) (car row)) murk-command-table)) + +(defun murk-channel-completions () + (mapcar (lambda (ctx) + (murk-context->string ctx)) + (seq-filter (lambda (ctx) + (not (murk-network-context-p ctx))) + murk-contexts))) + +(defun murk-context-completions () + (mapcar (lambda (ctx) (murk-context->string ctx)) murk-contexts)) + (defun murk-command-help (params) (if params (let* ((cmd-str (upcase (car params))) @@ -1058,13 +1074,25 @@ The head of this list is always the current context.") (murk-display-notice nil "Usage: /join channel [channel2 ...]"))) (defun murk-command-part (params) - (let* ((network (murk-context-network (murk-current-context))) - (channel (if params - (car params) - (murk-context-channel (murk-current-context))))) - (if channel - (murk-send-msg network (murk-msg nil nil "PART" channel)) - (murk-display-error "No current channel to leave")))) + (let ((ctx (cond + ((not params) (murk-current-context)) + ((seq-contains (car params) "@") (murk-string->context (car params))) + (t (list (murk-context-network (murk-current-context)) (car params)))))) + (let ((network (murk-context-network ctx)) + (channel (murk-context-channel ctx))) + (if channel + (murk-send-msg network (murk-msg nil nil "PART" channel)) + (murk-display-error "Specify which channel to leave"))))) + +(defun murk-command-switch-context (params) + (if (not params) + (murk-display-notice nil "Usage: /switchcontext #channel@network") + (let ((ctx (murk-string->context (car params)))) + (murk-switch-to-context ctx) + (murk-highlight-current-context) + (murk-render-prompt) + (if murk-zoomed + (murk-zoom-in (murk-current-context)))))) (defun murk-command-nick (params) (if params