From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Nicolas Richard" Subject: Re: An org-attach link type [7.9.1 (7.9.1-elpa @ /home/youngfrog/.emacs.d/elpa/org-20120903/)] Date: Thu, 27 Sep 2012 18:25:27 +0200 Message-ID: <87bogra0w8.fsf@yahoo.fr> References: <5059DC5B.3080203@yahoo.fr> <87sjaawh1a.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:59512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THGuK-0001gt-VV for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 12:25:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THGuE-000107-4Q for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 12:25:48 -0400 Received: from plane.gmane.org ([80.91.229.3]:40744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THGuD-0000zQ-Px for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 12:25:42 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1THGuF-0001TA-2p for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 18:25:43 +0200 Received: from geodiff-mac3.ulb.ac.be ([164.15.131.113]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 27 Sep 2012 18:25:43 +0200 Received: from theonewiththeevillook by geodiff-mac3.ulb.ac.be with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 27 Sep 2012 18:25:43 +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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Bastien writes: Hello, > If you feel like adding the attach link type to org-attach.el > please go ahead and provide a patch. Ok, so here it is, in two parts. The first patch (included below) modifies org-attach-file-list to try and make it slightly more customizable : - The DIR argument is made optional (when given, old behaviour is used) - When that argument is not given, the function obeys a customizable option saying which attached files it should list for the subtree at point. That option defaults to the old behaviour. - Accordingly, functions that use org-attach-file-list are modified. The second patch (which should be independent from this one) follows in a different email, with the actual completing function. > Beware of the format of > the patch, though: it must contain a proper ChangeLog. See I did my best. Now I hope its sufficient. -- N. -- 8> -- >From 0b675ab013de01422f55669ea1aebd8a77c1f7af Mon Sep 17 00:00:00 2001 From: "nrichard (geodiff-mac3)" Date: Thu, 27 Sep 2012 17:37:03 +0200 Subject: [PATCH 1/2] (org-attach) Add some options for listing attachments * lisp/org-attach.el (org-attach-file-list-method): new variable (org-attach-file-list-skip-re): new variable (org-attach-file-list): use new variables to customize which files are listed. Moreover the argument DIR is now optional : if it is given, the old behaviour is kept for backward compatibility, otherwise attachments are listed for the subtree at point. (org-attach-delete-one): drop the now optional argument (org-attach-sync): drop the now optional argument (org-attach-open): drop the now optional argument --- lisp/org-attach.el | 59 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index e02d7e0..4a4c195 100644 --- a/lisp/org-attach.el +++ b/lisp/org-attach.el @@ -71,6 +71,28 @@ attachments is not kept in this property." (const :tag "None" nil) (string :tag "Tag"))) +(defcustom org-attach-file-list-method 'default + "Determine what files are to be listed as attached files. + +It can be the symbols : +- `default' :: list all files and directories in the attachment directory. +- `explicit' :: list only attached files that are explicitly listed in + the `org-attach-file-list-property' (Attachments) + property. (unreliable) +- `recurse' :: list all files in the attachment directory, recursively. + +See also variable `org-attach-file-list-skip-re'." + :group 'org-attach + :type '(choice + (const :tag "List content of the attachment directory" default) + (const :tag "List content of the property `org-attach-file-list-property'" explicit) + (const :tag "List files in the attachment directory recursively" recurse))) + +(defcustom org-attach-file-list-skip-re "\\`\\.\\|~\\'" + "Files matching this regexp will be skipped when listing attachments." + :group 'org-attach + :type 'regexp) + (defcustom org-attach-method 'cp "The preferred method to attach a file. Allowed values are: @@ -350,7 +372,7 @@ The attachment is created as an Emacs buffer." "Delete a single attachment." (interactive) (let* ((attach-dir (org-attach-dir t)) - (files (org-attach-file-list attach-dir)) + (files (org-attach-file-list)) (file (or file (org-icompleting-read "Delete attachment: " @@ -389,7 +411,7 @@ This can be used after files have been added externally." (org-entry-delete (point) org-attach-file-list-property)) (let ((attach-dir (org-attach-dir))) (when attach-dir - (let ((files (org-attach-file-list attach-dir))) + (let ((files (org-attach-file-list))) (and files (org-attach-tag)) (when org-attach-file-list-property (dolist (file files) @@ -397,12 +419,31 @@ This can be used after files have been added externally." (org-entry-add-to-multivalued-property (point) org-attach-file-list-property file)))))))) -(defun org-attach-file-list (dir) - "Return a list of files in the attachment directory. -This ignores files starting with a \".\", and files ending in \"~\"." - (delq nil - (mapcar (lambda (x) (if (string-match "^\\." x) nil x)) - (directory-files dir nil "[^~]\\'")))) +(declare-function find-lisp-find-files "find-lisp") + +(defun org-attach-file-list (&optional dir) + "List files in the directory DIR, or attachments to the subtree at point. + +When DIR is not given, list attachments to the subtree at point +according to `org-attach-file-list-method'. + +When DIR is given, list files in that directory. + +In both cases, files matching `org-attach-file-list-skip-re' are +ignored. Default is to skip files starting with a \".\" and files +ending in \"~\"." + (let* ((attach-dir (or dir (org-attach-dir nil))) + (list (cond + ; when DIR is explicitly given, use old method for backward compatibility. + ((or (eq org-attach-file-list-method 'default) dir) + (directory-files attach-dir)) + ((eq org-attach-file-list-method 'explicit) + (org-entry-get-multivalued-property nil org-attach-file-list-property)) + ((eq org-attach-file-list-method 'recurse) + (progn (require 'find-lisp) + (mapcar (lambda (x) (file-relative-name x attach-dir)) (find-lisp-find-files attach-dir "")))))) + (skip-function (lambda (x) (if (string-match org-attach-file-list-skip-re x) nil x)))) + (delq nil (mapcar skip-function list)))) (defun org-attach-reveal (&optional if-exists) "Show the attachment directory of the current task in dired." @@ -425,7 +466,7 @@ and in the system-specific variants of this variable. If IN-EMACS is non-nil, force opening in Emacs." (interactive "P") (let* ((attach-dir (org-attach-dir t)) - (files (org-attach-file-list attach-dir)) + (files (org-attach-file-list)) (file (if (= (length files) 1) (car files) (org-icompleting-read "Open attachment: " -- 1.7.12