emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: stardiviner <numbchild@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] make org-attach-url download function as an option
Date: Mon, 25 May 2020 08:12:10 +0800	[thread overview]
Message-ID: <87367ohnz9.fsf@gmail.com> (raw)
In-Reply-To: <87pnatl9ek.fsf@bzg.fr>

[-- Attachment #1.1: Type: text/plain, Size: 2135 bytes --]

Bastien <bzg@gnu.org> writes:

> Hi,
> stardiviner <numbchild@gmail.com> 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.

It's not the URL file size problem, sometime network is bad. I meet some
situations like downloading 1M file might use 5 minutes. Not 1M file or 1G file

>> 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.)

Aha, I forgot the patch. I attached now. The patch does not provide an async
function to download. Just provide an easy way for user to use other async

> 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)?

Actually I did check out url-copy-file-synchronously source code, try to mimic
an async version function. But seems I can't implement it. I will post an email
to Emacs-dev mailing list whether this can be improved.

> Until Emacs has a function to copy a URL's contents asynchronously,
> I'd rather not add this functionality in Org.

Emacs async functionality is always bad. Waiting for Emacs get better async
support might need a very long time.

I still think simply provide an simple entry for user to change downloading
function is a simpler option. WDYT?

[ 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-lisp-org-attach.el-support-custom-url-file-downloadi.patch --]
[-- Type: text/x-patch, Size: 1673 bytes --]

From 61e26e148e68deb03f26dddb2a88beae5b6869f7 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Wed, 29 Apr 2020 21:38:34 +0800
Subject: [PATCH] lisp/org-attach.el: support custom url file downloading

lisp/org-attach.el (org-attach-url-function): make download function as
a defcustom option. So that user can use async function or other
functions instead.
 lisp/org-attach.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 57d1360fc..e33551f40 100644
--- a/lisp/org-attach.el
+++ b/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
@@ -504,7 +510,7 @@ (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) (apply org-attach-url-function file (list attach-file))))
       (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (cond ((eq org-attach-store-link-p 'attached)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 515 bytes --]

  reply	other threads:[~2020-05-25  0:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29 13:49 [PATCH] make org-attach-url download function as an option stardiviner
2020-05-24 14:01 ` Bastien
2020-05-25  0:12   ` stardiviner [this message]
2020-07-15  9:05   ` [QUESTION] " stardiviner
2020-07-16  0:52     ` Ihor Radchenko
2020-07-16 22:54       ` stardiviner
2020-07-16 23:20         ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87367ohnz9.fsf@gmail.com \
    --to=numbchild@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).