From: F. Jason Park Date: Tue, 23 May 2023 04:43:29 +0000 (-0700) Subject: Add command to view ERC-NEWS X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8a149966dd50a801abe25e97d446ce363252cdf9;p=emacs.git Add command to view ERC-NEWS * etc/ERC-NEWS: Mention `erc-news' command. * lisp/erc/erc.el (erc--news-url, erc--news-temp-file, erc-news): Add new command and supporting variable. --- diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS index d257bdcbf51..5e5779cfcd5 100644 --- a/etc/ERC-NEWS +++ b/etc/ERC-NEWS @@ -136,9 +136,10 @@ Some minor quality-of-life niceties have finally made their way to ERC. For example, the function 'erc-echo-timestamp' is now interactive and can be invoked on any message to view its timestamp in the echo area. The command 'erc-button-previous' now moves to the -beginning instead of the end of buttons. And the 'irccontrols' module -now supports additional colors and special handling for "spoilers" -(hidden text). +beginning instead of the end of buttons. A new command, 'erc-news', +can now be invoked to visit this very file. And the 'irccontrols' +module now supports additional colors and special handling for +"spoilers" (hidden text). ** Changes in the library API. diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 0be9eb69432..aad6f7d9d54 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -7428,6 +7428,51 @@ If BUFFER is nil, update the mode line in all ERC buffers." (goto-char (point-min)) (insert "X-Debbugs-CC: emacs-erc@gnu.org\n"))) +(defconst erc--news-url + "https://git.savannah.gnu.org/cgit/emacs.git/plain/etc/ERC-NEWS") + +(defvar erc--news-temp-file nil) + +(defun erc-news (arg) + "Show ERC news in a manner similar to `view-emacs-news'. +With ARG, download and display the latest revision, which may +contain more up-to-date information, even for older versions." + (interactive "P") + (find-file + (or (and arg erc--news-temp-file + (time-less-p (current-time) (car erc--news-temp-file)) + (cdr erc--news-temp-file)) + (and arg + (with-current-buffer (url-retrieve-synchronously erc--news-url) + (goto-char (point-min)) + (search-forward "200 OK" (pos-eol)) + (search-forward "\n\n") + (delete-region (point-min) (point)) + (let ((tempfile (make-temp-file "erc-news."))) + (write-region (point-min) (point-max) tempfile) + (kill-buffer) + (cdr (setq erc--news-temp-file + (cons (time-add (current-time) (* 60 60 12)) + tempfile)))))) + (and-let* ((file (or (eval-when-compile (macroexp-file-name)) + (locate-library "erc"))) + (dir (file-name-directory file)) + (adjacent (expand-file-name "ERC-NEWS" dir)) + ((file-exists-p adjacent))) + adjacent) + (expand-file-name "ERC-NEWS" data-directory))) + (when (fboundp 'emacs-news-view-mode) + (emacs-news-view-mode)) + (let ((v (mapcar #'number-to-string + (seq-take-while #'natnump (version-to-list erc-version))))) + (while (and v + (goto-char (point-min)) + (not (search-forward (concat "\014\n* Changes in ERC " + (string-join v ".")) + nil t))) + (setq v (butlast v)))) + (beginning-of-line)) + (defun erc-port-to-string (p) "Convert port P to a string. P may be an integer or a service name."