emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH v2] org-attach.el: ID to path functions may return nil
Date: Mon, 14 Nov 2022 23:59:52 +0700	[thread overview]
Message-ID: <3326940f-f7a8-37f6-2dc2-f1f035f4c491@gmail.com> (raw)
In-Reply-To: <87sfimfc2p.fsf@localhost>

On 14/11/2022 10:29, Ihor Radchenko wrote:
> 
> I went through the patch and tried to clarify the wording.
> Especially in the defcustom docstring.

I do not mind in general.

Please, remove a stray space in the defcustom.

> I also added the dumb fallback to the default value.
> I feel that otherwise the description of too confusing.

I am unsure concerning adding it to the default value. From my point of 
view, it is better to ask user to clarify their intention. I believe 
that the obscure error message is the real bug, not that Org can not 
handle too short ID by default.

I think, for new users default value should include just strict variants 
of `org-attach-id-uuid-folder-format' and 
`org-attach-id-ts-folder-format' that checks ID format as in the example 
in ORG-NEWS. Changing of `org-id-method' will not cause non-optimal 
subdir layout for the same value of 'org-attach-id-to-path-function-list'.

It will cause a problem for users who changed `org-id-method' in the 
past, so they have either XX/timestamp or YYYYMM/uuid subdirectories. It 
may be solved by adding original variants of 
`org-attach-id-uuid-folder-format' and `org-attach-id-ts-folder-format', 
but perhaps it is better to add predicates for "wrong" style (UUID or 
Org for timestamp and vice versa) just for backward compatibility.

It should be responsibility of the user to setup subdirs layout for 
non-standard ID format. The dumb fallback is intended as an example and 
a variant for those who do not have a lot of attachments and do not care 
where they are stored.

> +#+begin_src emacs-lisp
> +(setq org-attach-id-to-path-function-list
> +      '(;; When ID looks like an UUIDs or Org internal ID, use
> +        ;; `org-attach-id-uuid-folder-format'.
> +        (lambda (id)
> +          (and (or (org-uuidgen-p id)
> +	           (string-match-p "[0-9a-z]\\{12\\}" id))
> +	       (org-attach-id-uuid-folder-format id)))
> +        ;; When ID looks like a timestap-based ID. Group by year-month
> +        ;; folders.
> +        (lambda (id)
> +          (and (string-match-p "[0-9]\\{8\\}T[0-9]\\{6\\}\.[0-9]\\{6\\}" id)
> +               (org-attach-id-ts-folder-format id)))
> +        ;; Any other ID goes into "important" folder.
> +        (lambda (id) (format "important/%s/%s" (substring id 0 1) id))))

`org-attach-id-uuid-folder-format' and `org-attach-id-ts-folder-format' 
here were added for users changed `org-id-method' in the past and so 
having mixed subdirs layout with UUIDs in 6 character prefix directories 
or timestamps in two characters folders.

> +#+end_src

> +(defun org-attach-id-fallback-folder-format (id)
> +  "Return \"__/X/ID\" folder path as a dumb fallback.
> +X is the first character in the ID string.
> +
> +This function may be appended to `org-attach-id-path-function-list' to
> +provide a fallback for non-standard ID values that other functions in
> +`org-attach-id-path-function-list' are unable to handle.  For example,
> +when the ID is too short for `org-attach-id-ts-folder-format'.
> +
> +However, we recommend to define a more specific function spreading
> +entries over multiple folders.  This function may create a large
> +number of entries in a single folder, which may cause issues on some
> +systems."
> +  (format "__/%s/%s" (substring id 0 1) id))

Additional single character subdir level should be a minor improvement, 
unless `org-id-prefix' is non-nil.

> +(defcustom org-attach-id-to-path-function-list '( org-attach-id-uuid-folder-format
space ----------------------------------------------^

> +					org-attach-id-ts-folder-format

If strict variants of functions were used above then non-standard IDs 
would be isolated in the directory returned by the next entry

> +                                        org-attach-id-fallback-folder-format)

So I do not have strong objections since default value of 
`org-attach-id-to-path-function-list' may be adjusted later. Maybe 
strict variants of ID to subdir functions should be added as named 
functions. Fortunately it does not conflict with the patch variant your 
suggested. Feel free to commit your version.


  reply	other threads:[~2022-11-15  2:13 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-20 19:12 [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] Janek F
2022-07-23  5:22 ` [PATCH] " Ihor Radchenko
2022-08-02 22:26   ` Janek F
2022-08-03 16:03   ` Max Nikulin
2022-08-03 22:25     ` Ihor Radchenko
2022-08-10 11:43       ` [PATCH v2] " Ihor Radchenko
2022-08-10 12:17         ` Max Nikulin
2022-08-10 13:23           ` [PATCH v3] " Ihor Radchenko
2022-08-10 15:18             ` Max Nikulin
2022-08-11  4:19               ` Ihor Radchenko
2022-08-11 14:43                 ` Max Nikulin
2022-08-13  5:29                   ` Ihor Radchenko
2022-08-13 16:25                     ` Max Nikulin
2022-08-14  4:00                       ` Ihor Radchenko
2022-10-02  9:14                         ` [PATCH v4] " Ihor Radchenko
2022-10-04 15:27                           ` Max Nikulin
2022-10-05  5:44                             ` Ihor Radchenko
2022-11-06  7:43                               ` Ihor Radchenko
2022-11-07 17:05                               ` [PATCH] org-attach.el: ID to path functions may return nil Max Nikulin
2022-11-08  5:08                                 ` Ihor Radchenko
2022-11-09 16:53                                   ` [PATCH v2] " Max Nikulin
2022-11-10  7:19                                     ` Ihor Radchenko
2022-11-13 16:26                                       ` Max Nikulin
2022-11-14  3:29                                         ` Ihor Radchenko
2022-11-14 16:59                                           ` Max Nikulin [this message]
2022-11-15  2:41                                             ` Ihor Radchenko
2022-11-15 16:41                                               ` Max Nikulin
2022-11-16  1:54                                                 ` Ihor Radchenko
2022-08-12 15:35 ` [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] Max Nikulin
2022-08-12 16:08   ` Janek F
2022-08-13  5:17     ` Ihor Radchenko
2022-08-13 15:59     ` Max Nikulin

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=3326940f-f7a8-37f6-2dc2-f1f035f4c491@gmail.com \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /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).