From 398c059dc13ab46bffffc0087a95b8b31bb1f90b Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 8 Jul 2020 16:51:47 +0100 Subject: signel tweaks --- net/signel.org | 59 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/net/signel.org b/net/signel.org index 6f54456..25b7d25 100644 --- a/net/signel.org +++ b/net/signel.org @@ -393,6 +393,12 @@ functions to format those parts: (when (looking-at-p (regexp-quote signel-prompt)) (let ((inhibit-read-only t)) (delete-char (length signel-prompt))))) + +(defun signel--delete-last-prompt () + (goto-char (point-max)) + (when (re-search-backward (concat "^" (regexp-quote signel-prompt))) + (signel--delete-prompt))) + #+end_src With that, we're finally ready to insert messages in our signel chat @@ -414,35 +420,32 @@ buffers: (when (fboundp 'tracking-add-buffer) (tracking-add-buffer (current-buffer) '(signel-notification)))) +(defun signel--needs-insert-p (data stamp rec-stamp msg) + (or data + (and (or rec-stamp stamp) + (not (string= source signel-cli-user)) + (or signel-report-deliveries + (and signel-report-read (signel--msg-is-read msg)))))) + (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) - (signel--delete-prompt) - (if data - (let ((p (point))) - (insert (signel--timestamp "[" stamp "] ") - (signel--contact (signel--contact-name source)) - signel-prompt - data - "\n") - (fill-region p (point)) - (signel--prompt-and-notify)) - (let ((is-delivery (or (signel--msg-is-delivery msg) - (signel--msg-is-receipt msg))) - (is-read (signel--msg-is-read msg))) - (if (and (or rec-stamp stamp) - (not (string= source signel-cli-user)) - (or signel-report-deliveries - (and signel-report-read is-read))) - (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)))) + (when (signel--needs-insert-p data stamp rec-stamp msg) + (when-let ((b (signel--contact-buffer source))) + (with-current-buffer b + (signel--delete-last-prompt) + (if data + (let ((p (point))) + (insert (signel--timestamp "[" stamp "] ") + (signel--contact (signel--contact-name source)) + signel-prompt + data + "\n") + (fill-region p (point))) + (let ((is-read (signel--msg-is-read msg))) + (insert (signel--timestamp "*" (or rec-stamp stamp) "* ") + (signel--notice (if is-read "(read)" "(delivered)")) + "\n"))) + (signel--prompt-and-notify) + (end-of-line))))) #+end_src There are some rough edges in the above implementation that must be -- cgit v1.2.3