From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oEi8KLqIqV44ewAA0tVLHw (envelope-from ) for ; Wed, 29 Apr 2020 14:01:30 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id gGfuLsOIqV6fVAAAbx9fmQ (envelope-from ) for ; Wed, 29 Apr 2020 14:01:39 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 404F594220E for ; Wed, 29 Apr 2020 14:01:32 +0000 (UTC) Received: from localhost ([::1]:56852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTnHH-0002Gf-MD for larch@yhetil.org; Wed, 29 Apr 2020 10:01:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42242) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTnGC-00027T-HW for emacs-orgmode@gnu.org; Wed, 29 Apr 2020 10:00:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTnCt-0002cH-S1 for emacs-orgmode@gnu.org; Wed, 29 Apr 2020 10:00:24 -0400 Received: from [183.249.139.183] (port=1605 helo=dark.localdomain) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTnCs-0002Wr-FB for emacs-orgmode@gnu.org; Wed, 29 Apr 2020 09:56:59 -0400 Received: by dark.localdomain (Postfix, from userid 1000) id F1E362412B6; Wed, 29 Apr 2020 21:49:09 +0800 (HKT) User-agent: mu4e 1.4; emacs 28.0.50 From: stardiviner To: Org Mode Subject: [PATCH] make org-attach-url download function as an option Date: Wed, 29 Apr 2020 21:49:09 +0800 Message-ID: <87zhaupfl6.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: softfail client-ip=183.249.139.183; envelope-from=numbchild@gmail.com; helo=dark.localdomain X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 09:49:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 183.249.139.183 X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: numbchild@gmail.com Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: 1.59 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Scan-Result: default: False [1.59 / 13.00]; HAS_REPLYTO(0.00)[numbchild@gmail.com]; GENERIC_REPUTATION(0.00)[-0.49333789600058]; DWL_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; FREEMAIL_FROM(0.00)[gmail.com]; REPLYTO_ADDR_EQ_FROM(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[5]; FROM_NEQ_ENVFROM(0.00)[numbchild@gmail.com,emacs-orgmode-bounces@gnu.org]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[doubanio.com:url,stardiviner.github.io:url]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_REPLYTO(0.00)[gmail.com]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.18), country: US(-0.00), ip: 2001:470:142::17(-0.49)]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; DNSWL_BLOCKED(0.00)[2001:470:142::17:from]; MIME_TRACE(0.00)[0:+]; FORGED_SENDER_MAILLIST(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none] X-TUID: 1XEiwzFsR54U =2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 I found when network is bad and slow, or the download file is big, the org-attach-url will suspend Emacs for a long time. User might have to cancel downloading, and start again later. I hope to make "org-attach-url" download file asynchronously. But function org-attach-attach hardcoded this function for 'url method. Here is a patch = to make it into an option. So user can specify a custom function to download f= ile. # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D BTW, I'm wandering why function "url-retrieve" download file is not complet= e and failed. Bellowing code snippets are my try: Use function ~url-copy-file~ works fine: #+begin_src emacs-lisp :eval no (url-copy-file "https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2592521688.we= bp" (expand-file-name "~/kk.webp")) #+end_src I check out function ~url-copy-file~ implement, try to implement an async v= ersion like this: #+begin_src emacs-lisp (defun url-copy-file-asynchronous (url newname &optional ok-if-already-exis= ts &rest _ignored) "Copy URL to NEWNAME. Both arguments must be strings. Signal a `file-already-exists' error if file NEWNAME already exists, unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. An integer as third argument means request confirmation if NEWNAME already exists." (and (file-exists-p newname) (or (not ok-if-already-exists) (and (integerp ok-if-already-exists) (not (yes-or-no-p (format "File %s already exists; copy to it anyway? " newname))))) (signal 'file-already-exists (list "File already exists" newname))) (let* ((buffer (or (url-retrieve url (lambda (&rest ignored))) (signal 'file-missing (list "Opening URL" "No such file or directory" url)))) (handle (with-current-buffer buffer (mm-dissect-buffer t)))) (let ((mm-attachment-file-modes (default-file-modes))) (mm-save-part-to-file handle newname)) (kill-buffer buffer) (mm-destroy-parts handle))) (put 'copy-file 'url-file-handlers #'url-copy-file-asynchronous) #+end_src #+begin_src emacs-lisp (url-copy-file-asynchronous "https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2592521688.we= bp" (expand-file-name "~/kk.webp")) #+end_src But it download seems incomplete and failed. Don't know why. Also there are extra async libraries support download file asynchronously. = Like "deferred", "async" etc. Those libraries can be used for user define their = own functions. Is you have better idea, please tell me, thanks in advance. =2D --=20 [ stardiviner ] I try to make every word tell the meaning that I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 =20=20=20=20=20=20 =2D----BEGIN PGP SIGNATURE----- iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl6phdUUHG51bWJjaGls ZEBnbWFpbC5jb20ACgkQG13xyVromsNswQgAjuFtM/+WU0EXdpQOx3C4kymgUTex jEZgw96JlfHSP3JcoOuA5Ll2F+nXShWwIeGJAe1aRgjLTy9O5XSZO6BdlxoN2QRB RfrZvl5X5cJu9NIyiwhSYbIMM8+DJKHSp/nBGIimXwDoNU/ye43E4OmApVKfWjf0 TmMXUzLnXWSxdSubFe/M7SEGUaarFI5y2bNwytBMOQr7q1yY6UgynlB6Vda06mqb BO/AnJgYtP69XvghK14NJ6/X8nol5oFijLtt67QUNKBCdUlp3tx/G+6lFebGruHS kZ6PjTzoAwZOk5l7lTx9mG+dle1g/7rNce1TRVFP+cT1+qS5+7UHhwfnwg=3D=3D =3DpYDj =2D----END PGP SIGNATURE-----