From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id PwT8KNLaEF/zSwAA0tVLHw (envelope-from ) for ; Thu, 16 Jul 2020 22:55:14 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 2HRcJNLaEF/bLwAAB5/wlQ (envelope-from ) for ; Thu, 16 Jul 2020 22:55:14 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.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 24B649400BB for ; Thu, 16 Jul 2020 22:55:14 +0000 (UTC) Received: from localhost ([::1]:52652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwCmV-0002hc-T4 for larch@yhetil.org; Thu, 16 Jul 2020 18:55:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwCm5-0002hS-Tx for emacs-orgmode@gnu.org; Thu, 16 Jul 2020 18:54:45 -0400 Received: from [183.249.139.74] (port=10804 helo=dark) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwCm3-0007Dk-Rv; Thu, 16 Jul 2020 18:54:45 -0400 Received: by dark (Postfix, from userid 1000) id 7586524185A; Fri, 17 Jul 2020 06:54:35 +0800 (CST) References: <87zhaupfl6.fsf@gmail.com> <87pnatl9ek.fsf@bzg.fr> <87sgdt5esh.fsf@gmail.com> <878sfkmgct.fsf@localhost> User-agent: mu4e 1.5.5; emacs 28.0.50 From: stardiviner To: Ihor Radchenko Subject: Re: [QUESTION] Re: [PATCH] make org-attach-url download function as an option In-reply-to: <878sfkmgct.fsf@localhost> Date: Fri, 17 Jul 2020 06:54:35 +0800 Message-ID: <87blkf5avo.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-Host-Lookup-Failed: Reverse DNS lookup failed for 183.249.139.74 (deferred) Received-SPF: softfail client-ip=183.249.139.74; envelope-from=numbchild@gmail.com; helo=dark X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/16 18:54:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 38 X-Spam_score: 3.8 X-Spam_bar: +++ X-Spam_report: (3.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, FSL_HELO_NON_FQDN_1=0.001, HELO_NO_DOMAIN=1, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_XBL=0.375, RDNS_NONE=0.793, SPF_SOFTFAIL=0.665, SPOOFED_FREEMAIL_NO_RDNS=1 autolearn=no autolearn_force=no X-Spam_action: no action 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 Cc: Bastien , Org Mode Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 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 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 2.39 X-TUID: nrTXV3ixhBaO Ihor Radchenko writes: > I do not know an answer to your question, but would like to point out > that make-thread will return immidietealy and all the following code > will run before the download finishes: > > (run-hook-with-args 'org-attach-after-change-hook attach-dir) > (org-attach-tag) > (cond ((eq org-attach-store-link-p 'attached)... > > At least the hooks and org-attach-tag would expect that the file is > attached already. Indeed, as long as org-attach introduced new async actions. Those hooks will have problem if they requires files is downloading finished. Also `make-thread' does not have process sentinel. That's also an problem. Does anyone have better idea? > > Best, > Ihor > > stardiviner writes: > >> I got solution for async org-attach-url now. Use `make-thread` for async >> downloading is simple. >> >> Here is the code prototype, but it has a problem, seems `apply` part code does >> not really downloading file. I don't know why. Does anybody knows the reason? >> >> #+begin_src diff >> modified lisp/org-attach.el >> @@ -110,6 +110,12 @@ (defcustom org-attach-method 'cp >> (const :tag "Hard Link" ln) >> (const :tag "Symbol Link" lns))) >> >> +(defcustom org-attach-url-function 'url-copy-file >> + "The download file function to use in org-attach-url." >> + :type '(choice (const 'url-copy-file)) >> + :safe #'functionp >> + :group 'org-attach) >> + >> (defcustom org-attach-expert nil >> "Non-nil means do not show the splash buffer with the attach dispatcher." >> :group 'org-attach >> @@ -503,7 +509,12 @@ (defun org-attach-attach (file &optional visit-dir method) >> ((eq method 'cp) (copy-file file attach-file)) >> ((eq method 'ln) (add-name-to-file file attach-file)) >> ((eq method 'lns) (make-symbolic-link file attach-file)) >> - ((eq method 'url) (url-copy-file file attach-file))) >> + ((eq method 'url) (make-thread >> + (lambda () >> + ;; (url-copy-file file attach-file) >> + ;; FIXME This seems does not really download file. Don't know why. >> + (apply org-attach-url-function '(file attach-file))) >> + "org-attach-url downloading"))) >> (run-hook-with-args 'org-attach-after-change-hook attach-dir) >> (org-attach-tag) >> (cond ((eq org-attach-store-link-p 'attached) >> #+end_src >> >> Bastien writes: >> >>> Hi, >>> >>> stardiviner writes: >>> >>>> 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. >>> >>> Indeed, this might be annoying. At the same time, it is not >>> unreasonable to expect the user to know what size is the contents he >>> is willing to attach to an Org node. >>> >>>> 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. >>> >>> (FWIW, I could not find the patch.) >>> >>> I think you are on the right track when trying to enhance the 'url >>> package. Maybe url-copy-file should be asynchronous and url could >>> provide url-copy-file-synchronously (to mimic the url-retrieve and >>> url-retrieve-synchronously pair)? >>> >>> Until Emacs has a function to copy a URL's contents asynchronously, >>> I'd rather not add this functionality in Org. >> >> >> -- >> [ 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 >> -- [ 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