emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Florian Lindner <mailinglists@xgm.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Moving and resetting attachments
Date: Sat, 10 Jun 2017 09:36:27 +0200	[thread overview]
Message-ID: <87mv9gz43o.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <oh8bbr$463$1@blaine.gmane.org> (Florian Lindner's message of "Wed, 7 Jun 2017 09:52:34 +0200")

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.

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

  (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))))
      (message "old-attach-dir = %S" old) ;FIXME: remove?
      (message "new-attach-dir = %S" new) ;FIXME: remove?
      (unless (or (string= old new)
                  (not old))
        ;; FIXME: Need a special case for directory reset (non-nil ARG).
        ;; FIXME: Maybe `yes-or-no-p' is safer when moving data around?
        (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))))))

Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2017-06-10  7:36 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 [this message]
2017-06-13  8:49           ` Florian Lindner
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=87mv9gz43o.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=mailinglists@xgm.de \
    /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).