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 MErHIu6kD18oLQAA0tVLHw (envelope-from ) for ; Thu, 16 Jul 2020 00:53:02 +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 QN64Hu6kD19jbAAAB5/wlQ (envelope-from ) for ; Thu, 16 Jul 2020 00:53:02 +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 008639401CB for ; Thu, 16 Jul 2020 00:53:02 +0000 (UTC) Received: from localhost ([::1]:45762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jvs8y-0007Nm-LQ for larch@yhetil.org; Wed, 15 Jul 2020 20:53:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvs8Z-0007Nc-Lx for emacs-orgmode@gnu.org; Wed, 15 Jul 2020 20:52:35 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:43394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jvs8X-0003pp-PO; Wed, 15 Jul 2020 20:52:35 -0400 Received: by mail-pf1-x444.google.com with SMTP id a24so2875679pfc.10; Wed, 15 Jul 2020 17:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=q9FTC6vH7nqoC4a3ImVyNmIvUjcclpncGe8DNAEOyso=; b=Mp80AQG+FMIxfRVbVjFqGlXBydOBDlYrCbGj5kcBgjE1wkLU/9Tb7iBFoJWjb1EdiN QdqQE8SrDjd4maUb77iLsVxLADbuOJUe0SyTTj2NY7a/eLwK2tSfnCwRRVGU1xdDO+95 nMRaUTe8N9ANR309iSe7hy6ZWD8mXFv3AZnASnYvohuB3Tnu5gGR/uxFXslG55/y1GF/ Zh86CwpL8UiYyPwJTNfpLK9ElF9O9vaorQtPmLv5f/K7NmQ+84FYCr+BWM2Cc2cKB4Rl QpAgpDtnf5YmF59G/aiBiLhx3Fpa+cY3gAIAxruL33ogrr9UIOeUE2kshWykUb5Zu6XR Oa3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=q9FTC6vH7nqoC4a3ImVyNmIvUjcclpncGe8DNAEOyso=; b=DKIHyiG2Lubt+g5IzCAVKe66Rqusvg7wxcx9xfPqWScEtA15zM/wTKlnNk3n6iDxmI +tDnDzSTVKeaM/gdafwD0TCXZ6ORl6/mm/hTHq2Srzl4MY6AVnEyB+jzSNigkE3QxOOE ntGUBSxCKJG8kc0VNtMRpSWrReto/4GRdYF0/fEU3LHupAmv1Nvpk8QtB3sLK/U3p6YG dXTU2DPgfSFSgtjz5kr8XGr86Q26836ksc7koEBOCdLOIH6dyeJbvr4kXl1zkAOQcK/M QLO8+jeDpv2jEhwafX7AYwJ98rcWvKdtWMpnimw6/OW6VTvug6JbidGaJE8HurJSSI7R 1OIQ== X-Gm-Message-State: AOAM532q7PvD8bxoxqa7wiH+SC51ewvZcSJl+TGrlX59nnaozrzryluZ JZN8ItrLtRVs+L6+WtF2qw4= X-Google-Smtp-Source: ABdhPJxQqDcBq4WSqySXgnw8gb4wuEz0XNlM91x8GFkx7wNj38ThfY0Cr225tg88LtotLv2kaIS+Mg== X-Received: by 2002:aa7:810c:: with SMTP id b12mr1609835pfi.69.1594860751875; Wed, 15 Jul 2020 17:52:31 -0700 (PDT) Received: from localhost ([103.234.38.162]) by smtp.gmail.com with ESMTPSA id 127sm3405289pgf.5.2020.07.15.17.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2020 17:52:30 -0700 (PDT) From: Ihor Radchenko To: numbchild@gmail.com, Bastien Subject: Re: [QUESTION] Re: [PATCH] make org-attach-url download function as an option In-Reply-To: <87sgdt5esh.fsf@gmail.com> References: <87zhaupfl6.fsf@gmail.com> <87pnatl9ek.fsf@bzg.fr> <87sgdt5esh.fsf@gmail.com> Date: Thu, 16 Jul 2020 08:52:02 +0800 Message-ID: <878sfkmgct.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=yantar92@gmail.com; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , 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=pass header.d=gmail.com header.s=20161025 header.b=Mp80AQG+; dmarc=pass (policy=none) header.from=gmail.com; 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: -1.21 X-TUID: 4ea2fEmCJ4n2 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. 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 > -- Ihor Radchenko, PhD, Center for Advancing Materials Performance from the Nanoscale (CAMP-nano) State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg