(require 'w3m) (require 'file-write-to) ;; use this with ~/.zsh/download (defun write-dl-URL (&optional url append) (let*((the-url (or url (w3m-anchor))) (dl-file "~/.w3m/dl_URL.txt") (url-newline (format "%s\n" the-url)) ) (when (and (file-exists-p dl-file) (not append) ) (delete-file dl-file)) (append-to-file url-newline nil ; ignored dl-file) )) (defun w3m-img-at-point-p () (w3m-url-valid (w3m-image))) (defun w3m-dl-str-p (s) (and s (or (string-match-p "^magnet:" s) (string-match-p "^https*://www.youtube.com" s) ))) (defun w3m-dl-dwim (&optional prefer-link-or-append) (interactive "P") (let*((image (w3m-img-at-point-p)) (link-str (w3m-anchor)) (special-link (w3m-dl-str-p link-str)) (url (thing-at-point 'url)) (special-url (w3m-dl-str-p url)) ) (cond (special-link (write-dl-URL link-str prefer-link-or-append)) (special-url (write-dl-URL url prefer-link-or-append)) ((and link-str (or prefer-link-or-append (not image))) (w3m-download link-str)) (image (w3m-download-this-image)) (url (w3m-download url)) (t (w3m-download w3m-current-url)) ))) (defalias 'download 'w3m-dl-dwim) (defalias 'dl 'w3m-dl-dwim) (provide 'dl)