Start configuring browse-url, eww, and webjump

This commit is contained in:
Gerard Vermeulen 2022-03-21 07:52:06 +01:00
parent 693966082a
commit e3097abadf

View File

@ -3209,6 +3209,81 @@ and names in buffers for debugging.
:CUSTOM_ID: sec:hyperlinking-web-navigating
:END:
*** [[info:emacs#Browse-URL][Browse URL (info)]]
:PROPERTIES:
:CUSTOM_ID: sec:browse-url
:END:
Listing [[lst:configure-browse-url]] configures =browse-url=.
#+caption[Configure =browse-url=]:
#+caption: Configure =browse-url=.
#+name: lst:configure-browse-url
#+begin_src emacs-lisp
(with-eval-after-load 'browse-url
(defun browse-url-mpv (url &optional _)
(start-process "mpv" nil "mpv" url))
(custom-set-variables
'(browse-url-browser-function
'(("https:\\/\\/www\\.youtu\\.*be." . browse-url-mpv)
("https://soundcloud.com" . browse-url-mpv)
("." . eww-browse-url)))
`(browse-url-generic-program ,(or (when (eq system-type 'darwin) "open")
(executable-find "firefox")))))
#+end_src
*** [[https://en.wikipedia.org/wiki/Eww_(web_browser)][Emacs Web Wowser]]
:PROPERTIES:
:CUSTOM_ID: sec:emacs-web-wowser
:END:
#+caption[Configure =eww= URLs]:
#+caption: Configure =eww= URLs.
#+name: lst:configure-eww-urls
#+begin_src emacs-lisp
(when (fboundp 'eww-browse-url)
(defmacro defun-dictionary (name where how)
`(defun ,name (word)
,(format "Look up WORD at '%s' in Emacs." where)
(interactive
(list (if (use-region-p)
(buffer-substring (region-beginning) (region-end))
(read-string ,(format "Search '%s' for: " where)
(thing-at-point 'word)))))
(eww-browse-url (concat ,(format "%s%s" where how) word))))
(defun-dictionary eww-dict-en "www.thefreedictionary.com" "/")
(defun-dictionary eww-dict-fr "www.cntrl.fr" "/definition/")
(defun-dictionary eww-dict-nl "www.woorden.org" "/woord/")
(defun-dictionary eww-webster "webster-dictionary.org" "/definition/")
(defun eww-subreddit ()
"Read a subreddit in Emacs."
(interactive)
(eww-browse-url (format "www.reddit.com/r/%s/.mobile"
(completing-read "subreddit: "
'("emacs"
"i3wm"
"orgmode")
nil t)))))
#+end_src
#+caption[Configure =eww= rendering]:
#+caption: Configure =eww= rendering.
#+name: lst:configure-eww-rendering
#+begin_src emacs-lisp
(with-eval-after-load 'eww
(defun eww-rename-buffer ()
"Rename the buffer using title or url."
(let* ((title (plist-get eww-data :title))
(name (or (and (eq "" title) (plist-get eww-data :url)) title)))
(rename-buffer (format "*%s # eww*" name) t)))
(add-hook 'eww-after-render-hook #'eww-rename-buffer)
(advice-add 'eww-back-url :after #'eww-rename-buffer)
(advice-add 'eww-forward-url :after #'eww-rename-buffer))
#+end_src
*** [[info:emacs#Goto Address mode][Goto address mode (info)]]
:PROPERTIES:
:CUSTOM_ID: sec:goto-address-mode
@ -3264,6 +3339,42 @@ files.
application/pdf; emacsclient %s
#+end_src
*** [[https://www.emacswiki.org/emacs/WebJump][Webjump]]
:PROPERTIES:
:CUSTOM_ID: sec:webjump
:END:
Listing [[lst:configure-webjump]] binds {{{kbd(C-c j)}}} to =webjump= and
initializes a list of =webjump-sites=.
#+caption[Configure =webjump=]:
#+caption: Configure =webjump=.
#+name: lst:configure-webjump
#+begin_src emacs-lisp
(when (fboundp 'webjump)
(global-set-key (kbd "C-c j") 'webjump)
(with-eval-after-load 'webjump
(custom-set-variables
'(webjump-sites
'(("Emacs Git Repositories" . "savannah.gnu.org/git/?group=emacs")
("Org Mode List" . "list.orgmode.org")
("Planet Emacs Life" . "planet.emacslife.com")
("Asian Pacific Journal Japan Focus" "apjjf.org")
("Counterpunch" . "www.counterpunch.org")
("Dictionary EN" . [simple-query "thefreedictionary.com"
"thefreedictionary.com/" ""])
("Dictionary FR" . [simple-query "www.cntrl.fr"
"www.cntrl.fr/definition/" ""])
("Dictionary NL" . [simple-query "www.woorden.org"
"www.woorden.org/woord/" ""])
("Dictionary Webster" . [simple-query
"www.webster-dictionary.org"
"www.webster-dictionary.org/definition/" ""])
("NRC". "www.nrc.nl")
("Trouw" . "www.trouw.nl")
("Volkskrant" . "www.volkskrant.nl"))))))
#+end_src
** [[https://github.com/skeeto/elfeed#readme][Elfeed: Emacs web feed reader]]
:PROPERTIES:
:CUSTOM_ID: sec:emacs-web-feed-reader