From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Moving and resetting attachments Date: Sat, 10 Jun 2017 09:36:27 +0200 Message-ID: <87mv9gz43o.fsf@nicolasgoaziou.fr> References: <874lw05njr.fsf@ericabrahamsen.net> <8737bi21dc.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJawi-0002KA-89 for emacs-orgmode@gnu.org; Sat, 10 Jun 2017 03:36:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJawh-0005et-63 for emacs-orgmode@gnu.org; Sat, 10 Jun 2017 03:36:32 -0400 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:33277) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dJawg-0005eX-Vg for emacs-orgmode@gnu.org; Sat, 10 Jun 2017 03:36:31 -0400 In-Reply-To: (Florian Lindner's message of "Wed, 7 Jun 2017 09:52:34 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Florian Lindner Cc: emacs-orgmode@gnu.org Hello, Florian Lindner 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