summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-03-25 23:18:00 +0000
committerjao <jao@gnu.org>2021-03-25 23:18:00 +0000
commit4eb79b623129e0275771d442a0746749e2b5b2c0 (patch)
tree802ff4b5cc95621afba5f25e05cd62bdc6572d84
parent01f1ebeae9d6031e266996a667093fe4afea1491 (diff)
downloadelibs-4eb79b623129e0275771d442a0746749e2b5b2c0.tar.gz
elibs-4eb79b623129e0275771d442a0746749e2b5b2c0.tar.bz2
w3m-agnostic init.org
-rw-r--r--init.org259
1 files changed, 109 insertions, 150 deletions
diff --git a/init.org b/init.org
index 607dd16..5d54892 100644
--- a/init.org
+++ b/init.org
@@ -2043,41 +2043,24 @@
#+END_SRC
* Browsing
- #+begin_src emacs-lisp
- (require 'browse-url)
+*** Variables
+ #+begin_src emacs-lisp
+ (require 'browse-url)
- (defun jao-url-around-point ()
+ (defvar jao-browse-download-dir jao-sink-dir)
+ (defvar jao-browse-doc-use-emacs-p t)
+ (defvar jao-browse-url-function nil)
+ (defvar jao-browse-url-external-function nil)
+ (setq browse-url-generic-program (jao-d-l "open" "~/bin/firehog"))
+ #+end_src
+*** Helpers
+ #+BEGIN_SRC emacs-lisp
+ (defun jao-url-around-point ()
(or (and (fboundp 'w3m-anchor) (w3m-anchor))
(shr-url-at-point nil)
(ffap-url-at-point)
(thing-at-point 'url)))
- (defun jao-browse-with-external-browser (&rest url)
- "Browse with external hogging"
- (interactive "s")
- (let ((url (or (car url) (jao-url-around-point))))
- (if (not url)
- (message "No URL at point")
- (when (and jao-exwm-enabled-p (fboundp 'jao-exwm-firefox))
- (jao-exwm-firefox))
- (when (and jao-sway-enabled-p (fboundp 'jao-sway-firefox))
- (jao-sway-firefox))
- (browse-url-generic url))))
-
- (setq browse-url-generic-program (jao-d-l "open" "~/bin/firehog"))
- (setq jao-browse-url-external-function 'jao-browse-with-external-browser)
-
- (defvar jao-browse-download-dir jao-sink-dir)
- (defvar jao-browse-doc-use-emacs-p t)
-
- (with-eval-after-load "embark"
- (global-set-key (kbd "C-c M")
- (lambda () (interactive) (message "Use embark!")))
- (define-key embark-url-map "m" 'jao-browse-with-external-browser))
-
- #+end_src
-*** Helpers
- #+BEGIN_SRC emacs-lisp
(defun jao--fln (url)
(shell-quote-argument
(if (string-match "^[^:]*:/*?\\(/?[^/].*\\)" url)
@@ -2107,107 +2090,97 @@
(if def (format " (%s): " def) ": "))))
(read-string prompt nil nil def)))
+
+ #+END_SRC
+*** Downloads using wget
+ #+BEGIN_SRC emacs-lisp
(defvar jao-browse-url-wget-exts
'("ps" "pdf" "dvi" "djvu" "zip" "gz" "tgz" "mp4" "mp3" "flv")
"Extensions of HTTP(S) URLs to be downloaded using wget.")
- (defun jao-see-current-file ()
- (interactive)
- (jao--run (jao-d-l "open" "see") (buffer-file-name)))
- #+END_SRC
-*** Downloaders
-***** Using wget
- #+BEGIN_SRC emacs-lisp
- (defun jao-wget--regexp ()
- (concat "^http[s]?://.+\\(\\."
- (mapconcat 'identity jao-browse-url-wget-exts "\\|\\.")
- "\\)\\'"))
-
- (defun jao-wget (url &optional user pwd &rest ignored)
- "Download URL using wget."
- (let* ((def (file-name-nondirectory url))
- (pmt (format "Save %s to: " url))
- (read-file-name-function nil)
- (dest (expand-file-name
- (read-file-name pmt jao-browse-download-dir nil nil def)))
- (src-url (or (jao-url-around-point)
- (and (boundp w3m-current-url) w3m-current-url)))
- (auth (when (and user pwd) `(,(format "--http-user=%s" user)
- ,(format "--http-password=%s" pwd)))))
- (switch-to-buffer-other-window (get-buffer-create "*downloads*"))
- (setq jao-browse-download-dir (file-name-directory dest))
- (erase-buffer)
- (when (equalp (file-name-directory dest)
- (file-name-as-directory jao-sink-dir))
- (kill-new (format "[[doc:%s][%s]] (from [[%s][here]])"
- (file-name-nondirectory dest)
- (read-string "Title: " (jao-wget--get-title dest))
- (or src-url (file-name-directory url)))))
- (apply 'make-term `("downloads" "wget" nil ,@auth "-O" ,dest ,url))))
-
- (defun jao-download (url &optional pws)
- "Download URL using wget"
- (interactive (list (jao--url-prompt)))
- (when url
- (let ((usr (and pws (read-string "Login name: ")))
- (pwd (and pws (read-passwd "Password: "))))
- (jao-wget url usr pwd))))
-
- (with-eval-after-load "embark"
- (define-key embark-url-map (kbd "d") #'jao-download))
-
- #+END_SRC
-***** See/open
- #+BEGIN_SRC emacs-lisp
- (defun jao--see (url &rest r)
- (jao--run "see" url))
+ (defun jao-wget--regexp ()
+ (concat "^http[s]?://.+\\(\\."
+ (mapconcat 'identity jao-browse-url-wget-exts "\\|\\.")
+ "\\)\\'"))
+
+ (defun jao-wget (url &optional user pwd &rest ignored)
+ "Download URL using wget."
+ (let* ((def (file-name-nondirectory url))
+ (pmt (format "Save %s to: " url))
+ (read-file-name-function nil)
+ (dest (expand-file-name
+ (read-file-name pmt jao-browse-download-dir nil nil def)))
+ (src-url (or (jao-url-around-point)
+ (and (boundp w3m-current-url) w3m-current-url)))
+ (auth (when (and user pwd) `(,(format "--http-user=%s" user)
+ ,(format "--http-password=%s" pwd)))))
+ (switch-to-buffer-other-window (get-buffer-create "*downloads*"))
+ (setq jao-browse-download-dir (file-name-directory dest))
+ (erase-buffer)
+ (when (equalp (file-name-directory dest)
+ (file-name-as-directory jao-sink-dir))
+ (kill-new (format "[[doc:%s][%s]] (from [[%s][here]])"
+ (file-name-nondirectory dest)
+ (read-string "Title: " (jao-wget--get-title dest))
+ (or src-url (file-name-directory url)))))
+ (apply 'make-term `("downloads" "wget" nil ,@auth "-O" ,dest ,url))))
+
+ (defun jao-download (url &optional pws)
+ "Download URL using wget"
+ (interactive (list (jao--url-prompt)))
+ (when url
+ (let ((usr (and pws (read-string "Login name: ")))
+ (pwd (and pws (read-passwd "Password: "))))
+ (jao-wget url usr pwd))))
+
+ (with-eval-after-load "embark"
+ (define-key embark-url-map (kbd "d") #'jao-download))
- (defun jao--open (url &rest r) (jao--remote-run url "open"))
- #+END_SRC
-***** Video downloads and playing
- #+BEGIN_SRC emacs-lisp
- (defvar jao-video--url-rx
- (format "^https?://\\(?:www\\.\\)?%s/.+"
- (regexp-opt '("youtube.com" "blip.tv" "vimeo.com" "infoq.com")
- t)))
+ #+END_SRC
+*** Video downloads and playing
+ #+BEGIN_SRC emacs-lisp
+ (defvar jao-video--url-rx
+ (format "^https?://\\(?:www\\.\\)?%s/.+"
+ (regexp-opt '("youtube.com" "blip.tv" "vimeo.com" "infoq.com")
+ t)))
- (defun jao--remote-run (url prg)
- (let ((args (format "%s %s" prg (shell-quote-argument url))))
- (start-process-shell-command prg nil args)))
+ (defun jao--remote-run (url prg)
+ (let ((args (format "%s %s" prg (shell-quote-argument url))))
+ (start-process-shell-command prg nil args)))
- (defun jao--mpv (url &rest args) (jao--remote-run url "mpv"))
- (defun jao--vlc (url &rest args) (jao--remote-run url "vlc"))
+ (defun jao--mpv (url &rest args) (jao--remote-run url "mpv"))
+ (defun jao--vlc (url &rest args) (jao--remote-run url "vlc"))
- (defvar jao--video-player 'jao--mpv)
+ (defvar jao--video-player 'jao--mpv)
- (defun jao-view-video (url)
- "Tries to stream a video from the current or given URL"
- (interactive (list (jao--url-prompt)))
- (when url (funcall jao--video-player url)))
+ (defun jao-view-video (url)
+ "Tries to stream a video from the current or given URL"
+ (interactive (list (jao--url-prompt)))
+ (when url (funcall jao--video-player url)))
- (defun jao-maybe-view-video (url &rest _ignored)
- (interactive)
- (if (y-or-n-p "View video (y) or web page (n)? ")
- (jao-view-video url)
- (funcall jao-browse-url-function url)))
+ (defun jao-maybe-view-video (url &rest _ignored)
+ (interactive)
+ (if (y-or-n-p "View video (y) or web page (n)? ")
+ (jao-view-video url)
+ (funcall jao-browse-url-function url)))
- #+END_SRC
-*** File extensions
- #+BEGIN_SRC emacs-lisp
- (defun jao--make-file-rx (exts)
- (format "file:/?/?.+\\.%s$" (regexp-opt exts)))
- (setq jao--music-exts (jao--make-file-rx '("mp3" "m4a" "ogg")))
- (setq jao--see-exts
- (jao--make-file-rx '("jpg" "jpeg" "png" "mov" "wmv" "avi" "mp4")))
- (setq jao--doc-exts
- (jao--make-file-rx '("ps" "ps.gz" "pdf" "dvi" "djvu" "chm")))
- #+END_SRC
-*** eww
- #+BEGIN_SRC emacs-lisp
- (setq eww-download-directory "~/var/download")
#+END_SRC
*** Browse URL
#+BEGIN_SRC emacs-lisp
+
+ (defun jao-browse-with-external-browser (&rest url)
+ "Browse with external hogging"
+ (interactive "s")
+ (let ((url (or (car url) (jao-url-around-point))))
+ (if (not url)
+ (message "No URL at point")
+ (when (and jao-exwm-enabled-p (fboundp 'jao-exwm-firefox))
+ (jao-exwm-firefox))
+ (when (and jao-sway-enabled-p (fboundp 'jao-sway-firefox))
+ (jao-sway-firefox))
+ (browse-url-generic url))))
+ (setq jao-browse-url-external-function 'jao-browse-with-external-browser)
+
(defun jao--browse-doc (url search &optional no-add)
(let* ((url (substring-no-properties url))
(file (jao--fln url)))
@@ -2219,42 +2192,28 @@
(set-process-sentinel (jao--run "see" file)
(jao--browse-sentinel url))))))
- (defun jao--browse-music (url &rest r)
- (when (string-match "music:\\(.+\\)" url)
- (let ((path (match-string-no-properties 1 url)))
- (cond ((file-directory-p path) (emms-play-directory-tree path))
- ((file-exists-p path) (emms-play-file path))))))
+ (defun jao--make-file-rx (exts)
+ (format "file:/?/?.+\\.%s$" (regexp-opt exts)))
+
+ (setq jao--see-exts
+ (jao--make-file-rx '("jpg" "jpeg" "png" "mov" "wmv" "avi" "mp4")))
+
+ (setq jao--doc-exts
+ (jao--make-file-rx '("ps" "ps.gz" "pdf" "dvi" "djvu" "chm")))
+
+ (defun jao--see (url &rest r) (jao--run "see" url))
(setq browse-url-handlers
- (jao-d-l
- `(("^file://?.+\\.htm[l]?\\'" . ,jao-browse-url-function)
- ("^file://?" . (lambda (url &rest r)
- (find-file-other-window (jao--fln url))))
- ("^info://" . (lambda (url &rest r)
- (info-other-window (jao--fln url))))
- ("^https?://.+" . ,jao-browse-url-function)
- ("." . jao--open))
-
- `((,jao--doc-exts . jao--browse-doc)
- (,jao--see-exts . jao--see)
- ("^file://?.+\\.htm[l]?\\'" . ,jao-browse-url-function)
- ("^file://?" . (lambda (url &rest r)
- (find-file-other-window (jao--fln url))))
- ("^info://" . (lambda (url &rest r)
- (info-other-window (jao--fln url))))
- ("^https?://bigml\\.slack\\..*" . browse-url-generic)
- ("^https?://github\\.com/.*issues.*" .
- ,jao-browse-url-external-function)
- ("^https?://.*\\.gotomeeting\\.com\\.*" . browse-url-chrome)
- ("^https?://meet\\.google\\.com\\.*" .
- ,jao-browse-url-external-function)
- (,(jao-wget--regexp) . jao-wget)
- ("^mailto:.+" . browse-url-mail)
- (,jao-video--url-rx . jao-maybe-view-video)
- ("." . ,jao-browse-url-function))))
-
- ;; (setq browse-url-browser-function 'browse-url-firefox)
- ;; (setq browse-url-handlers nil)
+ `((,jao--doc-exts . jao--browse-doc)
+ (,jao--see-exts . jao--see)
+ ("^file://?.+\\.htm[l]?\\'" . ,jao-browse-url-function)
+ ("^file://?" . (lambda (url &rest r)
+ (find-file-other-window (jao--fln url))))
+ ("^https?://.*\\.slack\\..*" . ,jao-browse-url-external-function)
+ ("^https?://.*\\.gotomeeting\\.com\\.*" . browse-url-chrome)
+ ("^https?://meet\\.google\\.com\\.*" . ,jao-browse-url-external-function)
+ (,(jao-wget--regexp) . jao-wget)
+ ("." . ,jao-browse-url-function)))
(setq browse-url-browser-function jao-browse-url-function)