Skip to content

Commit

Permalink
Port hackernews--button-string to Emacs 28
Browse files Browse the repository at this point in the history
When its first argument is a string, make-text-button failed to
return it until Emacs 24.3, and no longer modifies it since Emacs
28[1], so a compatibility shim is necessary.

This was reported in the following emacs-devel thread:
https://lists.gnu.org/archive/html/emacs-devel/2020-06/msg00117.html

[1]: Don’t attempt to modify constant strings
313955110b 2020-05-16 22:25:07 -0700
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=313955110b242cd18fc19bd168032d3ddf39fe94
  • Loading branch information
basil-conto committed Jun 3, 2020
1 parent 2362d7b commit 79c05f7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions hackernews.el
Original file line number Diff line number Diff line change
Expand Up @@ -496,17 +496,30 @@ which see."
(interactive)
(hackernews--visit (point) #'ignore t))

(defalias 'hackernews--text-button
;; Emacs 24.4 was the first to return BEG when it's a string, so
;; earlier versions can't return the result of `make-text-button'.
;; Emacs 28.1 started modifying a copy of BEG when it's a string, so
;; subsequent versions must return the result of `make-text-button'.
(if (version< "24.3" emacs-version)
#'make-text-button
(lambda (beg end &rest properties)
(apply #'make-text-button beg end properties)
beg))
"Like `make-text-button', but always return BEG.
This is for compatibility with various Emacs versions.
\n(fn BEG END &rest PROPERTIES)")

(defun hackernews--button-string (type label url id)
"Make LABEL a text button of TYPE for item ID and URL."
(let* ((props (and hackernews-show-visited-links
(gethash id (cdr (assq type hackernews--visited-ids)))))
(face (button-type-get type (if (plist-get props :visited)
'hackernews-visited-face
'hackernews-face))))
(make-text-button label nil
'type type 'font-lock-face face
'id id 'help-echo url 'shr-url url))
label)
(hackernews--text-button label nil
'type type 'font-lock-face face
'id id 'help-echo url 'shr-url url)))

(defun hackernews--render-item (item)
"Render Hacker News ITEM in current buffer.
Expand Down

0 comments on commit 79c05f7

Please sign in to comment.