Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Gnus support and update for Emacs 27.1 #71

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 45 additions & 28 deletions ace-link.el
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
((or (member major-mode '(compilation-mode grep-mode))
(bound-and-true-p compilation-shell-minor-mode))
(ace-link-compilation))
((eq major-mode 'gnus-article-mode)
((memq major-mode '(gnus-article-mode gnus-summary-mode))
(ace-link-gnus))
((eq major-mode 'mu4e-view-mode)
(ace-link-mu4e))
Expand Down Expand Up @@ -409,45 +409,62 @@ If EXTERNAL is double prefix, browse in new buffer."
(declare-function compile-goto-error "compile")

;;* `ace-link-gnus'
(defvar gnus-article-buffer)
(defvar mm-text-html-renderer)
(declare-function gnus-article-press-button "gnus-art")
(declare-function gnus-get-buffer-window "gnus-win")
(declare-function widget-button-press "wid-edit")
(declare-function widget-forward "wid-edit")

;;;###autoload
(defun ace-link-gnus ()
"Open a visible link in a `gnus-article-mode' buffer."
(interactive)
(when (eq major-mode 'gnus-summary-mode)
(gnus-summary-widget-forward 1))
(let ((pt (avy-with ace-link-gnus
(avy-process
(ace-link--gnus-collect)
(avy--style-fn avy-style)))))
(ace-link--gnus-action pt)))
(save-selected-window
(when (eq major-mode 'gnus-summary-mode)
(if-let ((win (gnus-get-buffer-window gnus-article-buffer 'visible)))
(progn
(select-window win)
(select-frame-set-input-focus (window-frame win)))
(user-error "No article window found")))
(let ((pt (avy-with ace-link-gnus
(avy-process
(ace-link--gnus-collect)
(avy--style-fn avy-style)))))
(ace-link--gnus-action pt))))

(defun ace-link--gnus-action (pt)
(when (number-or-marker-p pt)
(goto-char (1+ pt))
(widget-button-press (point))))

(declare-function widget-forward "wid-edit")
(declare-function gnus-summary-widget-forward "gnus-sum")
(declare-function widget-button-press "wid-edit")
(cond ((< emacs-major-version 27)
(widget-button-press (point)))
((and (eq mm-text-html-renderer 'shr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could possibly already be required for Emacs 26.3 to open links in portions of the buffer rendered by shr.

(get-text-property (point) 'shr-url))
(shr-browse-url))
((get-text-property (point) 'gnus-callback)
(gnus-article-press-button))
(t (push-button)))))

(defun ace-link--gnus-collect ()
"Collect the positions of visible links in the current gnus buffer."
(require 'wid-edit)
(let (candidates pt)
(save-excursion
(save-restriction
(narrow-to-region
(window-start)
(window-end))
(goto-char (point-min))
(setq pt (point))
(while (progn (widget-forward 1)
(> (point) pt))
(if (<= 27 emacs-major-version)
(mapcar #'cdr (ace-link--woman-collect))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the "collect links in a buffer using button.el" functionality could be extracted and given a more general name.

(require 'wid-edit)
(let (candidates pt)
(save-excursion
(save-restriction
(narrow-to-region
(window-start)
(window-end))
(goto-char (point-min))
(setq pt (point))
(when (or (plist-get (text-properties-at (point)) 'gnus-string)
(plist-get (text-properties-at (point)) 'shr-url))
(push (point) candidates)))
(nreverse candidates)))))
(while (progn (widget-forward 1)
(> (point) pt))
(setq pt (point))
(when (or (plist-get (text-properties-at (point)) 'gnus-string)
(plist-get (text-properties-at (point)) 'shr-url))
(push (point) candidates)))
(nreverse candidates))))))

;;* Helper functions for `ace-link-mu4e' and `ace-link-notmuch'
(defun ace-link--email-view-plain-collect ()
Expand Down