summaryrefslogtreecommitdiff
path: root/lisp/init-ace.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/init-ace.el')
-rw-r--r--lisp/init-ace.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/lisp/init-ace.el b/lisp/init-ace.el
index d033e52..9ec2727 100644
--- a/lisp/init-ace.el
+++ b/lisp/init-ace.el
@@ -36,6 +36,40 @@
(push it points)))
(nreverse points))))
+(defun km/ace-link-widget ()
+ "Press a widget that is visible in the current buffer.
+This can be used in place of `ace-link-gnus' and has the
+advantage of working for gwene buffers in addition to normal mail
+buffers working to normal mail buffers because it doesn't rely on
+the 'gnus-string' text property."
+ (interactive)
+ (when (eq major-mode 'gnus-summary-mode)
+ (gnus-summary-widget-forward 1))
+ (let ((res (avy--with-avy-keys km/ace-link-widget
+ (avy--process
+ (km/ali--widget-collect-references)
+ #'avy--overlay-post))))
+ (when res
+ (goto-char (1+ res))
+ (widget-button-press (point)))))
+
+(defun km/ali--widget-collect-references ()
+ "Collect the positions of visible widgets in 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 (ignore-errors (widget-forward 1))
+ (> (point) pt))
+ (setq pt (point))
+ (push (point) candidates))
+ (nreverse candidates)))))
+
(ace-link-setup-default)
(after 'org
(define-key org-mode-map (kbd "C-c m o") 'ace-link-org))