Am 10.06.2017 um 09:36 schrieb Nicolas Goaziou: > Hello, > > Florian Lindner <mailingli...@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