From 833b4e5c61c803df32035e87524caad28f31a3f3 Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 27 Jun 2020 17:00:28 +0100 Subject: signel improvements --- net/signel.org | 80 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 28 deletions(-) (limited to 'net/signel.org') diff --git a/net/signel.org b/net/signel.org index b429b21..6f54456 100644 --- a/net/signel.org +++ b/net/signel.org @@ -328,50 +328,71 @@ named ~signel-user~ that is set /after/ enabling ~signel-chat-mode~: order here matters because the major mode activation cleans up the values of any local variables previously set (i always forget that!). -We have now almost all the ingredients to write -~signel--update-chat-buffer~, the function that inserts the received -message data into the chat buffer. We'll just need a couple of new -faces for the different parts of inserted messages: +* And a customization group + +We're going to need a couple of new faces for the different parts of +inserted messages, so we'll take the chance to be tidy and introduce a +customization group: #+begin_src emacs-lisp (defgroup signel nil "Signel") -(defface signel-contact-face '((t :weight bold)) +(defface signel-contact '((t :weight bold)) "Face for contact names." :group 'signel) -(defface signel-timestamp-face '((t :foreground "grey70")) +(defface signel-timestamp '((t :foreground "grey70")) "Face for timestamp names." :group 'signel) -(defface signel-notice-face '((t :inherit signel-timestamp-face)) +(defface signel-notice '((t :inherit signel-timestamp)) "Face for delivery notices." :group 'signel) -(defface signel-prompt-face '((t :weight bold)) +(defface signel-prompt '((t :weight bold)) "Face for the input prompt marker." :group 'signel) -(defface signel-notification-face '((t :foreground "burlywood")) +(defface signel-user '((t :foreground "orangered")) + "Face for sent messages." + :group 'signel) + +(defface signel-notification '((t :foreground "burlywood")) "Face for notifications shown by tracking, when available." :group 'signel) #+end_src -and let's be tidy and define little functions to format those parts: + +* Displaying incoming messages + +We have now almost all the ingredients to write +~signel--update-chat-buffer~, the function that inserts the received +message data into the chat buffer. Let's define a few little +functions to format those parts: #+begin_src emacs-lisp (defun signel--contact (name) - (propertize name 'face 'signel-contact-face)) + (propertize name 'face 'signel-contact)) (defun signel--timestamp (&rest p) - (propertize (apply #'concat p) 'face 'signel-timestamp-face)) + (propertize (apply #'concat p) 'face 'signel-timestamp)) (defun signel--notice (notice) - (propertize notice 'face 'signel-notice-face)) - -(defun signel--prompt () - (propertize signel-prompt 'face 'signel-prompt-face)) + (propertize notice 'face 'signel-notice)) + +(defun signel--insert-prompt () + (let ((inhibit-read-only t) + (p (point))) + (insert signel-prompt) + (set-text-properties p (- (point) 1) + '(face signel-prompt + read-only t front-sticky t rear-sticky t)))) + +(defun signel--delete-prompt () + (when (looking-at-p (regexp-quote signel-prompt)) + (let ((inhibit-read-only t)) + (delete-char (length signel-prompt))))) #+end_src With that, we're finally ready to insert messages in our signel chat @@ -389,21 +410,21 @@ buffers: :type 'boolean) (defun signel--prompt-and-notify () - (insert (signel--prompt)) + (signel--insert-prompt) (when (fboundp 'tracking-add-buffer) - (tracking-add-buffer (current-buffer) '(signel-notification-face)))) + (tracking-add-buffer (current-buffer) '(signel-notification)))) (defun signel--update-chat-buffer (source data stamp rec-stamp msg) (when-let ((b (signel--contact-buffer source))) (with-current-buffer b (goto-char (point-max)) (beginning-of-line) - (ignore-errors (delete-char (length signel-prompt))) + (signel--delete-prompt) (if data (let ((p (point))) (insert (signel--timestamp "[" stamp "] ") (signel--contact (signel--contact-name source)) - (signel--prompt) + signel-prompt data "\n") (fill-region p (point)) @@ -415,11 +436,12 @@ buffers: (not (string= source signel-cli-user)) (or signel-report-deliveries (and signel-report-read is-read))) - (progn (insert (signel--timestamp "*" (or rec-stamp stamp) "* ") - (signel--notice (if is-read "(read)" "(delivered)")) - "\n") - (signel--prompt-and-notify)) - (insert (signel--prompt))))) + (let ((inhibit-read-only t)) + (insert (signel--timestamp "*" (or rec-stamp stamp) "* ") + (signel--notice (if is-read "(read)" "(delivered)")) + "\n") + (signel--prompt-and-notify)) + (signel--insert-prompt)))) (end-of-line)))) #+end_src @@ -429,7 +451,7 @@ handling of timestamps and their formats. And of course notifications should be much more customizable (here i'm using [[https://github.com/jorgenschaefer/circe/blob/master/tracking.el][Circe's tracking.el]] if available). -* The DBUS interface +* Sending messages: the DBUS interface With that, we're going to receive and display messages and simple receipts, and i'm sure that we will feel the urge to answer some of @@ -482,12 +504,14 @@ when the buffer was created." (let* ((p (point)) (plen (length signel-prompt)) (msg (buffer-substring (+ p plen) (point-max)))) - (delete-char plen) + (signel--delete-prompt) (signel--send-message signel-user msg) (insert (signel--timestamp (format-time-string "(%H:%M) "))) (fill-region p (point-max)) (goto-char (point-max)) - (insert "\n" (signel--prompt)))) + (set-text-properties p (point) '(face signel-user)) + (insert "\n") + (signel--insert-prompt))) #+end_src and we can bind it to the return key in signal chat buffers: -- cgit v1.2.3