emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Florian Lindner <mailinglists@xgm.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Moving and resetting attachments
Date: Tue, 13 Jun 2017 10:49:05 +0200	[thread overview]
Message-ID: <f1c95d02-d856-69ec-9bf3-beb22d803839@xgm.de> (raw)
In-Reply-To: <87mv9gz43o.fsf@nicolasgoaziou.fr>

Am 10.06.2017 um 09:36 schrieb Nicolas Goaziou:
> Hello,
> 
> Florian Lindner <mailinglists@xgm.de> writes:
> 
>> Ok, my new version is here. It should be able to replace
>> org-attach-set-directory
> 
> Thank you. Comments follow.
> 
>> Some questions about the code
>>
>> * Is that the correct way to deal with a boolean prefix arg? I'm not interested in the value of the prefix arg, only if
>> it's given or not.
> 
> No, it should be (interactive "P") so PREFIX, or more commonly, ARG, is
> nil when not provided.

Thanks!.

>> * The code changes the semantics of org-attach-set-directory, because it creates the newly set attach dir. IMHO this
>> makes more sense.
> 
> OK.
> 
>> * It deletes only the first part of the dir, e.g. data/83/1234567, it only deletes the 1234567 dir, even if 83 is empty
>> afterwards. But I think that's ok.
> 
> OK.
> 
> Here is an update of your function, with comments and FIXME. The
> docstring could certainly be improved, but you get the idea.

Yeah, docstring is usually the last I add, since I should at least know what the function is supposed to do ;-)

>   (defun flo/org-attach-move (&optional arg)
>     "Move current attachements to another directory.
>   When ARG is non-nil, reset attach directory.  Create directory if
>   needed."
>     (interactive "P")
>     (let ((old (org-attach-dir))
>           (new
>            (progn
>              (if arg (org-entry-delete nil "ATTACH_DIR")
>                (let ((dir (read-directory-name
>                            "Attachment directory: "
>                            (org-entry-get nil
>                                           "ATTACH_DIR"
>                                           (and org-attach-allow-inheritance t)))))

What is the use of (and org-attach-allow-inheritance t)? Doesn't it always returns org-attach-allow-inheritance?
Anyways, I'm not really sure if I understand the doc of org-entry-get correctly. Does org-entry-get not automatically
take inheritance into account, based on the the per-entry or global setting?

>                  (org-entry-put nil "ATTACH_DIR" dir)))
>              (org-attach-dir t))))
>       (message "old-attach-dir = %S" old) ;FIXME: remove?
>       (message "new-attach-dir = %S" new) ;FIXME: remove?

Yes, of course.

>       (unless (or (string= old new)
>                   (not old))
>         ;; FIXME: Need a special case for directory reset (non-nil ARG).

Why that? Aren't old and new holding the appropriate dirs in that case and copy over / delete as they should?

>         ;; FIXME: Maybe `yes-or-no-p' is safer when moving data around?

Ok. I wasn't aware of the difference, since I have (fset 'yes-or-no-p 'y-or-n-p) in my .emacs.

>         (when (y-or-n-p "Copy over attachments from old directory? ")
>           (copy-directory old-attach-dir new t nil t))
>         (when (y-or-n-p (concat "Delete " old))
>           ;; FIXME: Why not `delete-directory'?
>           (shell-command (format "rm -fr %s" old))))))

I took it from org-attach-delete-all. But you're delete-directory is probably better than a shell-command.

Latest version:

(defun flo/org-attach-move (&optional arg)
  "Move current attachements to another directory.
  When ARG is non-nil, reset attach directory.  Create directory if
  needed."
  (interactive "P")
  (let ((old (org-attach-dir))
        (new
         (progn
           (if arg (org-entry-delete nil "ATTACH_DIR")
             (let ((dir (read-directory-name
                         "Attachment directory: "
                         (org-entry-get nil
                                        "ATTACH_DIR"
                                        (and org-attach-allow-inheritance t)))))
               (org-entry-put nil "ATTACH_DIR" dir)))
           (org-attach-dir t))))
    (unless (or (string= old new)
                (not old))
      ;; FIXME: Need a special case for directory reset (non-nil ARG).
      (when (yes-or-no-p "Copy over attachments from old directory? ")
        (copy-directory old new t nil t))
      (when (yes-or-no-p (concat "Delete " old))
        (delete-directory old t)))))



Best,
Florian

  reply	other threads:[~2017-06-13  8:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31 12:29 Moving and resetting attachments Florian Lindner
2017-06-01  4:39 ` Eric Abrahamsen
2017-06-01 11:20   ` Florian Lindner
2017-06-02  9:19     ` Eric Abrahamsen
2017-06-02  9:51       ` Nicolas Goaziou
2017-06-02 12:34         ` Eric Abrahamsen
2017-06-02 14:34           ` Nicolas Goaziou
2017-06-02 16:51             ` Eric Abrahamsen
2017-06-04  7:59               ` Nicolas Goaziou
2017-06-04 23:25                 ` Eric Abrahamsen
2017-06-06 13:56                   ` Florian Lindner
2017-06-07  7:52       ` Florian Lindner
2017-06-10  7:36         ` Nicolas Goaziou
2017-06-13  8:49           ` Florian Lindner [this message]
2017-06-13 21:41             ` Nicolas Goaziou
2017-06-20 18:12               ` Florian Lindner
2017-06-24  8:53                 ` Nicolas Goaziou
2017-06-28 14:57                   ` Florian Lindner
2017-06-13  8:53           ` Florian Lindner

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=f1c95d02-d856-69ec-9bf3-beb22d803839@xgm.de \
    --to=mailinglists@xgm.de \
    --cc=emacs-orgmode@gnu.org \
    /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).