emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Moving and resetting attachments


From: Nicolas Goaziou
Subject: Re: [O] Moving and resetting attachments
Date: Sat, 10 Jun 2017 09:36:27 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Hello,

Florian Lindner <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]