Make sermon usable with visual-line-mode

This commit is contained in:
Tom Willemse 2016-08-28 01:18:52 +02:00
parent ced484c62a
commit cd257205ed

View file

@ -59,67 +59,90 @@
(defvar sermon-original-format-server-nick-change nil (defvar sermon-original-format-server-nick-change nil
"The original value of `circe-format-server-nick-change'.") "The original value of `circe-format-server-nick-change'.")
(defun sermon--fill-string ()
(make-string (+ sermon-longest-nick 3) ?\s))
(defun sermon--update-longest-nick (keywords) (defun sermon--update-longest-nick (keywords)
(let* ((nick (plist-get keywords :nick)) (let* ((nick (plist-get keywords :nick))
(len (length nick))) (len (length nick)))
(when (> len sermon-longest-nick) (when (> len sermon-longest-nick)
(setq sermon-longest-nick len) (setq sermon-longest-nick len)
(setq-local lui-fill-type (make-string (+ len 3) ?\s))))) (when lui-fill-type
(setq-local lui-fill-type (sermon--fill-string))))))
(defun sermon-say-formatter (&rest keywords) (defun sermon-say-formatter (&rest keywords)
(sermon--update-longest-nick keywords) (sermon--update-longest-nick keywords)
(lui-format (format "{nick:%ds} {body}" sermon-longest-nick) (propertize
keywords)) (lui-format (format "{nick:%ds} {body}" sermon-longest-nick)
keywords)
'wrap-prefix (sermon--fill-string)))
(defun sermon-self-say-formatter (&rest keywords) (defun sermon-self-say-formatter (&rest keywords)
(format (format "%%%ds %%s" sermon-longest-nick) (propertize (format (format "%%%ds %%s" sermon-longest-nick)
">" (plist-get keywords :body))) ">" (plist-get keywords :body))
'wrap-prefix (sermon--fill-string)))
(defun sermon-action-formatter (&rest keywords) (defun sermon-action-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} {nick} {body}" sermon-longest-nick) (lui-format
(plist-put keywords :intro "*"))) (format "{intro:%ds} {nick} {body}" sermon-longest-nick)
(plist-put keywords :intro "*"))
'wrap-prefix (sermon--fill-string)))
(defun sermon-server-message-formatter (&rest keywords) (defun sermon-server-message-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} {body}" sermon-longest-nick) (lui-format
(plist-put keywords :intro "***"))) (format "{intro:%ds} {body}" sermon-longest-nick)
(plist-put keywords :intro "***"))
'wrap-prefix (sermon--fill-string)))
(defun sermon-server-join-in-channel-formatter (&rest keywords) (defun sermon-server-join-in-channel-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} Join: {nick} ({userinfo}) joined {channel}" (lui-format
sermon-longest-nick) (format "{intro:%ds} Join: {nick} ({userinfo}) joined {channel}"
(plist-put keywords :intro ">>>"))) sermon-longest-nick)
(plist-put keywords :intro ">>>"))
'wrap-prefix (sermon--fill-string)))
(defun sermon-server-join-formatter (&rest keywords) (defun sermon-server-join-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} Join: {nick} ({userinfo})" (lui-format
sermon-longest-nick) (format "{intro:%ds} Join: {nick} ({userinfo})"
(plist-put keywords :intro ">>>"))) sermon-longest-nick)
(plist-put keywords :intro ">>>"))
'wrap-prefix (sermon--fill-string)))
(defun sermon-server-quit-formatter (&rest keywords) (defun sermon-server-quit-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} Quit: {nick} ({userhost}) left IRC: {reason}" (lui-format
sermon-longest-nick) (format "{intro:%ds} Quit: {nick} ({userhost}) left IRC: {reason}"
(plist-put keywords :intro "<<<"))) sermon-longest-nick)
(plist-put keywords :intro "<<<"))
'wrap-prefix (sermon--fill-string)))
(defun sermon-server-quit-channel-formatter (&rest keywords) (defun sermon-server-quit-channel-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} Quit: {nick} ({userhost}) left {channel}: {reason}" (lui-format
sermon-longest-nick) (format "{intro:%ds} Quit: {nick} ({userhost}) left {channel}: {reason}"
(plist-put keywords :intro "<<<"))) sermon-longest-nick)
(plist-put keywords :intro "<<<"))
'wrap-prefix (sermon--fill-string)))
(defun sermon-server-part-formatter (&rest keywords) (defun sermon-server-part-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} Part: {nick} ({userhost}) left {channel}: {reason}" (lui-format
sermon-longest-nick) (format "{intro:%ds} Part: {nick} ({userhost}) left {channel}: {reason}"
(plist-put keywords :intro "***"))) sermon-longest-nick)
(plist-put keywords :intro "***"))
'wrap-prefix (sermon--fill-string)))
(defun sermon-server-nick-change-formatter (&rest keywords) (defun sermon-server-nick-change-formatter (&rest keywords)
(lui-format (propertize
(format "{intro:%ds} Nick change: {old-nick} ({userhost}) is now know as {new-nick}" (lui-format
sermon-longest-nick) (format "{intro:%ds} Nick change: {old-nick} ({userhost}) is now know as {new-nick}"
(plist-put keywords :intro "***"))) sermon-longest-nick)
(plist-put keywords :intro "***"))
'wrap-prefix (sermon--fill-string)))
;;;###autoload ;;;###autoload
(defun enable-sermon () (defun enable-sermon ()