1
0
Fork
You've already forked erc-history
0
Retrieve chat history when scrolling upward from IRC channels with logs in Emacs's ERC
  • Emacs Lisp 100%
Find a file
2026年04月11日 01:05:24 +03:00
erc-history.el fix pulling bugs and update README to include working example 2026年04月11日 01:05:24 +03:00
preview.gif update preview 2024年06月21日 22:51:12 +03:00
README.org fix pulling bugs and update README to include working example 2026年04月11日 01:05:24 +03:00

ERC History

This package enhances Emacs's IRC client ERC by enabling it to retrieve chat history from channels. Note that chat logs must be archived and accessible online (currently, this package only supports HTTP access).

Configuration

The primary configuration required is setting the variable erc-history-sources, which is a list of sources (HTTP links) and the channels they offer logs for.

The link can include wildcards that will be replaced when pulling chat logs:

  • #CHANNEL#: The name of the currently viewed channel.
  • TIME: Replaces all available time formats using Emacs Lisp's format-time-string function.
 (require 'erc-history)
 (setq erc-history-sources
 '(("http://localhost/grc-history/#CHANNEL#/%Y/%m/%d.txt"
 ("#erc-history" "#erc-history-1"))))

Most of the time, the available logs will need to be parsed. In such cases, you can provide a parser function for each source. If no parser function is provided, a default one will be used, though it may not work properly.

The 3rd element in the source list is the function that parses log messages. The parser will receive a line from the chat logs and is expected to return a list of three variables: (MSG_TIME SENDER_NICK MSG_CONTENT). Ensure that the time format is in Emacs Lisp's time format. Use encode-time when needed, and convert the timezone as necessary. The default parser is erc-history-common-message-parser.

 (defun erc-history-myhost-message-parser (msg)
 "Display MSG in its erc buffer named CHANNEL.
MSG must match the format described for erc messages.
example: 2024年06月10日 08:00:01 - ByteMaster: Good morning, team!"
 (let ((regex "\\([0-9-]+ [0-9:]+\\) - \\([^:]+\\): \\(.*\\)"))
 (when (string-match regex msg)
 (let* ((time (match-string 1 msg))
 (nick (match-string 2 msg))
 (content (match-string 3 msg))
 (full-date (format-time-string
 (concat (string-replace " " "T" time) "+0000")
 erc-history-last-pulled-date)))
 (list (encode-time (parse-time-string full-date))
 nick
 content)))))
 (setq erc-history-sources
 '(("http://myhost/grc-history/#CHANNEL#/%Y/%m/%d.txt"
 ("#erc-history" "#erc-history-1")
 erc-history-myhost-message-parser)))

Example: Configuring Ubuntu Archives

Since all of Ubuntu's IRC chats are archived, they can be easily accessed using erc-history.

(defun erc-history-ubuntu-message-parser (msg)
 "Parse a chat log MSG and return a list of (time nickname message).
example: [23:22] <Bashing-om> UWN: Opening 842 for Saturday."
 (let ((regex "\\[\\([0-9:]+\\)\\] <\\([^>]+\\)> \\(.*\\)"))
 (when (string-match regex msg)
 (let* ((time (match-string 1 msg))
 (nick (match-string 2 msg))
 (content (match-string 3 msg))
 (full-date (format-time-string
 (concat "%Y-%m-%dT" time ":00+0000")
 erc-history-last-pulled-date)))
 (list (encode-time (parse-time-string full-date))
 nick
 content)))))
 (setq erc-history-sources
 ;; my personal logs
 '(("http://myhost/grc-history/#CHANNEL#/%Y/%m/%d.txt"
 ("#erc-history-1" "#erc-history"))
 ;; ubuntu logs
 ("https://irclogs.ubuntu.com/%Y/%m/%d/#CHANNEL#.txt"
 ("#cloud-init" "#kubuntu-devel" "#kubuntu"
 "#launchpad-dev" "#launchpad" "#lubuntu-devel"
 "#lubuntu" "#maas" "#mir-server" "#netplan"
 "#snappy" "#ubports" "#ubuntu-au" "#ubuntu-bd"
 "#ubuntu-bugs" "#ubuntu-community-team" "#ubuntu-de"
 "#ubuntu-desktop" "#ubuntu-devel" "#ubuntu-discuss"
 "#ubuntu-doc" "#ubuntu-es" "#ubuntu-hr" "#ubuntu-ir"
 "#ubuntu-irc" "#ubuntu-it" "#ubuntu-kernel" "#ubuntu-kr"
 "#ubuntu-lt" "#ubuntu-mate" "#ubuntu-meeting" "#ubuntu-mirrors"
 "#ubuntu-news" "#ubuntu-next" "#ubuntu-nl" "#ubuntu-on-air"
 "#ubuntu-ops" "#ubuntu-pl" "#ubuntu-qt" "#ubuntu-quality"
 "#ubuntu-release" "#ubuntu-ru" "#ubuntu-sa" "#ubuntu-security"
 "#ubuntu-server" "#ubuntu-tw" "#ubuntu-uk" "#ubuntu-us-mi"
 "#ubuntu-us-oh" "#ubuntu-us-pa" "#ubuntu" "#ubuntustudio-devel"
 "#ubuntustudio" "#xubuntu-devel" "#xubuntu")
 erc-history-ubuntu-message-parser)))

The configured channels' logs will automatically be retrieved when you navigate to the beginning of their buffers.

Note: Make sure you enable erc-history-mode.

use-package Configuration

For modern emacs, you can use use-package to install and configure erc-history quickly. It's highly recommended to start this package with the snippet below, it will immediately allow you to use any of the channels in erc-history-sources. You can start by joining ubuntu-desktop for example and start scrolling upward via mouse or keybindings and you will see previous messages getting pulled.

 (use-package erc-history
 :after erc
 :ensure t
 :vc (:url "https://github.com/ebeem/erc-history")
 :hook (erc-mode . erc-history-mode)
 :init
 (defun erc-history-ubuntu-message-parser (msg)
 "Parse a chat log MSG and return a list of (time nickname message).
 example: [23:22] <Bashing-om> UWN: Opening 842 for Saturday."
 (let ((regex "\\[\\([0-9:]+\\)\\] <\\([^>]+\\)> \\(.*\\)"))
 (when (string-match regex msg)
 (let* ((time (match-string 1 msg))
 (nick (match-string 2 msg))
 (content (match-string 3 msg))
 (full-date (format-time-string
 (concat "%Y-%m-%dT" time ":00+0000")
 erc-history-last-pulled-date)))
 (list (encode-time (parse-time-string full-date))
 nick
 content)))))
 (setq erc-history-sources
 ;; my personal logs
 '(;; ubuntu logs
 ("https://irclogs.ubuntu.com/%Y/%m/%d/#CHANNEL#.txt"
 ("#cloud-init" "#kubuntu-devel" "#kubuntu"
 "#launchpad-dev" "#launchpad" "#lubuntu-devel"
 "#lubuntu" "#maas" "#mir-server" "#netplan"
 "#snappy" "#ubports" "#ubuntu-au" "#ubuntu-bd"
 "#ubuntu-bugs" "#ubuntu-community-team" "#ubuntu-de"
 "#ubuntu-desktop" "#ubuntu-devel" "#ubuntu-discuss"
 "#ubuntu-doc" "#ubuntu-es" "#ubuntu-hr" "#ubuntu-ir"
 "#ubuntu-irc" "#ubuntu-it" "#ubuntu-kernel" "#ubuntu-kr"
 "#ubuntu-lt" "#ubuntu-mate" "#ubuntu-meeting" "#ubuntu-mirrors"
 "#ubuntu-news" "#ubuntu-next" "#ubuntu-nl" "#ubuntu-on-air"
 "#ubuntu-ops" "#ubuntu-pl" "#ubuntu-qt" "#ubuntu-quality"
 "#ubuntu-release" "#ubuntu-ru" "#ubuntu-sa" "#ubuntu-security"
 "#ubuntu-server" "#ubuntu-tw" "#ubuntu-uk" "#ubuntu-us-mi"
 "#ubuntu-us-oh" "#ubuntu-us-pa" "#ubuntu" "#ubuntustudio-devel"
 "#ubuntustudio" "#xubuntu-devel" "#xubuntu")
 erc-history-ubuntu-message-parser))))

Preview

/ebeem/erc-history/media/branch/master/preview.gif