xwwp-follow-link-ido.el 2.1 KB

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