From c29f6653150081aafa1ddcb7d6518cccb464b7c2 Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 20 May 2021 06:13:31 +0100 Subject: eww/w3m consult narrowing refactored --- completion.org | 66 +++++++++------------------------------------------------- 1 file changed, 10 insertions(+), 56 deletions(-) (limited to 'completion.org') diff --git a/completion.org b/completion.org index 5c1a050..741bb26 100644 --- a/completion.org +++ b/completion.org @@ -175,66 +175,20 @@ #+end_src *** narrow helpers #+begin_src emacs-lisp - (defvar jao-consult-www-narrow nil) + (defvar jao-consult-narrow nil) (defun jao-consult-initial-narrow () - (when (and jao-consult-www-narrow - (eq this-command #'consult-buffer) - (string-equal "Web" (jao-afio-current-frame))) + (when (eq this-command #'consult-buffer) + (when-let (c (cdr (assoc (jao-afio-current-frame) jao-consult-narrow))) (setq unread-command-events - (append unread-command-events `(,jao-consult-www-narrow 32))))) + (append unread-command-events `(,c 32)))))) + (add-hook 'minibuffer-setup-hook #'jao-consult-initial-narrow) - #+end_src -*** narrowing eww buffers - #+begin_src emacs-lisp - (with-eval-after-load "jao-eww-session" - (defvar jao-eww-consult-history nil) - (defvar jao-eww-buffer-source - (list :name "eww buffer" - :category 'eww-buffer - :hidden t - :narrow (cons ?e "eww") - :annotate (lambda (c) (get-text-property 0 'url c)) - :history 'jao-eww-consult-history - :action (lambda (b) - (jao-afio--goto-www) - (switch-to-buffer (get-text-property 0 'buffer b))) - :items - (lambda () - (seq-map (lambda (b) - (with-current-buffer b - (let ((tl (or (jao-eww-buffer-title) "")) - (url (or (jao-eww--current-url) ""))) - (propertize (if (string-blank-p tl) url tl) - 'buffer b 'url url)))) - (jao-eww-session--list-buffers))))) - - (add-to-list 'consult-buffer-sources 'jao-eww-buffer-source t) - (unless jao-afio-use-w3m (setq jao-consult-www-narrow ?e))) - #+end_src -*** narrowing w3m buffers - #+begin_src emacs-lisp - (with-eval-after-load "w3m" - (defvar jao-consult-w3m-buffer-history nil) - (setq jao-consult-w3m-source - (list :name "w3m buffer" - :category 'w3m-buffer - :hidden t - :narrow (cons ?w "w3m") - :annotate (lambda (b) (get-text-property 0 'url b)) - :history 'jao-consult-w3m-buffer-history - :action (lambda (b) - (jao-afio--goto-www) - (switch-to-buffer (get-text-property 0 'buffer b))) - :items (lambda () - (seq-map (lambda (b) - (with-current-buffer b - (propertize w3m-current-title - 'buffer b - 'url w3m-current-url))) - (w3m-list-buffers))))) - (when jao-afio-use-w3m (setq jao-consult-www-narrow ?w)) - (add-to-list 'consult-buffer-sources 'jao-consult-w3m-source t)) + + (defun jao-consult-add-buffer-source (src &optional aframe key) + (add-to-list 'consult-buffer-sources src t) + (when (and aframe key) + (add-to-list 'jao-consult-narrow (cons aframe key)))) #+end_src * embark *** packages -- cgit v1.2.3