"Default full name.")
(defcustom lirc-user-name "plugd"
"Default user name.")
-(defcustom lirc-host "irc.libera.chat"
- "Default server.")
-(defcustom lirc-port 6697
- "Default port.")
+
+(defcustom lirc-networks
+ '(("libera" "irc.libera.chat" 6697)
+ ("freenode" "chat.freenode.net" 6697)
+ ("local" "localhost" 6697))
+ "IRC networks.")
(defcustom lirc-prompt-string "> "
"Prompt.")
(defvar lirc-error-prompt
(propertize "!!!" 'face 'lirc-error))
-
;;; Network process
;;
(lirc-eval-msg-string (string-trim line))
(setq lirc-response line))))
-(defun lirc-get-process (&optional connect)
+(defun lirc-sentinel (proc string)
+ (message string))
+
+(defun lirc-start-process (network)
+ (let* ((row (assoc network lirc-networks))
+ (host (elt row 1))
+ (port (elt row 2)))
+ (make-network-process :name "lirc"
+ :host host
+ :service port
+ :filter #'lirc-filter
+ :nowait nil
+ :tls-parameters (cons 'gnutls-x509pki
+ (gnutls-boot-parameters
+ :type 'gnutls-x509pki
+ :hostname host))
+ :buffer "*lirc*")))
+
+
+(defun lirc-connect (network)
+ (setq lirc-channel-list nil)
+ (setq lirc-current-channel 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")))
(if (and proc (eq (process-status proc) 'open))
- proc
- (if connect
- (make-network-process :name "lirc"
- :host lirc-host
- :service lirc-port
- :filter #'lirc-filter
- :nowait nil
- :tls-parameters (cons 'gnutls-x509pki
- (gnutls-boot-parameters
- :type 'gnutls-x509pki
- :hostname lirc-host))
- :buffer "*lirc*")
- (lirc-display-error "No server connection established.")
- (error "No server connection established")))))
+ (process-send-string proc (concat (lirc-msg->string msg) "\r\n"))
+ (lirc-display-error "No server connection established.")
+ (error "No server connection established"))))
;;; Messages
;;
(with-current-buffer (get-buffer-create "*lirc*")
(save-excursion
(goto-char lirc-prompt-marker)
- (let ((inhibit-read-only t))
+ (let ((inhibit-read-only t)
+ (old-pos (marker-position lirc-prompt-marker))
+ (adaptive-fill-regexp (rx (= 6 anychar))))
(insert-before-markers
(propertize (concat (format-time-string "%H:%M") " ")
'face 'lirc-text
'read-only t)
(propertize (concat (apply #'concat strings) "\n")
- 'read-only t))))))
-
-(defun lirc-connect ()
- (lirc-get-process t)
- (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 (lirc-get-process)))
- (process-send-string proc (concat (lirc-msg->string msg) "\r\n"))))
+ 'read-only t))
+ (fill-region old-pos lirc-prompt-marker)))))
(defun lirc-render-prompt ()
(with-current-buffer "*lirc*"
(pcase (lirc-msg-cmd msg)
("PING"
(lirc-send-msg
- (lirc-msg nil nil "PONG" (lirc-msg-params msg))))
+ (lirc-msg nil nil "PONG" (lirc-msg-params msg)))
+ (lirc-display-notice "ping-pong"))
("353" ; NAMEREPLY
(let* ((params (lirc-msg-params msg))
(defun lirc-enter-string (string)
(if (string-prefix-p "/" string)
(pcase (substring string 1)
- ((rx (: "TOPIC" " " (let new-topic (* not-newline))))
+ ((rx (: "CONNECT " (let network (* not-newline))))
+ (lirc-display-notice "Connecting to " network "...")
+ (lirc-connect network))
+
+ ((rx (: "TOPIC " (let new-topic (* not-newline))))
(lirc-send-msg (lirc-msg nil nil "TOPIC" lirc-current-channel new-topic)))
- ((rx (: "me" " " (let action (* not-newline))))
+ ((rx (: "ME " (let action (* not-newline))))
(lirc-send-msg (lirc-msg nil nil "PRIVMSG"
(list lirc-current-channel
(concat "\01ACTION " action "\01"))))
(switch-to-buffer "*lirc*"))
(lirc-mode)
(lirc-setup-buffer)
- (lirc-connect)
"Started LIRC.")