diff options
author | jao <jao@gnu.org> | 2021-03-26 22:44:17 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2021-03-26 22:44:17 +0000 |
commit | b0f89825a5958a33c5222caaf6b9d09f904f6ead (patch) | |
tree | 1caf1c61bf4c6af111dfbcf16ecdaef7a20a016f | |
parent | 288f5e293d1952707d81037409da2f6011c4a81d (diff) | |
download | elibs-b0f89825a5958a33c5222caaf6b9d09f904f6ead.tar.gz elibs-b0f89825a5958a33c5222caaf6b9d09f904f6ead.tar.bz2 |
browse-url clean ups
-rw-r--r-- | init.org | 71 |
1 files changed, 38 insertions, 33 deletions
@@ -2141,28 +2141,19 @@ '((height . 55))))) (find-file (jao--fln url))) - (defun jao-wget--get-title (filename) - (let ((fn (file-name-sans-extension (file-name-nondirectory filename)))) - (subst-char-in-string ?- ? (capitalize fn)))) - (defun jao--url-prompt () - (let* ((def (jao-url-around-point)) - (prompt (concat "URL" - (if def (format " (%s): " def) ": ")))) + (let* ((def (jao-url-around-point t)) + (prompt (concat "URL" (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-wget--regexp () - (concat "^http[s]?://.+\\(\\." - (mapconcat 'identity jao-browse-url-wget-exts "\\|\\.") - "\\)\\'")) + (defun jao-wget--get-title (filename) + (let ((fn (file-name-sans-extension filename))) + (if (string-blank-p fn) + (plist-get eww-data :title) + (subst-char-in-string ?- ? (capitalize fn))))) (defun jao-wget (url &optional user pwd &rest ignored) "Download URL using wget." @@ -2171,19 +2162,18 @@ (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))))) + (title (jao-wget--get-title dest)) + (src-url (jao-url-around-point t)) + (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))))) + (kill-new (format "[[doc:%s][%s]] (from [[%s][here]])" + (file-name-nondirectory dest) + (read-string "Title: " title) + (or src-url (file-name-directory url)))) (apply 'make-term `("downloads" "wget" nil ,@auth "-O" ,dest ,url)))) (defun jao-download (url &optional pws) @@ -2202,9 +2192,15 @@ #+BEGIN_SRC emacs-lisp (defvar jao-video--url-rx (format "^https?://\\(?:www\\.\\)?%s/.+" - (regexp-opt '("youtube.com" "blip.tv" "vimeo.com" "infoq.com") + (regexp-opt '("youtu.be" + "youtube.com" + "blip.tv" + "vimeo.com" + "infoq.com") t))) + (defun jao-video--url-p (url) (string-match-p jao-video--url-rx url)) + (defun jao--remote-run (url prg) (let ((args (format "%s %s" prg (shell-quote-argument url)))) (start-process-shell-command prg nil args))) @@ -2256,27 +2252,36 @@ (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"))) + (defvar jao--see-exts + (jao--make-file-rx '("jpg" "jpeg" "png" "mov" "wmv" "avi" "mp4"))) + + (defvar jao--doc-exts + (jao--make-file-rx '("ps" "ps.gz" "pdf" "dvi" "djvu" "chm"))) + + (defvar jao-browse-url-wget-exts + '("ps" "pdf" "dvi" "djvu" "zip" "gz" "tgz" "mp4" "mp3" "flv")) - (setq jao--doc-exts - (jao--make-file-rx '("ps" "ps.gz" "pdf" "dvi" "djvu" "chm"))) + (defun jao-wget--regexp () + (concat "^http[s]?://.+\\(\\." + (mapconcat 'identity jao-browse-url-wget-exts "\\|\\.") + "\\)\\'")) (defun jao--see (url &rest r) (jao--run "see" url)) (setq browse-url-handlers `((,jao--doc-exts . jao--browse-doc) (,jao--see-exts . jao--see) - ("^file://?.+\\.htm[l]?\\'" . ,jao-browse-url-function) + ("^file://?.+\\.html?$" . ,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-video--url-p . jao-maybe-view-video) ("." . ,jao-browse-url-function))) - (setq browse-url-browser-function jao-browse-url-function) + (setq browse-url-browser-function 'browse-url-default-browser) #+END_SRC *** Subscribe rss using r2e |