summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-04-06 03:52:08 +0100
committerjao <jao@gnu.org>2021-04-06 03:52:08 +0100
commit717d2a67c455237252852c88b31dd6c445e79b8e (patch)
treeea80c341de0964f6d96cab32df770842a61b581a
parentcfdb657c9496bc912860d5cb8a8fec5f3a8f8419 (diff)
downloadelibs-717d2a67c455237252852c88b31dd6c445e79b8e.tar.gz
elibs-717d2a67c455237252852c88b31dd6c445e79b8e.tar.bz2
w3m.org
-rw-r--r--attic/w3m.org344
-rw-r--r--eww.org17
-rw-r--r--gnus.org48
-rw-r--r--init.org3
-rw-r--r--org.org7
-rw-r--r--readme.org7
-rw-r--r--w3m.org150
7 files changed, 169 insertions, 407 deletions
diff --git a/attic/w3m.org b/attic/w3m.org
deleted file mode 100644
index e169e28..0000000
--- a/attic/w3m.org
+++ /dev/null
@@ -1,344 +0,0 @@
-#+title: Customizations for emacs-w3m
-
-* Custom variables:
- #+BEGIN_SRC emacs-lisp
- (use-package w3m
- :ensure t
- :custom ((w3m-key-binding 'info)
- (w3m-display-mode 'dual-pane))
- :init
- (setq w3m-add-user-agent nil
- w3m-command "w3m"
- w3m-confirm-leaving-secure-page nil
- w3m-cookie-accept-bad-cookies t
- w3m-use-tab nil
- w3m-display-mode 'dual-pane
- w3m-do-cleanup-temp-files t
- w3m-doc-view-content-types ()
- w3m-fill-column 110
- w3m-form-input-textarea-buffer-lines 40
- w3m-history-minimize-in-new-session t
- w3m-history-reuse-history-elements nil
- w3m-image-no-idle-timer t
- w3m-make-new-session t
- w3m-profile-directory "~/.w3m"
- w3m-redisplay-pages-automatically-p nil
- w3m-safe-url-regexp nil
- w3m-search-default-engine "duckduckgo" ; "google-en"
- w3m-select-buffer-horizontal-window nil
- w3m-select-buffer-window-ratio '(20 . 40)
- w3m-session-load-last-sessions t
- w3m-session-load-crashed-sessions 'ask
- w3m-show-graphic-icons-in-header-line t
- w3m-space-before-favicon "|"
- w3m-tab-separator ""
- w3m-use-cookies t
- w3m-use-favicon nil
- w3m-use-header-line nil
- w3m-use-refresh nil)
-
- (with-eval-after-load 'org (require 'ol-w3m nil t))
- (setq jao-browse-url-function 'jao-w3m-browse-url)
- :config (defalias 'jao-goto-w3m-frame 'jao-afio--goto-www)
- :bind (:map w3m-mode-map (("C-c C-@" . tracking-next-buffer)
- ("C-c C-SPC" . tracking-next-buffer))))
- (require 'w3m)
- #+END_SRC
-* Coding systems and content type
- #+begin_src emacs-lisp
- (mapc (lambda (v) (set v 'utf-8))
- '(w3m-default-coding-system
- w3m-bookmark-file-coding-system
- w3m-coding-system
- w3m-file-coding-system
- w3m-file-name-coding-system
- w3m-terminal-coding-system))
-
- (jao-when-linux
- (setq w3m-content-type-alist
- '(("text/plain" "\\.\\(?:txt\\|tex\\|el\\)\\'" nil nil)
- ("text/html" "\\.s?html?\\'" jao-browse-with-external-browser nil)
- ("text/html" "." jao-browse-with-external-browser nil)
- ("text/sgml" "\\.sgml?\\'" nil "text/plain")
- ("text/xml" "\\.xml\\'" nil "text/plain")
- ("image/jpeg" "\\.jpe?g\\'" ("emacsclient" file) nil)
- ("image/png" "\\.png\\'" ("emacsclient" file) nil)
- ("image/gif" "\\.gif\\'" ("emacsclient" file) nil)
- ("image/tiff" "\\.tif?f\\'" ("emacsclient" file) nil)
- ("image/x-xwd" "\\.xwd\\'" ("emacsclient" file) nil)
- ("image/x-xbm" "\\.xbm\\'" ("emacsclient" file) nil)
- ("image/x-xpm" "\\.xpm\\'" ("emacsclient" file) nil)
- ("image/x-bmp" "\\.bmp\\'" ("emacsclient" file) nil)
- ("video/mpeg" "\\.mpe?g\\'" jao-maybe-view-video nil)
- ("video/quicktime" "\\.mov\\'" jao-maybe-view-video nil)
- ("video/*" "\\.mpe?g\\'" jao-maybe-view-video nil)
- ("application/dvi" "\\.dvi\\'" ("xdvi" file) nil)
- ("application/postscript" "\\.e?ps\\'" ("/usr/bin/see" file) nil)
- ("application/pdf" "\\.pdf\\'" ("viewpdf.sh" file) nil)
- ("application/xml" "\\.xml\\'" nil w3m-detect-xml-type)
- ("application/rdf+xml" "\\.rdf\\'" nil "text/plain")
- ("application/rss+xml" "\\.rss\\'" nil "text/plain")
- ("application/xhtml+xml" nil nil "text/html")
- ("unknown" nil nil "text/plain"))))
- #+end_src
-* Filters
- #+begin_src emacs-lisp
- (setq w3m-use-filter t
- w3m-filter-configuration
- '((t "Strip Google's click-tracking"
- "\\`https?://[a-z]+\\.google\\."
- w3m-filter-google-click-tracking)
- (t "Align table columns vertically to shrink the table width in Google"
- "\\`http://\\(www\\|images\\|news\\|maps\\|groups\\)\\.google\\."
- w3m-filter-google-shrink-table-width)
- (t "Add name anchors that w3m can handle in all pages"
- ""
- w3m-filter-add-name-anchors)
- (t "Substitute disabled attr with readonly attr in forms"
- ""
- w3m-filter-subst-disabled-with-readonly)
- (t "Filter top and bottom cruft for stackexchange.com"
- "\\`https://\\(?:[0-9A-Za-z_~-]+\\.\\)*stackexchange\\.com\\(?:\\'\\|/\\)"
- w3m-filter-stackexchange)
- (t "filter for github.com repository main page"
- "\\`http[s]?://github\\.com/[^/]+/[^/]+[/]?\\'"
- w3m-filter-github-repo-main-page)
- (t "xkcd filter" "\\`http[s]?://xkcd.com/" w3m-filter-xkcd)
- (nil "Prefer a lazy image specified with data-src= in img tags"
- ""
- w3m-filter-prefer-lazy-images)))
- #+end_src
-* Symbols and drawing
- #+BEGIN_SRC emacs-lisp
- (setq w3m-default-symbol '("┼" "├" "┬" "┌" "┤" "│" "┐" ""
- "┴" "└" "─" "" "┘" "" "" ""
- "┼" "├" "┬" "┌" "┤" "│" "┐" ""
- "┴" "└" "─" "" "┘" "" "" ""
- "•" "•" "•" "•" " • "
- "•" "•" "•" "•" "•" "•" "•" "•"
- "≪ ↑ ↓ "))
- (setq w3m-symbol w3m-default-symbol)
- (setq-default w3m-use-symbol t)
- #+END_SRC
-* Browse url (with unique buffer support)
- #+BEGIN_SRC emacs-lisp
- (defvar jao-w3m-unique-buffer-rxs
- '("^file:.*hyperspec/.*"
- "^file:.*/usr/\\(local/\\)?share/doc/racket/.*"
- "^file:///home/jao/src/racket/doc/.*"
- "^file:.*/usr/local/plt/doc/.*"
- "^file:.*/\\(usr/share/doc/ghc6-doc/html/.*\\|\\.cabal/\\).*"
- "^file:.*/doc/hyperspec/.*"
- ("/tmp/jde_meta\.html" . "^file:.*/java/docs/.*")))
-
- (defun jao-w3m-url-matcher (url)
- (let* ((url (w3m-canonicalize-url url))
- (urx (format "^%s$" url)))
- (dolist (rx jao-w3m-unique-buffer-rxs)
- (let ((m (if (consp rx) (car rx) rx))
- (r (if (consp rx) (cdr rx) rx)))
- (when (string-match m url) (setq urx r))))
- urx))
-
- (defun jao-w3m-find-url (url)
- ;; (message "finding %s" url)
- (let ((urx (jao-w3m-url-matcher url))
- (buffers (w3m-list-buffers))
- (found nil))
- (save-current-buffer
- (while (not (or found (null buffers)))
- (let ((b (car buffers)))
- (set-buffer b)
- (if (and w3m-current-url
- (string-match urx
- (w3m-canonicalize-url w3m-current-url)))
- (setq found b)
- (setq buffers (cdr buffers))))))
- (when found
- (let ((pop-up-windows nil)
- (display-buffer-reuse-frames nil))
- (pop-to-buffer found)))
- found))
-
- (defun jao-w3m-browse-url (url &rest r)
- "Browse URL using w3m.
-
- If a frame running w3m already exists, reuses it creating
- a new tab. If the URL is already open, though, the tab
- containing it is selected."
- (jao-goto-w3m-frame)
- (select-window (frame-first-window))
- (or (jao-w3m-find-url url)
- (w3m-goto-url-new-session url)))
-
- (defun jao-w3m-do-browse ()
- "Use the generic browse-url with URL at point."
- (interactive)
- (let ((uri (or (w3m-anchor) (w3m-image) w3m-current-url)))
- (browse-url uri)))
-
- (defun jao-w3m-download (arg)
- (interactive "P")
- (jao-download (w3m-anchor) arg))
-
- (setq w3m-goto-article-function 'jao-w3m-browse-url)
- #+END_SRC
-* Tweeting and tooting
- #+BEGIN_SRC emacs-lisp
- (defun jao-w3m--toot-text (from to title)
- (let ((a (or (jao-url-around-point)
- w3m-current-url
- (error "No URL to tweet!")))
- (txt (or title
- (if (and from to)
- (buffer-substring from to)
- (w3m-current-title)))))
- (if (string-empty-p (or txt ""))
- a
- (format "'%s' -- %s" txt a))))
-
- (defun jao-w3m-tweet (&optional from to title buff)
- (interactive (when (use-region-p) (list (region-beginning) (region-end))))
- (let ((txt (jao-w3m--toot-text from to title)))
- (pop-to-buffer (or buff "#twitter_jaotwits"))
- (goto-char (point-max))
- (insert "post " txt)))
-
- (defun jao-w3m-toot (&optional from to title)
- (interactive (when (use-region-p) (list (region-beginning) (region-end))))
- (jao-w3m-tweet from to title "#mastodon"))
- #+END_SRC
-* Cookies
- #+begin_src emacs-lisp
- ;; for reddit http://i.reddit.com is non-js friendly
- (setq w3m-cookie-reject-domains '(".")
- w3m-cookie-accept-domains '(".github.com"
- ".librarything.com"
- ".goodreads.com"
- ".sr.ht"
- ".gnu.org"
- ".codeberg.org"
- "codeberg.org"
- ".bookshop.org"
- ".reddit.com"))
- #+end_src
-* Email
- #+begin_src emacs-lisp
- (defun jao-w3m-gmail-mark-all (unmark)
- (interactive "P")
- (goto-char (point-min))
- (when (search-forward (if unmark "[*]" "[ ]") nil t)
- (backward-char 4)
- (w3m-form-goto-next-field)
- (while (looking-at (if unmark "\\*\\]" " \\]"))
- (w3m-view-this-url)
- (w3m-form-goto-next-field))))
-
- (defun jao-w3m-mail-page ()
- (interactive)
- (let ((wb (w3m-alive-p)))
- (when wb
- (compose-mail nil
- (read-string "Subject: " (w3m-buffer-title wb)))
- (message-goto-body)
- (insert "\n\n<" (with-current-buffer wb w3m-current-url) ">\n")
- (message-goto-to))))
-
- (defun jao-w3m-gnus-html-renderer (handle)
- (let ((w3m-message-silent t)
- (mm-w3m-safe-url-regexp nil)
- (shr-use-colors nil)
- (shr-use-fonts nil)
- (fill-column (min (window-width) 110)))
- (condition-case nil
- (mm-inline-text-html-render-with-w3m handle)
- (error (delete-region (point) (point-max))
- (mm-shr handle)))))
-
- #+end_src
-* Proxies
- #+BEGIN_SRC emacs-lisp
- (defun jao-w3m-activate-proxy ()
- (interactive)
- (setq w3m-command-arguments
- (nconc w3m-command-arguments
- '("-o" "http_proxy=http://localhost:8888"))))
-
- (defun jao-w3m-deactivate-proxy ()
- (interactive)
- (setq w3m-command-arguments (cdr w3m-command-arguments)))
- #+END_SRC
-* Switch buffers
- #+BEGIN_SRC emacs-lisp
- (defun jao-w3m-switch-buffers (dist)
- (interactive "p")
- (let* ((dist (if (zerop dist) 1 dist))
- (current (current-buffer))
- (current-no (w3m-buffer-number current))
- (next (progn (w3m-next-buffer dist)
- (current-buffer)))
- (next-no (w3m-buffer-number next)))
- (with-current-buffer current
- (rename-buffer "*w3m*<*>")
- (w3m-buffer-set-number next current-no)
- (w3m-buffer-set-number current next-no)
- (w3m-pack-buffer-numbers))
- (switch-to-buffer current)))
- #+END_SRC
-* Capture page
- #+BEGIN_SRC emacs-lisp
- (defun jao-w3m-capture-page ()
- (interactive)
- (let* ((title (w3m-current-title))
- (url w3m-current-url)
- (html (y-or-n-p "Save as HTML (y) or PS (n)? "))
- (basename (concat (read-string "File name: ")
- (if html ".html" ".ps")))
- (name (expand-file-name basename jao-sink-dir)))
- (if html
- (progn
- (w3m-view-source)
- (write-region (point-min) (point-max) name nil nil nil t)
- (w3m-view-source))
- (progn
- (split-window-horizontally 85)
- (w3m-redisplay-this-page)
- (ps-print-buffer name)
- (delete-other-windows)
- (w3m-redisplay-this-page)))
- (kill-new (format "[[doc:%s][%s]] ([[%s][original]])"
- basename title url))))
-
- (defun jao-w3m-get-link ()
- (let ((wb (w3m-alive-p)))
- (when wb
- (let ((url (with-current-buffer wb w3m-current-url))
- (title (w3m-buffer-title wb)))
- (cons url title)))))
-
- (defun jao-insert-w3m-link ()
- (interactive)
- (let ((link (jao-w3m-get-link)))
- (when link (insert "[[" (car link) "][" (cdr link) "]]"))))
- #+END_SRC
-* Keybindings
- #+BEGIN_SRC emacs-lisp
- (define-key w3m-mode-map "B" 'jao-w3m-do-browse)
- (define-key w3m-mode-map "d" 'jao-w3m-download)
- (define-key w3m-mode-map (kbd "\C-ck") 'jao-w3m-gmail-mark-all)
- (define-key w3m-mode-map (kbd "\C-c\C-f") 'jao-w3m-switch-buffers)
- (define-key w3m-mode-map (kbd "\C-cc") 'jao-w3m-capture-page)
- (define-key w3m-mode-map "\M-\r" 'w3m-view-this-url-new-session)
- (define-key w3m-mode-map "+" 'w3m-zoom-in-image)
- (define-key w3m-mode-map "-" 'w3m-zoom-out-image)
- (define-key w3m-mode-map "m" 'jao-w3m-mail-page)
- (define-key w3m-mode-map "M" 'w3m-view-url-with-external-browser)
- (define-key w3m-mode-map "t" 'jao-w3m-tweet)
- (define-key w3m-mode-map "T" 'jao-w3m-toot)
- (define-key w3m-mode-map "f" 'w3m-lnum-follow)
- (define-key w3m-mode-map "c" 'w3m-print-this-url)
- (define-key w3m-mode-map "v" 'jao-view-video)
- (define-key w3m-mode-map "V" 'w3m-download)
- (define-key w3m-mode-map "x" 'jao-rss-subscribe-rss)
- (define-key w3m-mode-map "Y" 'w3m-print-current-url)
- #+END_SRC
diff --git a/eww.org b/eww.org
index 876ecbe..328af73 100644
--- a/eww.org
+++ b/eww.org
@@ -17,7 +17,15 @@
(setq jao-browse-url-function #'jao-eww-browse-url)
(setq browse-url-browser-function jao-browse-url-function)
#+end_src
-
+* Email
+ #+begin_src emacs-lisp
+ (defun jao-eww-html-renderer (handle)
+ (let ((shr-use-colors nil)
+ (shr-use-fonts nil)
+ (fill-column (min (window-width) 110)))
+ (mm-shr handle)))
+ (setq mm-text-html-renderer 'jao-eww-html-renderer)
+ #+end_src
* Buffer names
#+begin_src emacs-lisp
(defun jao-eww--title ()
@@ -181,20 +189,21 @@
("B" . eww-forward-url)
("d" . eww-download)
("D" . jao-download)
- ("o" . jao-eww-browse)
- ("O" . jao-eww-browse-new)
("f" . eww-lnum-follow)
("F" . eww-lnum-universal)
("j" . jao-eww-visit-url-on-page)
("J" . jao-eww-jump-to-url-on-page)
("L" . eww-forward-url)
("N" . jao-eww-next-image)
+ ("o" . jao-eww-browse)
+ ("O" . jao-eww-browse-new)
("r" . jao-eww-reload)
+ ("s" . eww-search-words)
("S" . jao-eww-session-load)
("u" . jao-eww-reopen)
("U" . jao-eww-reopen-new)
- ("W" . jao-eww-close)
("w" . org-eww-copy-for-org-mode)
+ ("W" . jao-eww-close)
("x" . jao-rss-subscribe)
("y" . eww-copy-page-url)
("C-c C-w" . jao-eww-close))))
diff --git a/gnus.org b/gnus.org
index bf5c30b..c622946 100644
--- a/gnus.org
+++ b/gnus.org
@@ -503,16 +503,8 @@
#+END_SRC
*** HTML email
#+BEGIN_SRC emacs-lisp
- ;; use w3m for html mail
- (defun jao-gnus-html-renderer (handle)
- (let ((shr-use-colors nil)
- (shr-use-fonts nil)
- (fill-column (min (window-width) 110)))
- (mm-shr handle)))
-
(setq gnus-button-url 'browse-url-generic
gnus-inhibit-images t
- mm-text-html-renderer 'jao-gnus-html-renderer ;; 'w3m ;; 'shr
mm-discouraged-alternatives nil ;; '("text/html" "text/richtext")
mm-inline-large-images 'resize)
@@ -584,50 +576,10 @@
(sit-for 1)
(jao-emms-echo))))))
#+end_src
-*** Tweets and toots
- #+BEGIN_SRC emacs-lisp
- (defun jao-gnus--find-link ()
- (when (eq major-mode 'gnus-summary-mode)
- (gnus-summary-select-article-buffer))
- (goto-char (point-max))
- (or (search-backward-regexp "^Link\\b" nil t)
- (search-backward-regexp "^URL: h" nil t)
- (search-backward-regexp "^Via: h"))
- (goto-char (match-end 0))
- (jao-w3m--toot-text nil nil ""))
-
- (defun jao-gnus-tweet-link (&optional toot)
- (interactive "P")
- (save-excursion
- (jao-gnus--find-link)
- (if toot
- (jao-w3m-toot nil nil (elt gnus-current-headers 1))
- (jao-w3m-tweet nil nil (elt gnus-current-headers 1)))))
-
- (defun jao-gnus-toot-link ()
- (interactive)
- (jao-gnus-tweet-link t))
-
- (defun jao-gnus-mail-link ()
- (interactive)
- (let ((txt (jao-gnus--find-link)))
- (when txt
- (message-mail-other-window)
- (message-goto-body)
- (insert "\n\n" txt)
- (message-goto-to))))
- #+END_SRC
* Keyboard shortcuts
#+BEGIN_SRC emacs-lisp
- (define-key gnus-article-mode-map "\C-ci" 'w3m-view-image)
- (define-key gnus-article-mode-map "\C-cb" 'jao-w3m-do-browse)
(define-key gnus-article-mode-map "i" 'jao-gnus-show-images)
(define-key gnus-summary-mode-map "i" 'jao-gnus-show-images)
- (define-key gnus-article-mode-map "z" 'w3m-lnum-zoom-in-image)
- (define-key gnus-article-mode-map "\C-ct" 'jao-gnus-tweet-link)
- (define-key gnus-summary-mode-map "\C-ct" 'jao-gnus-tweet-link)
- (define-key gnus-article-mode-map "\C-cT" 'jao-gnus-toot-link)
- (define-key gnus-summary-mode-map "\C-cT" 'jao-gnus-toot-link)
(define-key gnus-article-mode-map "\M-g" 'jao-gnus-follow-link)
(define-key gnus-summary-mode-map "\M-g" 'jao-gnus-follow-link)
(define-key gnus-summary-mode-map "v" 'scroll-other-window)
diff --git a/init.org b/init.org
index 3797ffa..cce374f 100644
--- a/init.org
+++ b/init.org
@@ -2220,9 +2220,10 @@
name url cat name)))))
(message "No feeds found"))))
#+end_src
-*** Web browser (eww)
+*** Web browsers
#+begin_src emacs-lisp
(jao-load-org "eww")
+ (jao-load-org "w3m")
#+end_src
* Shells
*** shell modes
diff --git a/org.org b/org.org
index f79f0ca..c103545 100644
--- a/org.org
+++ b/org.org
@@ -285,18 +285,13 @@
(org-show-subtree))))
(add-hook 'org-mode-hook 'jao-org--show-if-hidden t)
#+end_src
-* Geiser and org
- #+begin_src emacs-lisp
- (defun jao-org--set-geiser-impl () (setq-local geiser-repl--impl 'guile))
- (add-hook 'org-mode-hook #'jao-org--set-geiser-impl)
- #+end_src
* Keybindings
#+begin_src emacs-lisp
(define-key mode-specific-map [?a] 'org-agenda)
(define-key org-mode-map "\C-cv" 'jao-org-copy-link-at-point)
(define-key org-mode-map [(control ?c) tab] 'org-force-cycle-archived)
(define-key org-mode-map [(f7)] 'org-archive-to-archive-sibling)
- (define-key org-mode-map "\C-cW" 'jao-insert-eww-link)
+ (define-key org-mode-map "\C-cE" 'jao-insert-eww-link)
(define-key org-mode-map "\C-c'" 'org-edit-src-code)
(define-key org-mode-map (kbd "C-c o") #'jao-org-org-goto-pdf)
(define-key org-mode-map "\C-cO" 'outline-hide-other)
diff --git a/readme.org b/readme.org
index a31e761..70bc090 100644
--- a/readme.org
+++ b/readme.org
@@ -62,16 +62,15 @@
- [[./init.org][init.org]]: main configuration as a literate org file; it uses
(besides lots of packages), many of my libraries in [[./lib][lib]], and loads
on demand the other org files below.
-- [[./completion.org][completion.org]]: completion setup using company, consult and friends
- (see
+- [[./completion.org][completion.org]]: completion setup using company, consult and friends.
- [[./org.org][org.org]] org mode configuration.
- [[./blog.org][blog.org]]: blogging using org-static-blog.
- [[./gnus.org][gnus.org]]: tangled to gnus.el automatically by init.org, so that it's
ready for loading by Gnus.
+- [[./w3m.org][w3m.org]]: browsing with emacs-w3m.
- [[./eww.org][eww.org]]: browsing with eww.
- [[./exwm.org][exwm.org]]: configuration for exwm, loaded when ~jao-exwmn-enable~ is
called.
The [[./attic][attic]] contains other literate configuration files not currently
-used by init.org, like [[./attic/counsel.org][counsel.org]] for old ivy-based completion or
-[[./attic/w3m.org][w3m.org]] for emacs-w3m.
+used by init.org, like [[./attic/counsel.org][counsel.org]] for old ivy-based completion.
diff --git a/w3m.org b/w3m.org
new file mode 100644
index 0000000..0097ac5
--- /dev/null
+++ b/w3m.org
@@ -0,0 +1,150 @@
+#+title: Customizations for emacs-w3m
+
+* browse-url and afio
+ #+begin_src emacs-lisp
+ (defun jao-w3m-find-url (url)
+ (let* ((url (w3m-canonicalize-url url))
+ (fn `(lambda (b)
+ (with-current-buffer b
+ (string= ,url (w3m-canonicalize-url w3m-current-url))))))
+ (when-let (b (seq-find fn (w3m-list-buffers)))
+ (pop-to-buffer b))))
+
+ (defun jao-w3m-browse-url (url &rest r)
+ (jao-afio--goto-www)
+ (select-window (frame-first-window))
+ (or (jao-w3m-find-url url)
+ (w3m-goto-url-new-session url)))
+
+ (defun jao-w3m-download (arg)
+ (interactive "P")
+ (jao-download (w3m-anchor) arg))
+
+ (setq jao-afio-use-w3m t)
+ (setq jao-browse-url-function 'jao-w3m-browse-url)
+ #+end_src
+* Org integration
+ #+begin_src emacs-lisp
+ (defun jao-w3m-get-link ()
+ (let ((wb (w3m-alive-p)))
+ (when wb
+ (let ((url (with-current-buffer wb w3m-current-url))
+ (title (w3m-buffer-title wb)))
+ (cons url title)))))
+
+ (defun jao-insert-w3m-link ()
+ (interactive)
+ (let ((link (jao-w3m-get-link)))
+ (when link (insert "[[" (car link) "][" (cdr link) "]]"))))
+
+ (with-eval-after-load "org"
+ (require 'ol-w3m nil t)
+ (define-key org-mode-map "\C-cW" 'jao-insert-w3m-link))
+ #+end_src
+* Capture page
+ #+begin_src emacs-lisp
+ (defun jao-w3m-capture-page ()
+ (interactive)
+ (let* ((title (w3m-current-title))
+ (url w3m-current-url)
+ (html (y-or-n-p "Save as HTML (y) or PS (n)? "))
+ (basename (concat (read-string "File name: ")
+ (if html ".html" ".ps")))
+ (name (expand-file-name basename jao-sink-dir)))
+ (if html
+ (progn
+ (w3m-view-source)
+ (write-region (point-min) (point-max) name nil nil nil t)
+ (w3m-view-source))
+ (progn
+ (split-window-horizontally 85)
+ (w3m-redisplay-this-page)
+ (ps-print-buffer name)
+ (delete-other-windows)
+ (w3m-redisplay-this-page)))
+ (kill-new (format "[[doc:%s][%s]] ([[%s][original]])"
+ basename title url))))
+ #+end_src
+* Email
+ #+begin_src emacs-lisp
+ (defun jao-w3m-gnus-html-renderer (handle)
+ (let ((w3m-message-silent t)
+ (mm-w3m-safe-url-regexp nil)
+ (shr-use-colors nil)
+ (shr-use-fonts nil)
+ (fill-column (min (window-width) 110)))
+ (condition-case nil
+ (mm-inline-text-html-render-with-w3m handle)
+ (error (delete-region (point) (point-max))
+ (mm-shr handle)))))
+
+ (setq mm-text-html-renderer #'jao-w3m-gnus-html-renderer)
+
+ (with-eval-after-load "gnus-art"
+ (define-key gnus-article-mode-map "\C-ci" 'w3m-view-image)
+ (define-key gnus-article-mode-map "z" 'w3m-lnum-zoom-in-image))
+ #+end_src
+* Package
+ #+begin_src emacs-lisp
+ (use-package w3m
+ :ensure t
+ :custom ((w3m-key-binding 'info)
+ (w3m-display-mode 'dual-pane))
+ :init
+ (setq w3m-add-user-agent nil
+ w3m-command "w3m"
+ w3m-confirm-leaving-secure-page nil
+ w3m-cookie-accept-bad-cookies t
+ w3m-cookie-accept-domains '(".github.com"
+ ".librarything.com"
+ ".goodreads.com"
+ ".sr.ht"
+ ".gnu.org"
+ ".codeberg.org"
+ "codeberg.org"
+ ".bookshop.org"
+ ".reddit.com")
+ w3m-cookie-reject-domains '(".")
+ w3m-use-tab nil
+ w3m-do-cleanup-temp-files t
+ ;; w3m-doc-view-content-types ()
+ w3m-fill-column 110
+ w3m-goto-article-function 'jao-w3m-browse-url
+ w3m-form-input-textarea-buffer-lines 40
+ w3m-history-minimize-in-new-session t
+ w3m-history-reuse-history-elements nil
+ w3m-image-no-idle-timer t
+ w3m-make-new-session t
+ w3m-profile-directory "~/.w3m"
+ w3m-redisplay-pages-automatically-p nil
+ w3m-safe-url-regexp nil
+ w3m-search-default-engine "duckduckgo" ; "google-en"
+ w3m-select-buffer-horizontal-window nil
+ w3m-select-buffer-window-ratio '(20 . 40)
+ w3m-session-load-last-sessions t
+ w3m-session-load-crashed-sessions 'ask
+ w3m-show-graphic-icons-in-header-line t
+ w3m-space-before-favicon "|"
+ w3m-tab-separator ""
+ w3m-use-cookies t
+ w3m-use-filter nil
+ w3m-use-favicon nil
+ w3m-use-header-line nil
+ w3m-use-refresh nil
+ w3m-use-symbol t)
+
+ :config
+ :bind (:map w3m-mode-map
+ (("+" . w3m-zoom-in-image)
+ ("-" . w3m-zoom-out-image)
+ ("C-c C-@" . tracking-next-buffer)
+ ("C-c C-SPC" . tracking-next-buffer)
+ ("C-c c" . jao-w3m-capture-page)
+ ("V" . w3m-download)
+ ("c" . w3m-print-this-url)
+ ("d" . jao-w3m-download)
+ ("f" . w3m-lnum-follow)
+ ("v" . jao-view-video)
+ ("x" . jao-rss-subscribe-rss)
+ ("y" . w3m-print-current-url))))
+ #+end_src