diff options
-rw-r--r-- | init.el | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -1428,29 +1428,28 @@ ;;;; downloads using wget (defun jao-wget--get-title (filename) - (let ((fn (file-name-base filename))) - (if (string-blank-p fn) - (plist-get eww-data :title) - (subst-char-in-string ?- ? (capitalize fn))))) + (or (plist-get eww-data :title) + (and (not (string-blank-p (or filename ""))) + (subst-char-in-string ?- ? (capitalize (file-name-base filename)))))) (defun jao-wget (url &optional user pwd) - "Download URL using wget." + "Download URL using wget and kill a link for an org note." (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-sink-dir nil nil def))) (title (jao-wget--get-title dest)) - (src-url (jao-url-around-point t)) + (src-url (or (jao-url-around-point t) (file-name-directory url))) (auth (when (and user pwd) `(,(format "--http-user=%s" user) - ,(format "--http-password=%s" pwd))))) + ,(format "--http-password=%s" pwd)))) + (lnk (concat "doc:" (file-name-nondirectory dest)))) (switch-to-buffer-other-window (get-buffer-create "*downloads*")) (erase-buffer) - (kill-new (format "[[doc:%s][%s]] (from [[%s][here]])" - (file-name-nondirectory dest) - (read-string "Title: " title) - (or src-url (file-name-directory url)))) + (kill-new (format "%s (from %s)" + (org-link-make-string lnk title) + (org-link-make-string src-url "here"))) (apply 'make-term `("downloads" "wget" nil ,@auth "-O" ,dest ,url)))) (defun jao-download (url &optional pws) |