emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Nicolas Richard" <theonewiththeevillook@yahoo.fr>
To: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <87bogra0w8.fsf@yahoo.fr> (raw)
In-Reply-To: 87sjaawh1a.fsf@bzg.ath.cx

Bastien <bzg@altern.org> writes:


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


-- 8> --

From 0b675ab013de01422f55669ea1aebd8a77c1f7af Mon Sep 17 00:00:00 2001
From: "nrichard (geodiff-mac3)" <nrichard@ulb.ac.be>
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."
   (let* ((attach-dir (org-attach-dir t))
-	 (files (org-attach-file-list attach-dir))
+	 (files (org-attach-file-list))
 	 (file (or file
 		    "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."
 	       (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: "

  reply	other threads:[~2012-09-27 16:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-19 14:53 An org-attach link type [7.9.1 (7.9.1-elpa @ /home/youngfrog/.emacs.d/elpa/org-20120903/)] Nicolas Richard
2012-09-22  7:14 ` Viktor Rosenfeld
2012-09-22  8:58   ` Nicolas Richard
2012-09-22 17:52     ` Viktor Rosenfeld
2012-09-22  9:20 ` Bastien
2012-09-27 16:25   ` Nicolas Richard [this message]
2012-09-28  6:43     ` Bastien
2012-09-27 16:27   ` Nicolas Richard

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:

  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=87bogra0w8.fsf@yahoo.fr \
    --to=theonewiththeevillook@yahoo.fr \
    --cc=emacs-orgmode@gnu.org \


* 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


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