From 8ea756c5d0ff541d33fb1be56d4c53a0b12f90e4 Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 17 Apr 2021 23:16:19 +0100 Subject: configurable MUA in afio --- attic/w3m.org | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++ exwm.org | 4 +- lib/eos/jao-afio.el | 58 ++++++++++--------- w3m.org | 156 ---------------------------------------------------- 4 files changed, 191 insertions(+), 183 deletions(-) create mode 100644 attic/w3m.org delete mode 100644 w3m.org diff --git a/attic/w3m.org b/attic/w3m.org new file mode 100644 index 0000000..e1229ab --- /dev/null +++ b/attic/w3m.org @@ -0,0 +1,156 @@ +#+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-do-cleanup-temp-files t + 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 t + w3m-resize-images t + 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 nil + w3m-show-graphic-icons-in-mode-line nil + w3m-space-before-favicon "|" + w3m-use-tab nil + w3m-use-tab-line nil + w3m-use-title-buffer-name t + 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-b" . nil) + ("C-c c" . jao-w3m-capture-page) + ("b" . w3m-view-previous-page) + ("B" . w3m-view-next-page) + ("c" . w3m-print-this-url) + ("d" . jao-w3m-download) + ("D" . w3m-download) + ("f" . w3m-lnum-follow) + ("v" . jao-view-video) + ("w" . org-w3m-copy-for-org-mode) + ("x" . jao-rss-subscribe-rss) + ("y" . w3m-print-current-url)))) + #+end_src diff --git a/exwm.org b/exwm.org index eb8e81e..9e989df 100644 --- a/exwm.org +++ b/exwm.org @@ -213,7 +213,7 @@ (if jao-exwm--use-afio (cl-case n ((1) (jao-afio--goto-main)) - ((2) (jao-afio--goto-gnus)) + ((2) (jao-afio--goto-mail)) ((3) (jao-afio--goto-www)) ((4) (jao-afio--goto-docs)) ((5) (jao-afio--goto-scratch-1)) @@ -501,7 +501,7 @@ exwm-input-global-keys '(([?\s-0] . jao-afio--goto-scratch) ([?\s-1] . jao-afio--goto-main) - ([?\s-2] . jao-afio--goto-gnus) + ([?\s-2] . jao-afio--goto-mail) ([?\s-3] . jao-afio--goto-www) ([?\s-4] . jao-afio--goto-docs) ([?\s-A] . org-agenda-list) diff --git a/lib/eos/jao-afio.el b/lib/eos/jao-afio.el index 7ebaf5d..1410b80 100644 --- a/lib/eos/jao-afio.el +++ b/lib/eos/jao-afio.el @@ -86,26 +86,32 @@ (when (and (jao-doc-view-session) (y-or-n-p "Load saved session? ")) (jao-afio-open-pdf-session))))) +(defvar jao-afio-mail-function 'gnus) (defvar jao-afio-use-w3m nil) +(defvar jao-afio-notmuch-in-web t) + (declare w3m "w3m") (declare w3m-alive-p "w3m") (declare w3m-previous-buffer "w3m") +(declare notmuch "notmuch") ;;;###autoload (defun jao-afio-open-www () (interactive) (require 'jao-eww-session) - (if (< (frame-width) 180) + (if (< (frame-width) 160) (if jao-afio-use-w3m (w3m) (jao-eww-session-load)) (delete-other-windows) (split-window-right) - (if jao-afio-use-w3m (w3m) (jao-eww-session-load)) - (other-window 1) - (when jao-afio-use-w3m - (switch-to-buffer "*w3m*") - (ignore-errors (w3m-previous-buffer 2))) - (unless jao-afio-use-w3m - (switch-to-buffer (car (last (jao-eww-session--list-buffers))))))) + (if jao-afio-use-w3m + (w3m) + (jao-eww-session-load) + (let ((b (current-buffer))) + (other-window 1) + (if jao-afio-notmuch-in-web + (notmuch) + (switch-to-buffer (car (jao-eww-session--list-buffers b)))) + (other-window 1))))) ;;;###autoload (defun jao-afio-open-gnus () @@ -118,20 +124,22 @@ (jao-gnus--set-summary-line)) ;;;###autoload -(defun jao-afio-open-mail (mail-func) +(defun jao-afio-open-mail () (interactive) - (delete-other-windows) - (funcall mail-func) - (jao-bisect) - (other-window 1) - (find-file (expand-file-name "inbox.org" org-directory)) - (split-window-below (/ (window-height) 3)) - (other-window 1) - (org-agenda-list) - (split-window-below -9) - (other-window 1) - (switch-to-buffer "*Calendar*") - (other-window 1)) + (if (or (null jao-afio-mail-function) (eq 'gnus jao-afio-mail-function)) + (jao-afio-open-gnus) + (delete-other-windows) + (funcall jao-afio-mail-function) + (jao-bisect) + (other-window 1) + (find-file (expand-file-name "inbox.org" org-directory)) + (split-window-below (/ (window-height) 3)) + (other-window 1) + (org-agenda-list) + (split-window-below -9) + (other-window 1) + (switch-to-buffer "*Calendar*") + (other-window 1))) (defvar jao-afio-switch-hook nil) @@ -145,7 +153,7 @@ (delete-other-windows) (cl-case next (?w (jao-afio-open-www)) - (?g (jao-afio-open-gnus)) + (?g (jao-afio-open-mail)) (?p (jao-afio-open-doc)) (?s (delete-other-windows)))) (run-hooks 'jao-afio-switch-hook)))) @@ -160,7 +168,7 @@ (jao-afio--check-frame) (jao-afio--goto-frame ?s reset)) -(defun jao-afio--goto-gnus (&optional reset) +(defun jao-afio--goto-mail (&optional reset) (interactive "P") (jao-afio--check-frame) (jao-afio--goto-frame ?g reset)) @@ -201,7 +209,7 @@ (cl-case jao-afio--current-config (?c "Main") (?s "Scratch") - (?g "Gnus") + (?g "Mail") (?p "Docs") (?w "Web"))) @@ -216,7 +224,7 @@ ;;;###autoload (defun jao-afio-setup (&optional fallback-fun init-p) (global-set-key "\C-cf" 'jao-afio--goto-main) - (global-set-key "\C-cg" 'jao-afio--goto-gnus) + (global-set-key "\C-cg" 'jao-afio--goto-mail) (global-set-key "\C-cw" 'jao-afio--goto-www) (global-set-key "\C-cz" 'jao-afio--goto-docs) (setq jao-afio-fallback-fun fallback-fun) diff --git a/w3m.org b/w3m.org deleted file mode 100644 index e1229ab..0000000 --- a/w3m.org +++ /dev/null @@ -1,156 +0,0 @@ -#+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-do-cleanup-temp-files t - 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 t - w3m-resize-images t - 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 nil - w3m-show-graphic-icons-in-mode-line nil - w3m-space-before-favicon "|" - w3m-use-tab nil - w3m-use-tab-line nil - w3m-use-title-buffer-name t - 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-b" . nil) - ("C-c c" . jao-w3m-capture-page) - ("b" . w3m-view-previous-page) - ("B" . w3m-view-next-page) - ("c" . w3m-print-this-url) - ("d" . jao-w3m-download) - ("D" . w3m-download) - ("f" . w3m-lnum-follow) - ("v" . jao-view-video) - ("w" . org-w3m-copy-for-org-mode) - ("x" . jao-rss-subscribe-rss) - ("y" . w3m-print-current-url)))) - #+end_src -- cgit v1.2.3