-(defvar lirc-current-channel nil)
-
-(defun lirc-channel (name next prev users)
- (list name prev next users))
-
-(defun lirc-get-channel-name (channel)
- (elt channel 0))
-(defun lirc-get-channel-next (channel)
- (elt channel 1))
-(defun lirc-get-channel-prev (channel)
- (elt channel 2))
-(defun lirc-get-channel-users (channel)
- (elt channel 3))
-
-(defun lirc-set-channel-name (channel name)
- (setf (elt channel 0) name))
-(defun lirc-set-channel-next (channel next)
- (setf (elt channel 1) next))
-(defun lirc-set-channel-prev (channel prev)
- (setf (elt channel 2) prev))
-(defun lirc-set-channel-users (channel users)
- (setf (elt channel 3) users))
-
-(defun lirc-add-channel (new-channel)
- (if lirc-current-channel
- (let* ((prev lirc-current-channel)
- (next (lirc-get-channel-next lirc-current-channel)))
- (lirc-set-channel-next new-channel prev)
- (lirc-set-channel-prev new-channel next))
- (lirc-set-channel-next new-channel new-channel)
- (lirc-set-channel-prev new-channel new-channel))
- (setq lirc-current-channel new-channel))
-
-(defun lirc-del-channel (channel)
- (let ((prev (lirc-get-channel-prev channel))
- (next (lirc-get-channel-next channel)))
- (if (and prev next)
- (if (eq prev next)
- (progn
- (lirc-set-channel-next prev nil)
- (lirc-set-channel-prev prev nil)
- (setq lirc-current-channel prev))
- (lirc-set-channel-next prev next)
- (lirc-set-channel-prev next prev)
- (if (eq channel lirc-current-channel)
- (setq lirc-current-channel prev)))
- (setq lirc-current-channel nil))))
-
-(defun lirc-channel-do (proc)
- (if lirc-current-channel
- (let ((channel lirc-current-channel))
- (funcall proc lirc-current-channel)
- (while (not (eq (lirc-get-channel-next channel) lirc-current-channel))
- (setq channel (lirc-get-channel-next channel))
- (funcall proc channel)))))
-
-(defun lirc-get-channel-with-name (channel-name)
- (if lirc-current-channel
- (let ((channel lirc-current-channel))
- (while (and (not (equal (lirc-get-channel-name channel) channel-name))
- (not (eq (lirc-get-channel-next channel) lirc-current-channel)))
- (setq channel (lirc-get-channel-next channel)))
- (if (equal (lirc-get-channel-name channel) channel-name)
- channel
- nil))
+(defvar lirc-context-table
+ '((channel lirc-display-channel-message)
+ (nick lirc-display-private-message)
+ (host lirc-diaplay-server-message)))
+
+(defvar lirc-current-context nil)
+(defvar lirc-contexts (make-hash-table :test #'equal))
+
+(defun lirc-add-context (name)
+ (puthash name nil lirc-contexts))
+
+(defun lirc-del-context (name)
+ (remhash name lirc-contexts))
+
+(defun lirc-get-context-users (name)
+ (gethash name lirc-contexts))
+
+(defun lirc-add-context-users (context users)
+ (puthash context
+ (append users
+ (gethash context lirc-contexts))
+ lirc-contexts))
+
+(defun lirc-del-context-user (context user)
+ (puthash context
+ (remove user (gethash context lirc-contexts))
+ lirc-contexts))
+
+(defun lirc-del-user (user)
+ (dolist (context (lirc-get-context-list))
+ (lirc-del-context-user context user)))
+
+(defun lirc-get-context-type (name)
+ (cond
+ ((string-prefix-p "#" name) 'channel)
+ ((string-match-p (rx (or "." "localhost")) name) 'host)
+ (t 'nick)))
+
+(defun lirc-get-context-list ()
+ (let ((res nil))
+ (maphash (lambda (key val)
+ (cl-pushnew key res))
+ lirc-contexts)
+ res))
+
+(defun lirc-get-next-context ()
+ (if lirc-current-context
+ (let* ((context-list (lirc-get-context-list))
+ (context-list* (member lirc-current-context context-list)))
+ (if (> (length context-list*) 1)
+ (cadr context-list*)
+ (car context-list)))