From 1c9d04d792677faed5ec68a8fdc42d44c827ae74 Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Wed, 21 Aug 2019 18:54:04 -0400 Subject: emacs: erc: fix for erc lurker (bug#36843) https://bugs.gnu.org/36843 --- .emacs.d/init.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 71b7f10..d3f8850 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -2086,7 +2086,80 @@ https://csclub.uwaterloo.ca/~abandali") (add-to-list 'erc-modules 'notifications) (add-to-list 'erc-modules 'spelling) (add-to-list 'erc-modules 'scrolltoplace) - (erc-update-modules)) + (erc-update-modules) + + (when (and (version<= "24.4" emacs-version) + (version< emacs-version "27")) + ;; fix erc-lurker bug + ;; patch submitted: https://bugs.gnu.org/36843#10 + ;; TODO: remove when patch is merged and emacs 27 is released + (defvar erc-message-parsed) + (defun erc-display-message (parsed type buffer msg &rest args) + "Display MSG in BUFFER. + +ARGS, PARSED, and TYPE are used to format MSG sensibly. + +See also `erc-format-message' and `erc-display-line'." + (let ((string (if (symbolp msg) + (apply #'erc-format-message msg args) + msg)) + (erc-message-parsed parsed)) + (setq string + (cond + ((null type) + string) + ((listp type) + (mapc (lambda (type) + (setq string + (erc-display-message-highlight type string))) + type) + string) + ((symbolp type) + (erc-display-message-highlight type string)))) + + (if (not (erc-response-p parsed)) + (erc-display-line string buffer) + (unless (erc-hide-current-message-p parsed) + (erc-put-text-property 0 (length string) 'erc-parsed parsed string) + (erc-put-text-property 0 (length string) 'rear-sticky t string) + (when (erc-response.tags parsed) + (erc-put-text-property 0 (length string) 'tags (erc-response.tags parsed) + string)) + (erc-display-line string buffer))))) + + (defun erc-lurker-update-status (_message) + "Update `erc-lurker-state' if necessary. + +This function is called from `erc-insert-pre-hook'. If the +current message is a PRIVMSG, update `erc-lurker-state' to +reflect the fact that its sender has issued a PRIVMSG at the +current time. Otherwise, take no action. + +This function depends on the fact that `erc-display-message' +lexically binds `erc-message-parsed', which is used to check if +the current message is a PRIVMSG and to determine its sender. +See also `erc-lurker-trim-nicks' and `erc-lurker-ignore-chars'. + +In order to limit memory consumption, this function also calls +`erc-lurker-cleanup' once every `erc-lurker-cleanup-interval' +updates of `erc-lurker-state'." + (when (and (boundp 'erc-message-parsed) + (erc-response-p erc-message-parsed)) + (let* ((command (erc-response.command erc-message-parsed)) + (sender + (erc-lurker-maybe-trim + (car (erc-parse-user (erc-response.sender erc-message-parsed))))) + (server + (erc-canonicalize-server-name erc-server-announced-name))) + (when (equal command "PRIVMSG") + (when (>= (cl-incf erc-lurker-cleanup-count) + erc-lurker-cleanup-interval) + (setq erc-lurker-cleanup-count 0) + (erc-lurker-cleanup)) + (unless (gethash server erc-lurker-state) + (puthash server (make-hash-table :test 'equal) erc-lurker-state)) + (puthash sender (current-time) + (gethash server erc-lurker-state)))))))) (use-package erc-fill :after erc -- cgit v1.2.3-60-g2f50