emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [feature request] use relative path in the file set by org-agenda-files
@ 2010-03-23  7:32 zwz
  2010-03-23 10:30 ` Mikael Fornius
  0 siblings, 1 reply; 4+ messages in thread
From: zwz @ 2010-03-23  7:32 UTC (permalink / raw)
  To: emacs-orgmode

The variable "org-agenda-files" can be a list of file names or a single file 
name. I prefer the latter, since it is much easier to maintain one ordinary 
file without modifying the .emacs.

So in my .emacs I just use:
(setq org-agenda-files (expand-file-name "agenda" org-directory))

However, it seems that only absolute path works in that agenda file, e.g.
---------------------------------
in /path/to/org-directory/agenda:
/path/to/org-directory/home.org
/path/to/org-directory/lab.org
---------------------------------
Here I hope that I can use "./home.org" and "./lab.org" instead, so that when 
I copy the "/path/to/org-directory/" to another place, I do not have to modify 
the agenda file at all.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [feature request] use relative path in the file set by org-agenda-files
  2010-03-23  7:32 [feature request] use relative path in the file set by org-agenda-files zwz
@ 2010-03-23 10:30 ` Mikael Fornius
  2010-03-24 12:00   ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Fornius @ 2010-03-23 10:30 UTC (permalink / raw)
  To: zwz; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]


I have made a small patch implementing the following behavior:

With org-agenda-files = "/home/mfo/org/agenda", a filename.

| Line in agenda-file    | Expands to:                  |
|------------------------+------------------------------|
| $HOME/org/org-mode.org | "/home/mfo/org/org-mode.org" |
| td/td.org              | "/home/mfo/org/td/td.org"    |
| ~/org/test.org         | "/home/mfo/org/test.org"     |
| scratch.org            | "/home/mfo/org/scratch.org"  |
| /home/mfo/org/wep.org  | "/home/mfo/org/wep.org"      |
| ../te.org              | "/home/mfo/te.org"           |
|------------------------+------------------------------|

Here is the patch to current git-head:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-read-agenda-file-list --]
[-- Type: text/x-patch, Size: 626 bytes --]

diff --git a/lisp/org.el b/lisp/org.el
index 84bec4c..dad9293 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14672,8 +14672,10 @@ the buffer and restores the previous window configuration."
   (when (stringp org-agenda-files)
     (with-temp-buffer
       (insert-file-contents org-agenda-files)
-      (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*"))))
-
+      (mapcar (lambda (f)
+		(expand-file-name (substitute-in-file-name f)
+				  (file-name-directory org-agenda-files)))
+	      (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
 
 ;;;###autoload
 (defun org-cycle-agenda-files ()

[-- Attachment #3: Type: text/plain, Size: 20 bytes --]


-- 
Mikael Fornius

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Re: [feature request] use relative path in the file set by org-agenda-files
  2010-03-23 10:30 ` Mikael Fornius
@ 2010-03-24 12:00   ` Carsten Dominik
  2010-03-25 11:01     ` Mikael Fornius
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2010-03-24 12:00 UTC (permalink / raw)
  To: Mikael Fornius; +Cc: emacs-orgmode, zwz

Hi Mikael,

thanks for the patch, I have applied it.

It is incomplete in the following sense:  When I add another file
with `C-c [', the the expanded file names will be written back
to the file.  So maybe it would be useful to implement an inverse
operation in `org-store-new-agenda-file-list'.  I guess you cannot
get back environment variables because you don't know which
ones to use.  But getting back "~", and removing org-directory
might be nice.  Such a file could then be kept, for example
in the drop box and could work on different machines.

- Carsten

On Mar 23, 2010, at 11:30 AM, Mikael Fornius wrote:

>
> I have made a small patch implementing the following behavior:
>
> With org-agenda-files = "/home/mfo/org/agenda", a filename.
>
> | Line in agenda-file    | Expands to:                  |
> |------------------------+------------------------------|
> | $HOME/org/org-mode.org | "/home/mfo/org/org-mode.org" |
> | td/td.org              | "/home/mfo/org/td/td.org"    |
> | ~/org/test.org         | "/home/mfo/org/test.org"     |
> | scratch.org            | "/home/mfo/org/scratch.org"  |
> | /home/mfo/org/wep.org  | "/home/mfo/org/wep.org"      |
> | ../te.org              | "/home/mfo/te.org"           |
> |------------------------+------------------------------|
>
> Here is the patch to current git-head:
>
> diff --git a/lisp/org.el b/lisp/org.el
> index 84bec4c..dad9293 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -14672,8 +14672,10 @@ the buffer and restores the previous window  
> configuration."
>   (when (stringp org-agenda-files)
>     (with-temp-buffer
>       (insert-file-contents org-agenda-files)
> -      (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r 
> \n]*"))))
> -
> +      (mapcar (lambda (f)
> +		(expand-file-name (substitute-in-file-name f)
> +				  (file-name-directory org-agenda-files)))
> +	      (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r 
> \n]*")))))
>
> ;;;###autoload
> (defun org-cycle-agenda-files ()
>
> -- 
> Mikael Fornius
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

- Carsten

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [feature request] use relative path in the file set by org-agenda-files
  2010-03-24 12:00   ` Carsten Dominik
@ 2010-03-25 11:01     ` Mikael Fornius
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Fornius @ 2010-03-25 11:01 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode, zwz

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]


Thanks Carsten for the feedback!

The following patch remembers the un-expanded file names by re-reading
the agenda-files definition file before saving.

It matches the expanded file names with the un-expanded and keeps the
un-expanded version when saving. 

If you like it please apply it.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-agenda-files-expansion --]
[-- Type: text/x-patch, Size: 3675 bytes --]

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4c76cc0..709dbd8 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
+2010-03-25  Mikael Fornius  <mfo@abc.se>
+
+	* org.el (org-agenda-files): Typo.
+	(org-read-agenda-file-list): Optional argument added helping
+	org-store-new-agenda-file-list to remember un-expanded file names.
+	(org-store-new-agenda-file-list): Keep un-expanded file names when
+	saving, if availible.
+	(org-agenda-files): Updating documentation.
+
 2010-03-25  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-ascii.el (org-export-as-ascii): Catch the case of exporting
diff --git a/lisp/org.el b/lisp/org.el
index 68dd1ed..0abe787 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -2780,7 +2780,8 @@ If an entry is a directory, all files in that directory that are matched by
 
 If the value of the variable is not a list but a single file name, then
 the list of agenda files is actually stored and maintained in that file, one
-agenda file per line."
+agenda file per line. In this file paths can be given relative to this files
+directory, tilde expansion and environment variable substitution is also made."
   :group 'org-agenda
   :type '(choice
 	  (repeat :tag "List of files and directories" file)
@@ -14641,7 +14642,7 @@ If EXCLUDE-TMP is non-nil, ignore temporary buffers."
   "Get the list of agenda files.
 Optional UNRESTRICTED means return the full list even if a restriction
 is currently in place.
-When ARCHIVES is t, include all archive files hat are really being
+When ARCHIVES is t, include all archive files that are really being
 used by the agenda files.  If ARCHIVE is `ifmode', do this only if
 `org-agenda-archives-mode' is t."
   (let ((files
@@ -14694,17 +14695,28 @@ the buffer and restores the previous window configuration."
 (defun org-store-new-agenda-file-list (list)
   "Set new value for the agenda file list and save it correctly."
   (if (stringp org-agenda-files)
-      (let ((f org-agenda-files) b)
-	(while (setq b (find-buffer-visiting f)) (kill-buffer b))
-	(with-temp-file f
-	  (insert (mapconcat 'identity list "\n") "\n")))
+      (let ((fe (org-read-agenda-file-list t)) b u)
+	(while (setq b (find-buffer-visiting org-agenda-files))
+	  (kill-buffer b))
+	(with-temp-file org-agenda-files
+	  (insert
+	   (mapconcat
+	    (lambda (f) ;; Keep un-expanded entries.
+	      (if (setq u (assoc f fe)) 
+		  (cdr u)
+		f))
+	    list "\n")
+	   "\n")))
     (let ((org-mode-hook nil) (org-inhibit-startup t)
 	  (org-insert-mode-line-in-empty-file nil))
       (setq org-agenda-files list)
       (customize-save-variable 'org-agenda-files org-agenda-files))))
 
-(defun org-read-agenda-file-list ()
-  "Read the list of agenda files from a file."
+(defun org-read-agenda-file-list (&optional pair-with-expansion)
+  "Read the list of agenda files from a file.
+If PAIR-WITH-EXPANSION is t return pairs with un-expanded
+filenames, used by org-store-new-agenda-file-list to write back
+un-expanded file names."
   (when (file-directory-p org-agenda-files)
     (error "`org-agenda-files' cannot be a single directory"))
   (when (stringp org-agenda-files)
@@ -14712,8 +14724,11 @@ the buffer and restores the previous window configuration."
       (insert-file-contents org-agenda-files)
       (mapcar
        (lambda (f)
-	 (expand-file-name (substitute-in-file-name f)
-			   (file-name-directory org-agenda-files)))
+	 (let ((e (expand-file-name (substitute-in-file-name f)
+				    (file-name-directory org-agenda-files))))
+	   (if pair-with-expansion
+	       (cons e f)
+	     e)))
        (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
 
 ;;;###autoload

[-- Attachment #3: Type: text/plain, Size: 20 bytes --]


-- 
Mikael Fornius

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-03-25 10:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-23  7:32 [feature request] use relative path in the file set by org-agenda-files zwz
2010-03-23 10:30 ` Mikael Fornius
2010-03-24 12:00   ` Carsten Dominik
2010-03-25 11:01     ` Mikael Fornius

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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