;;; -*- lexical-binding: t -*- ;;; ;;; this file: ;;; http://user.it.uu.se/~embe8573/emacs-init/w3m/dl.el ;;; https://dataswamp.org/~incal/emacs-init/w3m/dl.el ;;; ;;; use with: ;;; https://dataswamp.org/~incal/conf/.zsh/download (require 'file-write-to) (require 'w3m) (defun write-dl-URL (&optional url append) (let*((the-url (or url (w3m-anchor))) (dl-file (getenv "DL_FILE")) (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)