xwwp-follow-link-helm.el 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "0.1"))
  8. ;; Copyright (C) 2020 Q. Hong <qhong@mit.edu>, 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. (result (seq-map #'cdr candidates)))
  36. (cons selection result)))
  37. (cl-defmethod xwwp-follow-link-read ((backend xwwp-follow-link-completion-backend-helm) prompt collection action update-fn)
  38. (add-hook 'helm-after-initialize-hook (lambda ()
  39. (with-current-buffer "*helm-xwwp*"
  40. (add-hook 'helm-move-selection-after-hook update-fn nil t)))
  41. nil t)
  42. (or (helm :sources
  43. (helm-make-source "Xwidget Plus" 'helm-source-sync
  44. :candidates collection
  45. :action action
  46. :filtered-candidate-transformer (lambda (candidates _)
  47. (oset backend candidates candidates)
  48. (funcall update-fn)
  49. candidates))
  50. :prompt prompt
  51. :buffer "*helm-xwwp*") (signal 'quit nil)))
  52. (provide 'xwwp-follow-link-helm)
  53. ;;; xwwp-follow-link-helm.el ends here