From 9bef2f474186f9fbbcd1a2ad2c3e1f30e0328d3c Mon Sep 17 00:00:00 2001 From: plugd Date: Mon, 20 May 2024 14:35:33 +0200 Subject: [PATCH] Added context switching primitives. --- murk.el | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/murk.el b/murk.el index e15bc84..64bc81d 100644 --- a/murk.el +++ b/murk.el @@ -53,7 +53,8 @@ '(("debug" "localhost" 6697) ("libera" "irc.libera.chat" 6697) ("tilde" "tilde.chat" 6697) - ("freenode" "chat.freenode.net" 6697)) + ("freenode" "chat.freenode.net" 6697) + ("mbr" "mbrserver.com" 6667 :notls)) "IRC networks." :type '(alist :key-type string)) @@ -312,12 +313,20 @@ The head of this list is always the current context.") (equal (seq-take c1 2) (seq-take c2 2))))) -(defun murk-context-server (ctx) (elt ctx 0)) -(defun murk-context-channel (ctx) (elt ctx 1)) -(defun murk-context-users (ctx) (elt ctx 2)) +(defun murk-context-server (ctx) + (elt ctx 0)) + +(defun murk-context-channel (ctx) + (elt ctx 1)) + +(defun murk-context-users (ctx) + (elt ctx 2)) + (defun murk-set-context-users (ctx users) (setcar (cddr ctx) users)) -(defun murk-server-context-p (ctx) (not (cdr ctx))) + +(defun murk-server-context-p (ctx) + (not (cdr ctx))) (defun murk-add-context (ctx) (add-to-list 'murk-contexts ctx)) @@ -340,9 +349,17 @@ The head of this list is always the current context.") (concat (murk-context-channel ctx) "@" (murk-context-server ctx)))) -(defun murk-get-context (server &optional name) - (if name - (let ((test-ctx (list server name))) +(defun murk-string->context (string) + (if (not (string-prefix-p "#" string)) + (murk-get-context string) + (let* ((parts (string-split string "@")) + (channel (elt parts 0)) + (server (elt parts 1))) + (murk-get-context server channel)))) + +(defun murk-get-context (server &optional channel) + (if channel + (let ((test-ctx (list server channel))) (seq-find (lambda (ctx) (equal (seq-take ctx 2) test-ctx)) murk-contexts)) @@ -357,6 +374,13 @@ The head of this list is always the current context.") (seq-take murk-contexts nminus1))) (append (cdr murk-contexts) (list (car murk-contexts)))))) +(defun murk-switch-to-context (ctx) + (setq murk-contexts + (let* ((new-head (memq ctx murk-contexts)) + (new-tail (take (- (length murk-contexts) + (length new-head))))) + (append new-head new-tail)))) + (defun murk-add-context-users (ctx users) (murk-set-context-users ctx -- 2.20.1