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 UC8wCv/gEF9fDgAA0tVLHw (envelope-from ) for ; Thu, 16 Jul 2020 23:21:35 +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 KG4OBv/gEF9xGAAA1q6Kng (envelope-from ) for ; Thu, 16 Jul 2020 23:21:35 +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 9F6D3940429 for ; Thu, 16 Jul 2020 23:21:34 +0000 (UTC) Received: from localhost ([::1]:34018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwDC1-0000ht-23 for larch@yhetil.org; Thu, 16 Jul 2020 19:21:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwDBS-0000ga-C2 for emacs-orgmode@gnu.org; Thu, 16 Jul 2020 19:20:58 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:50730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jwDBQ-0002aj-Fb; Thu, 16 Jul 2020 19:20:58 -0400 Received: by mail-pj1-x1043.google.com with SMTP id k71so5596257pje.0; Thu, 16 Jul 2020 16:20:55 -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=Te9p1TAHtVYOp52hkmpaFJgwksOQqE0mYdXun0OGIA0=; b=rtzs5PPAzYkEb3Rr1e1zahWXClSOEQBZljenoeARidXlZ8kuQJ5KqTqu/2U//4oa94 LvKgfFBaJff0Zwu2N4CS3Vcbetn98G2NP3R2Xnajw6oZjitywouqu36DtNsD88sTDTln KpyBn18MEE2+P2oFGOWZh9sr64mDVfUmlV6G3O/3vPdhkD0EnW9vnK32NIy3FDD4c7Xd v6gZIjZi2Im8JI5cIX03x63oVsUQZzW/9GlSvQRDhcyVDJ1w+41eCob3pRmRrZ5WPy1h sEYHCeGSUCqBxGjAMkz8qOpUdsHDD2B6EAlNcMyitKmSBbTjUgB9hn+kTdHwPsH4feZ7 828Q== 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=Te9p1TAHtVYOp52hkmpaFJgwksOQqE0mYdXun0OGIA0=; b=rc/aeMhqrDiCqRtB06b61xX5GAT5UgOeRHIaH5QSw9aS2XNH7BpPqGFQ96YQmZi9JZ UjIqZO8S85tTa40Hr/xHuPqAKXAZYeUlYVe7E9luCTvL7jrZPnGfpr5yudvLOzcyiI0d r5hDNgEc00PiuAASgMEIBBMS1CYKzCL53xvDS/lkRnZctpLsxD6+Y1TkqRs3pjAK/T4q pAKXTlnpsYlNUKAQ9gAUr5D6l7THd5qRQSixhr9/n6FqcGKLxPJrGBdOzkcRdwbZ+2Io bsogOmKUfK0dWBo6o02402H/OpFqYO8C+GUgq5fNeh2IgvUOI+/YYCIUK0vlJ1vcVv87 RJHg== X-Gm-Message-State: AOAM533AuVAu7oxjTmK5EEq4+jDrPpo3KUiRrqHWSTpmVNfvkZ3eUUWE JuF9uVYV6t7Z8ZVCVsJqFPk= X-Google-Smtp-Source: ABdhPJxkGFY4UVy5uSoyvjkhn4KsIadGVgaLaCBjx9/ezRjoN2QqjbPLE/eak30u81CLrQQcZn8Dvw== X-Received: by 2002:a17:90a:6acb:: with SMTP id b11mr7093721pjm.71.1594941654338; Thu, 16 Jul 2020 16:20:54 -0700 (PDT) Received: from localhost ([101.99.64.65]) by smtp.gmail.com with ESMTPSA id w4sm5668621pfd.39.2020.07.16.16.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 16:20:53 -0700 (PDT) From: Ihor Radchenko To: numbchild@gmail.com Subject: Re: [QUESTION] Re: [PATCH] make org-attach-url download function as an option In-Reply-To: <87blkf5avo.fsf@gmail.com> References: <87zhaupfl6.fsf@gmail.com> <87pnatl9ek.fsf@bzg.fr> <87sgdt5esh.fsf@gmail.com> <878sfkmgct.fsf@localhost> <87blkf5avo.fsf@gmail.com> Date: Fri, 17 Jul 2020 07:20:27 +0800 Message-ID: <875zankpxg.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1043.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: 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=pass header.d=gmail.com header.s=20161025 header.b=rtzs5PPA; 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: 0.29 X-TUID: a9uRPihC+WGY > 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? You can wrap the call to org-attach-url-function into with-mutex and run hooks in another thread ustilising the same mutex. Note that the heading contents (including :DIR: property), point, current buffer, and window might be changed at the time the hook thread will be called. You will need to perform some sanity checks and potentially cleanup after org-attach-url-function if the heading was modified in some undesired way. The above assumes that org-attach-url-function returns after the file is attached. This might not be the case if org-attach-url-function calls async shell command. This should be either documented or also handled in some way. Best, Ihor stardiviner writes: > 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 > -- 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