-
Notifications
You must be signed in to change notification settings - Fork 18
/
xwwp-follow-link-ido.el
49 lines (35 loc) · 1.88 KB
/
xwwp-follow-link-ido.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
;;; xwwp-follow-link-ido.el --- Link navigation in `xwidget-webkit' sessions using `ido' -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Damien Merenne <[email protected]>
;; This file is NOT part of GNU Emacs.
;;; License:
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Add support for navigating web pages in `xwidget-webkit' sessions using the
;; `ido' completion.
;;; Code:
(require 'xwwp-follow-link)
(require 'ido)
(defclass xwwp-follow-link-completion-backend-ido (xwwp-follow-link-completion-backend) ())
(cl-defmethod xwwp-follow-link-candidates ((backend xwwp-follow-link-completion-backend-ido))
(let ((collection (oref backend collection)))
(when collection
(seq-map (lambda (i) (cdr (assoc i collection))) ido-matches))))
(cl-defmethod xwwp-follow-link-read ((backend xwwp-follow-link-completion-backend-ido) prompt collection action update-fn)
(let ((choices (seq-map #'car collection)))
(advice-add #'ido-set-matches :after update-fn)
(let ((link (unwind-protect
(cdr (assoc (ido-completing-read prompt choices nil t) collection))
(oset backend collection nil)
(advice-remove #'ido-set-matches update-fn))))
(funcall action link))))
(provide 'xwwp-follow-link-ido)
;;; xwwp-follow-link-ido.el ends here