]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Add esy/eww, a competing-read wrapper for eww
authorEshel Yaron <eshel@areionsec.com>
Sun, 8 May 2022 09:00:21 +0000 (12:00 +0300)
committerEshel Yaron <eshel@areionsec.com>
Sun, 8 May 2022 09:00:21 +0000 (12:00 +0300)
.emacs.d/esy.org

index 4ed665b694da71c2649f6cf8aa4829ec8eaa705a..cbd04e8f1ec5191e250d1718d68421fb529192b6 100644 (file)
@@ -658,7 +658,6 @@ For further information about Elisp headers, see [[info:elisp#Library
     "Configure Gnus specific customizations."
     (require 'gnus)
     (require 'gnus-icalendar)
-    (require 'shr)
     (require 'ace-link)
     (setq 
           gnus-article-treat-types '("text/plain"
@@ -672,7 +671,6 @@ For further information about Elisp headers, see [[info:elisp#Library
                                  (address ,esy/user-mail-address-gmail)))
           gnus-icalendar-org-capture-file esy/inbox-path
           gnus-icalendar-org-capture-headline '("Calendar")
-          shr-use-colors nil
           calendar-date-style 'iso)
     (gnus-icalendar-setup)
     (gnus-icalendar-org-setup)
@@ -762,7 +760,7 @@ For further information about Elisp headers, see [[info:elisp#Library
     (keymap-set ctl-x-map "s" rg-global-map)
     (keymap-set ctl-x-map "c" #'org-capture)
     (keymap-set ctl-x-map "o" #'ace-window)
-    (keymap-set ctl-x-map "w" #'browse-web)
+    (keymap-set ctl-x-map "w" #'esy/eww)
     (keymap-set ctl-x-map "j" #'org-agenda))
 
   (add-hook 'after-init-hook #'esy/customize-ctl-x-map)
@@ -825,7 +823,7 @@ For further information about Elisp headers, see [[info:elisp#Library
             "https://planet.emacslife.com/atom.xml")))
 #+end_src
 
-** eww
+** eww                                                                 :www:
 :PROPERTIES:
 :CUSTOM_ID: eww
 :END:
@@ -834,6 +832,39 @@ For further information about Elisp headers, see [[info:elisp#Library
   (with-eval-after-load 'eww
     (setq eww-auto-rename-buffer 'title
           browse-url-browser-function #'eww-browse-url))
+
+  (with-eval-after-load 'shr
+    (setq shr-use-colors nil))
+#+end_src
+
+*** Prompt for URL with history-based completion
+:PROPERTIES:
+:CUSTOM_ID: eww-completing-read-url
+:CreatedAt: <2022-05-08 Sun>
+:CapturedAt: [[file:~/checkouts/protfiles/emacs/.emacs.d/prot-lisp/prot-eww.el::defun prot-eww-browse-dwim]]
+:CapturedAs: Emacs configuration fragment
+:END:
+
+The =eww= command in the heart of =eww.el= prompts the user for a URL,
+and browses it (see [[info:eww#Basics][eww#Basics]] for more details). One shortcoming of
+the built-in =eww= command is that it uses the =read-string= function
+to read the requested URL, which does not facilitate completions.
+
+The following fragment, inspired by [[https://protesilaos.com/emacs/dotemacs#h:524bc702-ff55-4ed9-9a38-26d30d64591d][Protesilaos Stavrou's prot-eww.el]],
+provides a simple wrapper for =eww= that uses =completing-read=
+instead of =read-string=, allowing for quick input completion based on
+the prior submitted URLs and web search keywords.
+
+#+begin_src emacs-lisp
+  (defun esy/eww ()
+    "URL ARG."
+    (interactive)
+    (require 'eww)
+    (eww (completing-read "Browse or search: "
+                          eww-prompt-history
+                          nil nil nil
+                          'eww-prompt-history
+                          (car (eww-suggested-uris)))))
 #+end_src
 
 ** Proced