From e7b5ce2f92d450860af2556ae1cc42b2ce12dd17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Mon, 24 Aug 2020 22:46:46 +0200 Subject: [PATCH 1/5] Change ace-link to work in Gnus summary buffer This completes the change in 7606a50 to fix #7. --- ace-link.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ace-link.el b/ace-link.el index a33a990..a3d8dac 100644 --- a/ace-link.el +++ b/ace-link.el @@ -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)) From 2f664aefeff2c3b8249b882fb7a8e52adf033a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Mon, 24 Aug 2020 22:52:27 +0200 Subject: [PATCH 2/5] Return to the summary buffer after selecting a link --- ace-link.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ace-link.el b/ace-link.el index a3d8dac..ee06027 100644 --- a/ace-link.el +++ b/ace-link.el @@ -413,13 +413,14 @@ If EXTERNAL is double prefix, browse in new buffer." (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) + (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)))) (defun ace-link--gnus-action (pt) (when (number-or-marker-p pt) From b06ee12adf96f2364eecd5630a6a09b311310a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Sat, 12 Sep 2020 09:48:05 +0200 Subject: [PATCH 3/5] Update ace-link-gnus for Emacs 27.1 --- ace-link.el | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/ace-link.el b/ace-link.el index ee06027..38f657c 100644 --- a/ace-link.el +++ b/ace-link.el @@ -425,30 +425,35 @@ If EXTERNAL is double prefix, browse in new buffer." (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) + (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)) + (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 () From 602b653aae8433375c607d3c97406d61efe23337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Sat, 12 Sep 2020 10:29:22 +0200 Subject: [PATCH 4/5] Use currently opened view of Gnus article buffer When `ace-link-gnus' is called from the summary buffer, use the currently opened article buffer instead of switching to the selected article (which might be different). Also, do not jump to the next button, as this might lead to unintended scrolling of the article buffer. --- ace-link.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ace-link.el b/ace-link.el index 38f657c..6efe2b0 100644 --- a/ace-link.el +++ b/ace-link.el @@ -415,7 +415,11 @@ If EXTERNAL is double prefix, browse in new buffer." (interactive) (save-selected-window (when (eq major-mode 'gnus-summary-mode) - (gnus-summary-widget-forward 1)) + (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) From 2580c8d4d6745e082f3d24cf7cc71e92aa949ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Wed, 6 Jan 2021 11:53:46 +0100 Subject: [PATCH 5/5] Fix byte-compile warnings --- ace-link.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ace-link.el b/ace-link.el index 6efe2b0..102550d 100644 --- a/ace-link.el +++ b/ace-link.el @@ -409,6 +409,13 @@ 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."