xwwp-follow-link-helm.el 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ;;; xwwp-follow-link-helm.el --- Link navigation in `xwidget-webkit' sessions using `helm' -*- 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. ;; `helm' completion.
  24. ;;; Code:
  25. (require 'xwwp-follow-link)
  26. (require 'helm)
  27. ;; tell the compiler these do exists
  28. (declare-function helm "helm")
  29. (declare-function helm-get-selection "helm")
  30. (declare-function helm-make-source "helm-source")
  31. (defclass xwwp-follow-link-completion-backend-helm (xwwp-follow-link-completion-backend) ((candidates)))
  32. (cl-defmethod xwwp-follow-link-candidates ((backend xwwp-follow-link-completion-backend-helm))
  33. (let* ((candidates (oref backend candidates))
  34. (selection (helm-get-selection))
  35. (selected (when selection (cdr (elt (oref backend collection) selection))))
  36. (result (seq-map #'cdr candidates)))
  37. (cons selected result)))
  38. (cl-defmethod xwwp-follow-link-read ((backend xwwp-follow-link-completion-backend-helm) prompt collection action update-fn)
  39. (add-hook 'helm-after-initialize-hook (lambda ()
  40. (with-current-buffer "*helm-xwwp*"
  41. (add-hook 'helm-move-selection-after-hook update-fn nil t)))
  42. nil t)
  43. (helm :sources
  44. (helm-make-source "Xwidget Plus" 'helm-source-sync
  45. :candidates collection
  46. :action action
  47. :filtered-candidate-transformer (lambda (candidates _)
  48. (oset backend candidates candidates)
  49. (funcall update-fn)
  50. candidates))
  51. :prompt prompt
  52. :buffer "*helm-xwwp*"))
  53. (provide 'xwwp-follow-link-helm)
  54. ;;; xwwp-follow-link-helm.el ends here