xwwp-follow-link-ido.el 1.9 KB

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