|
@@ -138,68 +138,92 @@ browser."
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Ido backend using ido-completing-read
|
|
;; Ido backend using ido-completing-read
|
|
|
-(defclass xwidget-plus-completion-backend-ido (xwidget-plus-completion-backend) ())
|
|
|
|
|
|
|
+(with-eval-after-load 'ido
|
|
|
|
|
+ (defclass xwidget-plus-completion-backend-ido (xwidget-plus-completion-backend) ())
|
|
|
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-candidates ((backend xwidget-plus-completion-backend-ido))
|
|
|
|
|
- (let ((collection (oref backend collection)))
|
|
|
|
|
- (when collection
|
|
|
|
|
- (seq-map (lambda (i) (cdr (assoc i collection))) ido-matches))))
|
|
|
|
|
|
|
+ (cl-defmethod xwidget-plus-follow-link-candidates ((backend xwidget-plus-completion-backend-ido))
|
|
|
|
|
+ (let ((collection (oref backend collection)))
|
|
|
|
|
+ (when collection
|
|
|
|
|
+ (seq-map (lambda (i) (cdr (assoc i collection))) ido-matches))))
|
|
|
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-read ((backend xwidget-plus-completion-backend-ido) prompt collection action update-fn)
|
|
|
|
|
- (let ((choices (seq-map #'car collection)))
|
|
|
|
|
- (advice-add #'ido-set-matches :after update-fn)
|
|
|
|
|
- (let ((link (cdr (assoc (ido-completing-read prompt choices nil t) collection))))
|
|
|
|
|
- (oset backend collection nil)
|
|
|
|
|
- (advice-remove #'ido-set-matches #'update-fn)
|
|
|
|
|
- (funcall action link))))
|
|
|
|
|
|
|
+ (cl-defmethod xwidget-plus-follow-link-read ((backend xwidget-plus-completion-backend-ido) prompt collection action update-fn)
|
|
|
|
|
+ (let ((choices (seq-map #'car collection)))
|
|
|
|
|
+ (advice-add #'ido-set-matches :after update-fn)
|
|
|
|
|
+ (let ((link (cdr (assoc (ido-completing-read prompt choices nil t) collection))))
|
|
|
|
|
+ (oset backend collection nil)
|
|
|
|
|
+ (advice-remove #'ido-set-matches #'update-fn)
|
|
|
|
|
+ (funcall action link)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Ivy backend using completing read
|
|
;; Ivy backend using completing read
|
|
|
-(defclass xwidget-plus-completion-backend-ivy (xwidget-plus-completion-backend) ())
|
|
|
|
|
|
|
+(with-eval-after-load 'ivy
|
|
|
|
|
+ (defclass xwidget-plus-completion-backend-ivy (xwidget-plus-completion-backend) ())
|
|
|
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-candidates ((backend xwidget-plus-completion-backend-ivy))
|
|
|
|
|
- (with-current-buffer (ivy-state-buffer ivy-last)
|
|
|
|
|
- (let* ((collection (ivy-state-collection ivy-last))
|
|
|
|
|
- (current (ivy-state-current ivy-last))
|
|
|
|
|
- (candidates (ivy--filter ivy-text ivy--all-candidates))
|
|
|
|
|
- (result (cons current candidates)))
|
|
|
|
|
- (seq-map (lambda (c) (cdr (nth (get-text-property 0 'idx c) collection))) result))))
|
|
|
|
|
|
|
+ (cl-defmethod xwidget-plus-follow-link-candidates ((backend xwidget-plus-completion-backend-ivy))
|
|
|
|
|
+ (with-current-buffer (ivy-state-buffer ivy-last)
|
|
|
|
|
+ (let* ((collection (ivy-state-collection ivy-last))
|
|
|
|
|
+ (current (ivy-state-current ivy-last))
|
|
|
|
|
+ (candidates (ivy--filter ivy-text ivy--all-candidates))
|
|
|
|
|
+ (result (cons current candidates)))
|
|
|
|
|
+ (seq-map (lambda (c) (cdr (nth (get-text-property 0 'idx c) collection))) result))))
|
|
|
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-read ((backend xwidget-plus-completion-backend-ivy) prompt collection action update-fn)
|
|
|
|
|
- (ivy-read "Link: " collection :require-match t :action (lambda (v) (funcall action (cdr v))) :update-fn update-fn))
|
|
|
|
|
|
|
+ (cl-defmethod xwidget-plus-follow-link-read ((backend xwidget-plus-completion-backend-ivy) prompt collection action update-fn)
|
|
|
|
|
+ (ivy-read "Link: " collection :require-match t :action (lambda (v) (funcall action (cdr v))) :update-fn update-fn)))
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Helm backend
|
|
;; Helm backend
|
|
|
-(defclass xwidget-plus-completion-backend-helm (xwidget-plus-completion-backend) ((candidates)))
|
|
|
|
|
-
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-candidates ((backend xwidget-plus-completion-backend-helm))
|
|
|
|
|
- (let* ((candidates (oref backend candidates))
|
|
|
|
|
- (selection (helm-get-selection))
|
|
|
|
|
- (selected (when selection (cdr (elt (oref backend collection) selection))))
|
|
|
|
|
- (result (seq-map #'cdr candidates)))
|
|
|
|
|
- (cons selected result)))
|
|
|
|
|
-
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-read ((backend xwidget-plus-completion-backend-helm) prompt collection action update-fn)
|
|
|
|
|
- (add-hook 'helm-after-initialize-hook (lambda ()
|
|
|
|
|
- (with-current-buffer "*helm-xwidget-plus*"
|
|
|
|
|
- (add-hook 'helm-move-selection-after-hook update-fn nil t)))
|
|
|
|
|
- nil t)
|
|
|
|
|
- (helm :sources
|
|
|
|
|
- (helm-make-source "Xwidget Plus" 'helm-source-sync
|
|
|
|
|
- :candidates collection
|
|
|
|
|
- :action action
|
|
|
|
|
- :filtered-candidate-transformer (lambda (candidates _)
|
|
|
|
|
- (oset backend candidates candidates)
|
|
|
|
|
- (funcall update-fn)
|
|
|
|
|
- candidates))
|
|
|
|
|
- :prompt prompt
|
|
|
|
|
- :buffer "*helm-xwidget-plus*"))
|
|
|
|
|
-
|
|
|
|
|
-(defvar xwidget-plus-completion-backend-instance (xwidget-plus-completion-backend-ivy))
|
|
|
|
|
|
|
+(with-eval-after-load 'helm
|
|
|
|
|
+ (defclass xwidget-plus-completion-backend-helm (xwidget-plus-completion-backend) ((candidates)))
|
|
|
|
|
+
|
|
|
|
|
+ (cl-defmethod xwidget-plus-follow-link-candidates ((backend xwidget-plus-completion-backend-helm))
|
|
|
|
|
+ (let* ((candidates (oref backend candidates))
|
|
|
|
|
+ (selection (helm-get-selection))
|
|
|
|
|
+ (selected (when selection (cdr (elt (oref backend collection) selection))))
|
|
|
|
|
+ (result (seq-map #'cdr candidates)))
|
|
|
|
|
+ (cons selected result)))
|
|
|
|
|
+
|
|
|
|
|
+ (cl-defmethod xwidget-plus-follow-link-read ((backend xwidget-plus-completion-backend-helm) prompt collection action update-fn)
|
|
|
|
|
+ (add-hook 'helm-after-initialize-hook (lambda ()
|
|
|
|
|
+ (with-current-buffer "*helm-xwidget-plus*"
|
|
|
|
|
+ (add-hook 'helm-move-selection-after-hook update-fn nil t)))
|
|
|
|
|
+ nil t)
|
|
|
|
|
+ (helm :sources
|
|
|
|
|
+ (helm-make-source "Xwidget Plus" 'helm-source-sync
|
|
|
|
|
+ :candidates collection
|
|
|
|
|
+ :action action
|
|
|
|
|
+ :filtered-candidate-transformer (lambda (candidates _)
|
|
|
|
|
+ (oset backend candidates candidates)
|
|
|
|
|
+ (funcall update-fn)
|
|
|
|
|
+ candidates))
|
|
|
|
|
+ :prompt prompt
|
|
|
|
|
+ :buffer "*helm-xwidget-plus*")))
|
|
|
|
|
+
|
|
|
|
|
+(defun xwidget-plus-follow-link-make-backend ()
|
|
|
|
|
+ "Instanciate a completion backend."
|
|
|
|
|
+ (cond ((eq xwidget-plus-completion-system 'default)
|
|
|
|
|
+ (cond ((featurep 'ivy)
|
|
|
|
|
+ #'xwidget-plus-completion-backend-ivy)
|
|
|
|
|
+ ((featurep 'helm)
|
|
|
|
|
+ #'xwidget-plus-completion-backend-helm)
|
|
|
|
|
+ ((featurep 'ido)
|
|
|
|
|
+ #'xwidget-plus-completion-backend-ido)
|
|
|
|
|
+ (t #'xwidget-plus-completion-backend-default)))
|
|
|
|
|
+ ((eq xwidget-plus-completion-system 'ivy)
|
|
|
|
|
+ #'xwidget-plus-completion-backend-ivy)
|
|
|
|
|
+ ((eq xwidget-plus-completion-system 'helm)
|
|
|
|
|
+ #'xwidget-plus-completion-backend-helm)
|
|
|
|
|
+ ((eq xwidget-plus-completion-system 'ido)
|
|
|
|
|
+ #'xwidget-plus-completion-backend-ido)
|
|
|
|
|
+ ((eq xwidget-plus-completion-system 'default)
|
|
|
|
|
+ #'xwidget-plus-completion-backend-default)
|
|
|
|
|
+ (t xwidget-plus-completion-system)))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+(defvar xwidget-plus-follow-link-completion-backend-instance '())
|
|
|
|
|
|
|
|
(defun xwidget-plus-follow-link-update (xwidget)
|
|
(defun xwidget-plus-follow-link-update (xwidget)
|
|
|
"Highligh LINKS in XWIDGET buffer when updating candidates."
|
|
"Highligh LINKS in XWIDGET buffer when updating candidates."
|
|
|
- (let ((links (xwidget-plus-follow-link-candidates xwidget-plus-completion-backend-instance)))
|
|
|
|
|
|
|
+ (let ((links (xwidget-plus-follow-link-candidates xwidget-plus-follow-link-completion-backend-instance)))
|
|
|
(when links
|
|
(when links
|
|
|
(let* ((selected (car links))
|
|
(let* ((selected (car links))
|
|
|
(candidates (cdr links)))
|
|
(candidates (cdr links)))
|
|
@@ -227,20 +251,21 @@ browser."
|
|
|
(let* ((xwidget (xwidget-webkit-current-session))
|
|
(let* ((xwidget (xwidget-webkit-current-session))
|
|
|
(links (xwidget-plus-follow-link-prepare-links links))
|
|
(links (xwidget-plus-follow-link-prepare-links links))
|
|
|
link)
|
|
link)
|
|
|
- (oset xwidget-plus-completion-backend-instance collection links)
|
|
|
|
|
|
|
+ (oset xwidget-plus-follow-link-completion-backend-instance collection links)
|
|
|
(unwind-protect
|
|
(unwind-protect
|
|
|
(condition-case nil
|
|
(condition-case nil
|
|
|
- (xwidget-plus-follow-link-read xwidget-plus-completion-backend-instance
|
|
|
|
|
|
|
+ (xwidget-plus-follow-link-read xwidget-plus-follow-link-completion-backend-instance
|
|
|
"Link: " links
|
|
"Link: " links
|
|
|
(apply-partially #'xwidget-plus-follow-link-trigger-action xwidget)
|
|
(apply-partially #'xwidget-plus-follow-link-trigger-action xwidget)
|
|
|
(apply-partially #'xwidget-plus-follow-link-update xwidget))
|
|
(apply-partially #'xwidget-plus-follow-link-update xwidget))
|
|
|
(quit (xwidget-plus-follow-link-cleanupxwidget))))
|
|
(quit (xwidget-plus-follow-link-cleanupxwidget))))
|
|
|
- (oset xwidget-plus-completion-backend-instance collection nil)))
|
|
|
|
|
|
|
+ (oset xwidget-plus-follow-link-completion-backend-instance collection nil)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
;;;###autoload
|
|
|
(defun xwidget-plus-follow-link (&optional xwidget)
|
|
(defun xwidget-plus-follow-link (&optional xwidget)
|
|
|
"Ask for a link in the XWIDGET session or the current one and follow it."
|
|
"Ask for a link in the XWIDGET session or the current one and follow it."
|
|
|
(interactive)
|
|
(interactive)
|
|
|
|
|
+ (setq xwidget-plus-follow-link-completion-backend-instance (funcall (xwidget-plus-follow-link-make-backend)))
|
|
|
(let ((xwidget (or xwidget (xwidget-webkit-current-session))))
|
|
(let ((xwidget (or xwidget (xwidget-webkit-current-session))))
|
|
|
(xwidget-plus-inject-style xwidget "__xwidget_plus_follow_link_style" (xwidget-plus-follow-link-style-definition))
|
|
(xwidget-plus-inject-style xwidget "__xwidget_plus_follow_link_style" (xwidget-plus-follow-link-style-definition))
|
|
|
(xwidget-plus-js-inject xwidget 'follow-link)
|
|
(xwidget-plus-js-inject xwidget 'follow-link)
|