emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Kaushal Modi <kaushal.modi@gmail.com>
Cc: emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: Allow #+SETUPFILE to point to an URL for the org file
Date: Fri, 26 May 2017 09:47:52 +0200	[thread overview]
Message-ID: <87o9ug83fb.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <CAFyQvY3WuEvBjMHWW4KQKOjD=Ky_0E9zo+BJYo1jbz-z_pyyTg@mail.gmail.com> (Kaushal Modi's message of "Thu, 25 May 2017 15:15:47 +0000")

Hello,

Kaushal Modi <kaushal.modi@gmail.com> writes:

> I have attached an updated and rebased patch with most of your suggestions
> implemented.

Thank you.

>> Here is my use case for org-file-clear-cache:
>>
>> Let's say I have a file where I have a SETUPFILE retrieved from a URL. Now
>> the upstream version changes but my cache is still on the older version. So
>> I need to clear the hash. The org-file-clear-cache simply does that.

I understand the use case for `org-file-clear-cache'. My suggestion is
to remove that need by clearing cache automatically. Of course, the
drawback is the cache is cleared more often than necessary. Users could
get very surprising results if they forget to call this function. So it
might be a good idea to call it from time to time, on user's behalf.

> I grepped org.texi but found no reference of org-file-contents. So may be
> we need to add a section for that, and there I can explain
> org-file-clear-cache in more detail. What would be a good node for
> that?

`org-file-contents' is a developer-facing function. I don't really see
a good place in the manual for it. That's the problem of
`org-file-clear-cache', which is really an implementation detail users
shouldn't care about.

Here's another idea: call it from `org-mode-restart'. So cache is reset
whenever `C-c C-c' is pressed on a keyword. So we don't need to document
the function anymore. Instead, we could drop a note about the cache in
(info "(org) The very busy C-c C-c key").

>>           (if (re-search-forward "HTTP.*\\s-+200\\s-OK" nil t)
>>>               ;; URL retrieved correctly.  Move point to after the
>>>               ;; url-retrieve header, update the cache `org--file-cache'
>>>               ;; and return contents.
>>>               (progn
>>>                 (search-forward "\n\n" nil 'move)
>>
>>
> I have integrated most of your refactored version except for this portion.
> Above will do a false match if that "HTTP.." string is present in the FILE
> body too! I have retained my version of only that part where the search
> happens only inside the url-retrieve header. The search is also faster in
> the case of failure as it does not have to search through the whole file
> before declaring a fail.. as only the header is searched.

OK. Then the following at least doesn't have the overhead of creating
a string:


(with-current-buffer (url-retrieve-synchronously file)
  (goto-char (point-min))
  ;; Move point to after the url-retrieve header.
  (search-forward "\n\n" nil 'move)
  ;; Search for the success code only in the url-retrieve header.
  (if (save-excursion (re-search-backward "HTTP.*\\s-+200\\s-OK" nil t))
      ;; Update the cache `org--file-cache' and return contents.
      (puthash file
               (buffer-substring-no-properties (point) (point-max))
               org--file-cache)
    (funcall (if noerror #'message #'user-error)
             "Unable to fetch file from %S"
             file)))

Also, mind the full stop at the end of the comments.

Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2017-05-26  7:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-03 17:23 Allow #+SETUPFILE to point to an URL for the org file Kaushal Modi
2016-12-08 11:51 ` Kaushal Modi
2016-12-08 14:22   ` John Kitchin
2016-12-08 14:31   ` Nicolas Goaziou
2016-12-08 14:44     ` Kaushal Modi
2016-12-08 21:48       ` Nicolas Goaziou
2016-12-08 22:07         ` Kaushal Modi
2016-12-08 22:40           ` Nicolas Goaziou
2017-03-13 17:37             ` Kaushal Modi
2017-03-30  7:43               ` Nicolas Goaziou
2017-05-23 19:07                 ` Kaushal Modi
2017-05-25 10:13                   ` Nicolas Goaziou
2017-05-25 10:18                     ` Nicolas Goaziou
2017-05-25 11:43                     ` Kaushal Modi
2017-05-25 15:15                       ` Kaushal Modi
2017-05-26  7:47                         ` Nicolas Goaziou [this message]
2017-05-26 20:24                           ` Kaushal Modi
2017-05-28  7:35                             ` Nicolas Goaziou
2017-05-28 10:04                               ` Kaushal Modi
2017-06-09 16:59                               ` Kaushal Modi
2017-06-12 19:32                                 ` Kaushal Modi
2017-06-13 12:43                                   ` Nicolas Goaziou
2017-06-13 15:45                                     ` Kaushal Modi
2017-06-13 21:32                                       ` Nicolas Goaziou
2017-06-13 21:42                                         ` Kaushal Modi

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=87o9ug83fb.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=kaushal.modi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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