X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=lirc.el;h=131b7ccb42e44cd9c818c03ae643a7375287c1af;hb=bdfc5855121daf26be78530df1dbb605aad428f9;hp=ee6bdd4a2bfe55598845e85a9cbce583bdf9f220;hpb=a8753ebe5492cf0bc66e7b18e128c7d87936f551;p=lurk.git diff --git a/lirc.el b/lirc.el index ee6bdd4..131b7cc 100644 --- a/lirc.el +++ b/lirc.el @@ -1,4 +1,4 @@ -;;; lirc.el --- Lambdalabs irc client -*- lexical-binding:t -*- +;;; lirc.el --- Lightweight irc client -*- lexical-binding:t -*- ;; Copyright (C) 2021 Tim Vaughan @@ -28,7 +28,7 @@ ;;; Code: -(provide 'lerc) +(provide 'lirc) ;;; Customizations ;; @@ -48,16 +48,20 @@ (defcustom lirc-port 6667 "Default port.") -(defcustom lirc-prompt-string "prompt> " +(defcustom lirc-prompt-string "> " "Prompt.") ;;; Faces ;; (defface lirc-prompt - '((t :inherit font-lock-string-face)) + '((t :inherit org-level-2)) "Face used for the prompt.") +(defface lirc-channel + '((t :inherit org-list-dt)) + "Face used for the channel name in the prompt.") + ;;; Global variables ;; @@ -181,15 +185,21 @@ (with-current-buffer "*lirc*" (set-marker-insertion-type lirc-prompt-marker nil) (set-marker-insertion-type lirc-input-marker t) - (let ((inhibit-read-only t)) - (delete-region lirc-prompt-marker lirc-input-marker)) (save-excursion - (goto-char lirc-prompt-marker) (let ((inhibit-read-only t)) - (insert (propertize lirc-prompt-string - 'face 'lirc-prompt - 'read-only t - 'rear-nonsticky t)))))) + (delete-region lirc-prompt-marker lirc-input-marker) + (goto-char lirc-prompt-marker) + (insert + (propertize (if lirc-current-channel + lirc-current-channel + "[no channel]") + 'face 'lirc-channel + 'read-only t) + (propertize lirc-prompt-string + 'face 'lirc-prompt + 'read-only t + 'rear-nonsticky t))))) + (set-marker-insertion-type lirc-input-marker nil)) (defvar lirc-prompt-marker nil "Marker for prompt position in LIRC buffer.") @@ -214,21 +224,48 @@ (defun lirc-eval-msg-string (string) (let* ((msg (lirc-string->msg string))) - (cond - ((equal (lirc-msg-cmd msg) "PING") + (pcase (lirc-msg-cmd msg) + ("PING" (lirc-send-msg (lirc-msg nil nil "PONG" (lirc-msg-params msg)))) - ((string-match (rx (= 3 digit)) (lirc-msg-cmd msg)) - (lirc-display-string (string-join (cdr (lirc-msg-params msg)) " "))) - (t + ;; ((rx (= 3 digit)) + ;; (lirc-display-string (string-join (cdr (lirc-msg-params msg)) " "))) + ((and "JOIN" (let (rx (: (literal lirc-nick) "!" (* anychar))) (lirc-msg-src msg))) + (let ((channel (car (lirc-msg-params msg)))) + (setq lirc-current-channel channel) + (add-to-list 'lirc-channel-list channel) + (lirc-render-prompt))) + (_ (lirc-display-string (lirc-msg->string msg)))))) +;;; Command entering +;; + +(defun lirc-enter-string (string) + (cond ((string-prefix-p "/" string) + (let ((cmd-str (substring string 1))) + (lirc-send-msg (lirc-msg nil nil cmd-str)))) + (t + (error "Unknown command" string)))) + +(defun lirc-enter () + "Enter current contents of line after prompt." + (interactive) + (with-current-buffer "*lirc*" + (lirc-enter-string + (buffer-substring lirc-input-marker (point-max))) + (let ((inhibit-read-only t)) + (delete-region lirc-input-marker (point-max))))) + + + ;;; Mode ;; (defvar lirc-mode-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "RET") 'lirc-enter) map)) (define-derived-mode lirc-mode text-mode "lirc"