'((t :inherit org-level-2))
"Face used for the prompt.")
-(defface lirc-channel
+(defface lirc-context
'((t :inherit org-list-dt))
- "Face used for the channel name in the prompt.")
+ "Face used for the context name in the prompt.")
(defface lirc-faded
'((t :inherit font-lock-preprocessor-face))
(lirc-eval-msg-string (string-trim line))
(setq lirc-response line))))
+(defun lirc-sentinel (proc string)
+ (unless (equal "open" (string-trim string))
+ (lirc-display-error "Disconnected from server.")
+ (clrhash lirc-contexts)
+ (setq lirc-current-context nil)
+ (lirc-render-prompt)))
+
(defun lirc-start-process (network)
(let* ((row (assoc network lirc-networks))
:host host
:service port
:filter #'lirc-filter
+ :sentinel #'lirc-sentinel
:nowait nil
:tls-parameters (cons 'gnutls-x509pki
(gnutls-boot-parameters
(defun lirc-connect (network)
(if (get-process "lirc")
(lirc-display-error "Already connected. Disconnect first.")
- (setq lirc-current-context nil)
- (clrhash lirc-contexts)
- (lirc-start-process network)
- (lirc-send-msg (lirc-msg nil nil "USER" lirc-user-name 0 "*" lirc-full-name))
- (lirc-send-msg (lirc-msg nil nil "NICK" lirc-nick))))
+ (if (not (assoc network lirc-networks))
+ (lirc-display-error "Network '" network "' is unknown.")
+ (clrhash lirc-contexts)
+ (setq lirc-current-context nil)
+ (lirc-start-process network)
+ (lirc-send-msg (lirc-msg nil nil "USER" lirc-user-name 0 "*" lirc-full-name))
+ (lirc-send-msg (lirc-msg nil nil "NICK" lirc-nick)))))
(defun lirc-send-msg (msg)
(let ((proc (get-process "lirc")))
lirc-contexts)
res))
-(defun lirc-get-next-context ()
+(defun lirc-get-next-context (&optional prev)
(if lirc-current-context
- (let* ((context-list (lirc-get-context-list))
+ (let* ((context-list (if prev
+ (reverse (lirc-get-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)))
nil))
-
-(defun lirc-cycle-contexts ()
- (interactive)
- (if lirc-current-channel
+(defun lirc-cycle-contexts (&optional rev)
+ (if lirc-current-context
(progn
- (setq lirc-current-channel (lirc-get-channel-next lirc-current-channel))
+ (setq lirc-current-context (lirc-get-next-context rev))
(lirc-render-prompt))
(lirc-display-error "No channels joined.")))
+(defun lirc-cycle-contexts-forward ()
+ (interactive)
+ (lirc-cycle-contexts))
+
+(defun lirc-cycle-contexts-reverse ()
+ (interactive)
+ (lirc-cycle-contexts t))
;;; Buffer
;;
(if (string-prefix-p "/" string)
(pcase (substring string 1)
((rx (: "CONNECT " (let network (* not-newline))))
- (lirc-display-notice "Connecting to " network "...")
+ (lirc-display-notice "Attempting to connect to " network "...")
(lirc-connect network))
((rx (: "TOPIC " (let new-topic (* not-newline))))
(let to (* (not whitespace)))
" "
(let text (* not-newline)))
- (lirc-send-msg (lirc-msg nil nil "PRIVMSG" target text))
- (lirc-display-message lirc-nick target text))
+ (lirc-send-msg (lirc-msg nil nil "PRIVMSG" to text))
+ (lirc-display-message lirc-nick to text))
((rx (: (let cmd-str (+ (not whitespace)))
(opt (: " " (let params-str (* not-newline))))))
(defvar lirc-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") 'lirc-enter)
- ;; (define-key map (kbd "<C-tab>") 'lirc-cycle-channels)
+ (define-key map (kbd "<C-tab>") 'lirc-cycle-contexts-forward)
+ (define-key map (kbd "<C-S-tab>") 'lirc-cycle-contexts-reverse)
map))
(define-derived-mode lirc-mode text-mode "lirc"