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))
(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)
(apply #'concat messages)))
(defun murk-highlight-current-context ()
- (maphash
- (lambda (this-context facelist)
- (if (equal (take 2 this-context) (take 2 (murk-current-context)))
- (setcar facelist 'murk-text)
- (setcar facelist 'murk-faded)))
- murk-context-facelists)
+ (with-current-buffer "*murk*"
+ (maphash
+ (lambda (this-context facelist)
+ (if (equal (take 2 this-context) (take 2 (murk-current-context)))
+ (setcar facelist 'murk-text)
+ (setcar facelist 'murk-faded)))
+ murk-context-facelists))
(force-window-update "*murk*"))
(defun murk-zoom-in (context)
(nick (elt params 0))
(text (string-join (seq-drop params 1) " ")))
(murk-set-connection-nick network nick)
- (murk-display-notice (murk-get-context network) text)))
+ (murk-display-notice (murk-get-context network) text))
+ (let* ((row (assoc network murk-networks))
+ (channels (if (memq :channels row)
+ (cdr (memq :channels row))
+ nil)))
+ (dolist (channel channels)
+ (murk-command-join (list channel)))))
("353" ; NAMEREPLY
(let* ((params (murk-msg-params msg))
(ctx (murk-get-context network channel)))
(if ctx
(murk-add-context-users ctx names)
- (murk-display-notice nil "Users in " channel
+ (murk-display-notice ctx "Users in " channel
": " (string-join names " ")))))
("366" ; ENDOFNAMES
ctx
(murk--as-string (length (murk-context-users ctx)))
" users in " channel)
- (murk-display-notice nil "End of " channel " names list."))))
+ (murk-display-notice (murk-get-context network)
+ "End of " channel " names list."))))
("331" ; RPL_NOTOPIC
(let* ((params (murk-msg-params msg))
("NICK"
(let ((old-nick (murk-msg-src msg))
(new-nick (car (murk-msg-params msg))))
- (murk-display-notice nil old-nick " is now known as " new-nick
+ (murk-display-notice (murk-get-context network)
+ old-nick " is now known as " new-nick
" on " network)
(murk-rename-network-user network old-nick new-nick)))
("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)
(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)))
(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
(let ((ctx (murk-current-context)))
(if ctx
(if (not params)
- (murk-display-notice nil "This command can generate lots of output. Use `/LIST -yes' if you really want this, or `/LIST <channel_regexp>' to reduce the output.")
+ (murk-display-notice nil "This command can generate lots of output."
+ " Use `/LIST -yes' if you really want this,"
+ " or `/LIST <channel_regexp>' to reduce the output.")
(let ((network (murk-context-network ctx)))
(if (equal (upcase (car params)) "-YES")
(murk-send-msg network (murk-msg nil nil "LIST"))