xwwp-follow-link-ivy.el 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ;;; xwwp-follow-link-ivy.el --- Link navigation in `xwidget-webkit' sessions using `ivy' -*- 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. ;; `ivy' completion.
  24. ;;; Code:
  25. (require 'xwwp-follow-link)
  26. (require 'ivy)
  27. (defclass xwwp-follow-link-completion-backend-ivy (xwwp-follow-link-completion-backend) ())
  28. (cl-defmethod xwwp-follow-link-candidates ((_ xwwp-follow-link-completion-backend-ivy))
  29. (with-current-buffer (ivy-state-buffer ivy-last)
  30. (let* ((collection (ivy-state-collection ivy-last))
  31. (current (ivy-state-current ivy-last))
  32. (candidates (ivy--filter ivy-text ivy--all-candidates))
  33. (result (cons current candidates)))
  34. (seq-map (lambda (c) (cdr (nth (get-text-property 0 'idx c) collection))) result))))
  35. (cl-defmethod xwwp-follow-link-read ((_ xwwp-follow-link-completion-backend-ivy) prompt collection action update-fn)
  36. (ivy-read prompt collection :require-match t :action (lambda (v) (funcall action (cdr v))) :update-fn update-fn))
  37. (provide 'xwwp-follow-link-ivy)
  38. ;;; xwwp-follow-link-ivy.el ends here