summaryrefslogtreecommitdiffhomepage
path: root/net/signel.org
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-03-04 22:59:26 +0000
committerjao <jao@gnu.org>2020-03-04 22:59:26 +0000
commit1385e63e99ae46a32aeb1bb15895ee634dd5f7ec (patch)
treefe633ecf0e020f3bc7714d5f7f3c7e688b112c14 /net/signel.org
parent6c8ca409eaaaa5f838368c62f34fc88f16cbf32b (diff)
downloadelibs-1385e63e99ae46a32aeb1bb15895ee634dd5f7ec.tar.gz
elibs-1385e63e99ae46a32aeb1bb15895ee634dd5f7ec.tar.bz2
signel faces
Diffstat (limited to 'net/signel.org')
-rw-r--r--net/signel.org80
1 files changed, 62 insertions, 18 deletions
diff --git a/net/signel.org b/net/signel.org
index 9d70d65..bbf74d7 100644
--- a/net/signel.org
+++ b/net/signel.org
@@ -319,9 +319,54 @@ 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 all the ingredients to write ~signel--update-chat-buffer~,
-the function that inserts the received message data into the chat
-buffer:
+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:
+
+#+begin_src emacs-lisp
+(defgroup signel nil "Signel")
+
+(defface signel-contact-face '((t :weight bold))
+ "Face for contact names."
+ :group 'signel)
+
+(defface signel-timestamp-face '((t :foreground "grey70"))
+ "Face for timestamp names."
+ :group 'signel)
+
+(defface signel-notice-face '((t :inherit signel-timestamp-face))
+ "Face for delivery notices."
+ :group 'signel)
+
+(defface signel-prompt-face '((t :weight bold))
+ "Face for the input prompt marker."
+ :group 'signel)
+
+(defface signel-notification-face '((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:
+
+#+begin_src emacs-lisp
+(defun signel--contact (name)
+ (propertize name 'face 'signel-contact-face))
+
+(defun signel--timestamp (&rest p)
+ (propertize (apply #'concat p) 'face 'signel-timestamp-face))
+
+(defun signel--notice (notice)
+ (propertize notice 'face 'signel-notice-face))
+
+(defun signel--prompt ()
+ (propertize signel-prompt 'face 'signel-prompt-face))
+#+end_src
+
+With that, we're finally ready to insert messages in our signel chat
+buffers:
#+begin_src emacs-lisp
(defun signel--update-chat-buffer (source data stamp rec-stamp msg)
@@ -332,9 +377,9 @@ buffer:
(ignore-errors (kill-line))
(if data
(let ((p (point)))
- (insert "[" stamp "] "
- (signel--contact-name source)
- signel-prompt
+ (insert (signel--timestamp "[" stamp "] ")
+ (signel--contact (signel--contact-name source))
+ (signel--prompt)
data
"\n")
(fill-region p (point)))
@@ -342,20 +387,19 @@ buffer:
(signel--msg-is-receipt msg)))
(is-read (signel--msg-is-read msg)))
(when (or rec-stamp stamp)
- (insert "*" (or rec-stamp stamp) "* "
- (if is-read "(read)" "(delivered)")
+ (insert (signel--timestamp "*" (or rec-stamp stamp) "* ")
+ (signel--notice (if is-read "(read)" "(delivered)"))
"\n"))))
- (insert signel-prompt))
+ (insert (signel--prompt)))
(when (fboundp 'tracking-add-buffer)
- (tracking-add-buffer b '(erc-pal-face)))))
+ (tracking-add-buffer b '(signel-notification-face)))))
#+end_src
-There are several rough edges in the above implementation that must
-be polished shold signel ever be released in the wild. For one,
-proper handling of timestamps and their formats, and some font lock
-for the different parts of the inserted texts. 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).
+There are some rough edges in the above implementation that must be
+polished shold signel ever be released in the wild. For one, proper
+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
@@ -410,10 +454,10 @@ when the buffer was created."
(let* ((p (point))
(msg (buffer-substring (+ p (length signel-prompt)) (point-max))))
(signel--send-message signel-user msg)
- (insert (format-time-string "(%H:%M) "))
+ (insert (signel--timestamp (format-time-string "(%H:%M) ")))
(fill-region p (point-max))
(goto-char (point-max))
- (insert "\n" signel-prompt)))
+ (insert "\n" (signel--prompt))))
#+end_src
and we can bind it to the return key in signal chat buffers: