From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id kP16HwTHDl9jUAAA0tVLHw (envelope-from ) for ; Wed, 15 Jul 2020 09:06:12 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 5B1jGwTHDl/7PgAA1q6Kng (envelope-from ) for ; Wed, 15 Jul 2020 09:06:12 +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 DE7039403AB for ; Wed, 15 Jul 2020 09:06:11 +0000 (UTC) Received: from localhost ([::1]:60216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jvdMf-00020W-21 for larch@yhetil.org; Wed, 15 Jul 2020 05:06:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvdMH-0001yR-Dl for emacs-orgmode@gnu.org; Wed, 15 Jul 2020 05:05:45 -0400 Received: from [183.249.139.74] (port=11140 helo=localhost) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jvdMF-0001YZ-E8 for emacs-orgmode@gnu.org; Wed, 15 Jul 2020 05:05:45 -0400 Received: by localhost (Postfix, from userid 1000) id 41489241411; Wed, 15 Jul 2020 17:05:34 +0800 (CST) References: <87zhaupfl6.fsf@gmail.com> <87pnatl9ek.fsf@bzg.fr> User-agent: mu4e 1.5.5; emacs 28.0.50 From: stardiviner To: Bastien Subject: [QUESTION] Re: [PATCH] make org-attach-url download function as an option In-reply-to: <87pnatl9ek.fsf@bzg.fr> Date: Wed, 15 Jul 2020 17:05:34 +0800 Message-ID: <87sgdt5esh.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=localhost X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/15 05:05:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 67 X-Spam_score: 6.7 X-Spam_bar: ++++++ X-Spam_report: (6.7 / 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_LOCALHOST=3.828, 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: reject 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: 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: a5scjbGVvQwY 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