all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Best way to implement project specific captures
@ 2012-08-22  3:00 Richard Riley
  2012-08-22 11:48 ` Sylvain Rousseau
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Riley @ 2012-08-22  3:00 UTC (permalink / raw)
  To: emacs-orgmode


Currently I maintain a datetree journal capture using a template so

,----
| 			      ("j" "journal" entry (file+datetree "journal.org")
| 			       "* %?\n\t:PROPERTIES:\n\t:DateCreated: %T\n\t:Link: %a\n\t:END:\n")
`----

I also use j rockways' eproject set up that allows a hook to be run when
a file is opened inside a "project". e.g

,----
| (add-hook 'web-project-file-visit-hook '(lambda ()
| 					  (ignore-errors
| 					    (message "Web Project : %s" eproject-root)
| 					    )))
`----

where "web-project" is created this:-

,----
| (define-project-type web (generic)
|   (look-for "plan.org")
|   :relevant-files ("\\.php$" "\\.js$" "\\.org$" "\\.sql$" "\\.css$" "authinfo" "vhost"))
`----

So whenever I open a file in a directory hierarchy which contains a
plan.org matching those types then my web-project-file-visit-hook is run.

What is the best emacs/elisp approach to setting a capture file
destination specific to a particular project? THe main point being that
the default capture template above should only be replaced if I am
actually in a "project" : any capture done in a file NOT contained
within a project should default to the capture template above. Is it
someting to do with buffer-locals perhaps or is there a
better/alternative way? e.g Perhaps "journal.org" becomes a variable and
this is overwritten (or whatever the elisp jargon is) in the project
hook as a buffer local?

Hope was clear!

regards

r.
 

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

* Re: Best way to implement project specific captures
  2012-08-22  3:00 Best way to implement project specific captures Richard Riley
@ 2012-08-22 11:48 ` Sylvain Rousseau
  2012-08-22 14:37   ` Bastien
                     ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Sylvain Rousseau @ 2012-08-22 11:48 UTC (permalink / raw)
  To: emacs-orgmode

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

Have a look at https://github.com/thisirs/org-context : Context agenda and
capture for Org-mode

It dynamically adds templates depending on the buffer you are currently
editing. New templates are available with the key "c" or merged if there is
no conflict with existing ones.

Hope this helps,


Sylvain.

[-- Attachment #2: Type: text/html, Size: 419 bytes --]

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

* Re: Best way to implement project specific captures
  2012-08-22 11:48 ` Sylvain Rousseau
@ 2012-08-22 14:37   ` Bastien
  2012-08-22 14:38     ` Bastien
  2012-08-22 21:12   ` Richard Riley
  2012-08-22 22:04   ` Richard Riley
  2 siblings, 1 reply; 20+ messages in thread
From: Bastien @ 2012-08-22 14:37 UTC (permalink / raw)
  To: Sylvain Rousseau; +Cc: emacs-orgmode

Hi Sylvain,

Sylvain Rousseau <thisirs@gmail.com> writes:

> Have a look at https://github.com/thisirs/org-context : Context
> agenda and capture for Org-mode

I *love* it!  This would be a great addition to contrib/lisp/ -- 
doors are open, just ring the bell.

One possible enhancement: allow using only the capture/agenda 
template instead of the full template in `org-context-capture-alist'
and `org-context-agenda-alist'.

For example, it would be easy to read/write

(setq org-context-capture-alist
      '(("*el"  . ("a" "b"))
        ("*org" . ("c" "d"))))

`a' and `b' being templates (triggered in *el files) already 
defined in `org-capture-templates'.

I guess this would speed up adoption of org-context...  but again, 
thanks for this!

-- 
 Bastien

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

* Re: Best way to implement project specific captures
  2012-08-22 14:37   ` Bastien
@ 2012-08-22 14:38     ` Bastien
  2012-08-22 18:04       ` Sylvain Rousseau
  0 siblings, 1 reply; 20+ messages in thread
From: Bastien @ 2012-08-22 14:38 UTC (permalink / raw)
  To: Sylvain Rousseau; +Cc: emacs-orgmode

Bastien <bzg@altern.org> writes:

> allow using only the capture/agenda 
> template instead of the full template

Of course, this should read:

... template letter instead of the full template definition.

-- 
 Bastien

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

* Re: Best way to implement project specific captures
  2012-08-22 14:38     ` Bastien
@ 2012-08-22 18:04       ` Sylvain Rousseau
  2012-08-23  9:13         ` Bastien
  0 siblings, 1 reply; 20+ messages in thread
From: Sylvain Rousseau @ 2012-08-22 18:04 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

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

> One possible enhancement: allow using only the capture/agenda
> template instead of the full template in `org-context-capture-alist'
> and `org-context-agenda-alist'.

Good idea! Adding it to my todo list with org-context ;-)

If you think this addon deserves to be added to the contrib directory, feel
free to add it!


Sylvain.

[-- Attachment #2: Type: text/html, Size: 385 bytes --]

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

* Re: Best way to implement project specific captures
  2012-08-22 11:48 ` Sylvain Rousseau
  2012-08-22 14:37   ` Bastien
@ 2012-08-22 21:12   ` Richard Riley
  2012-08-22 22:04   ` Richard Riley
  2 siblings, 0 replies; 20+ messages in thread
From: Richard Riley @ 2012-08-22 21:12 UTC (permalink / raw)
  To: emacs-orgmode

Sylvain Rousseau <thisirs@gmail.com> writes:

> Have a look at https://github.com/thisirs/org-context : Context agenda and capture for Org-mode
>
> It dynamically adds templates depending on the buffer you are currently editing. New templates are available with the key
> "c" or merged if there is no conflict with existing ones.
>
> Hope this helps,
>
> Sylvain.
>

Org and its users/contributors never cease to impress me!

Thanks!

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

* Re: Best way to implement project specific captures
  2012-08-22 11:48 ` Sylvain Rousseau
  2012-08-22 14:37   ` Bastien
  2012-08-22 21:12   ` Richard Riley
@ 2012-08-22 22:04   ` Richard Riley
  2012-08-22 22:54     ` Richard Riley
  2 siblings, 1 reply; 20+ messages in thread
From: Richard Riley @ 2012-08-22 22:04 UTC (permalink / raw)
  To: emacs-orgmode

Sylvain Rousseau <thisirs@gmail.com> writes:

> Have a look at https://github.com/thisirs/org-context : Context agenda and capture for Org-mode
>
> It dynamically adds templates depending on the buffer you are currently editing. New templates are available with the key
> "c" or merged if there is no conflict with existing ones.
>
> Hope this helps,
>
> Sylvain.
>

Hi,

I'm not sure if the error (?!) is mine or on your side - possibly error
is the wrong word. See this img here

http://i.imgur.com/Tvdgx.png

When I hit C-c c I then hit c for my customised "j" template  its
recreating shamrock/barwebs.org (see status line) as opposed to using
the existing barwebs.com which I have referenced via  org-agenda-files
'("~/.orgfiles" "~/webs/.orgfiles").

Can you advise further? (Looks great regardless btw!)




-- 
Sent using Emacs/Gnus from home ...

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

* Re: Best way to implement project specific captures
  2012-08-22 22:04   ` Richard Riley
@ 2012-08-22 22:54     ` Richard Riley
  2012-08-23  8:52       ` Sylvain Rousseau
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Riley @ 2012-08-22 22:54 UTC (permalink / raw)
  To: emacs-orgmode

Richard Riley <rileyrg@gmail.com> writes:

> Sylvain Rousseau <thisirs@gmail.com> writes:
>
>> Have a look at https://github.com/thisirs/org-context : Context agenda and capture for Org-mode
>>
>> It dynamically adds templates depending on the buffer you are currently editing. New templates are available with the key
>> "c" or merged if there is no conflict with existing ones.
>>
>> Hope this helps,
>>
>> Sylvain.
>>
>
> Hi,
>
> I'm not sure if the error (?!) is mine or on your side - possibly error
> is the wrong word. See this img here
>
> http://i.imgur.com/Tvdgx.png
>
> When I hit C-c c I then hit c for my customised "j" template  its
> recreating shamrock/barwebs.org (see status line) as opposed to using
> the existing barwebs.com which I have referenced via  org-agenda-files
               ^^^^^^^^^^^ this should say barwebs.org of course, sorry for the confusion.  
> '("~/.orgfiles" "~/webs/.orgfiles").
>
> Can you advise further? (Looks great regardless btw!)

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

* Re: Best way to implement project specific captures
  2012-08-22 22:54     ` Richard Riley
@ 2012-08-23  8:52       ` Sylvain Rousseau
  2012-08-23 17:52         ` Richard Riley
  0 siblings, 1 reply; 20+ messages in thread
From: Sylvain Rousseau @ 2012-08-23  8:52 UTC (permalink / raw)
  To: emacs-orgmode

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

It is an org-capture issue. You have to specify the full path of the org
file in the template even if this file is an agenda file. Otherwise
org-capture assumes that the file is located in `org-directory'.


> Can you advise further? (Looks great regardless btw!)

Thank you, building on Bastien's suggestion I'm working on a "stealing"
feature, that steals templates from `org-capture-templates' and changes the
target.

Sylvain.

[-- Attachment #2: Type: text/html, Size: 488 bytes --]

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

* Re: Best way to implement project specific captures
  2012-08-22 18:04       ` Sylvain Rousseau
@ 2012-08-23  9:13         ` Bastien
  2012-08-23 10:36           ` Carsten Dominik
  0 siblings, 1 reply; 20+ messages in thread
From: Bastien @ 2012-08-23  9:13 UTC (permalink / raw)
  To: Sylvain Rousseau; +Cc: emacs-orgmode

Sylvain Rousseau <thisirs@gmail.com> writes:

>> One possible enhancement: allow using only the capture/agenda
>> template instead of the full template in
> `org-context-capture-alist'
>> and `org-context-agenda-alist'.
>
> Good idea! Adding it to my todo list with org-context ;-)

Actually I love your idea so much I just implemented it in core.

See these new options:

  org-agenda-custom-commands-contexts
  org-capture-templates-contexts

The basic idea is the same than yours, except you only need to
define rules for the agenda/capture keys.  It's also extending
the notion of context by allowing to check against modes, not
only files.

Please let me know what do you think.  And thanks again for this
simple and beautiful idea.

-- 
 Bastien

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

* Re: Best way to implement project specific captures
  2012-08-23  9:13         ` Bastien
@ 2012-08-23 10:36           ` Carsten Dominik
  2012-08-23 11:09             ` Jambunathan K
                               ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Carsten Dominik @ 2012-08-23 10:36 UTC (permalink / raw)
  To: Bastien; +Cc: Sylvain Rousseau, emacs-orgmode

Hi Sylvain and Bastien,

this is an interesting idea!

I am wondering if the following feature would be useful as well:  Context sensitivity sounds most interesting to me if the same key would do different things in different contexts.  I am not sure if this is possible with the current implementation?  For example, I might want to have a bug recording key which creates an entry in a bug tracker file, but the file is different for different source files, and also the template and target type definitions might be different in different contexts.

That would require a setup which defines a selection letter, and then an a list of (sets of) conditions and the corresponding template definition.

Or am I going overboard here?

- Carsten

On 23 aug. 2012, at 11:13, Bastien <bzg@altern.org> wrote:

> Sylvain Rousseau <thisirs@gmail.com> writes:
> 
>>> One possible enhancement: allow using only the capture/agenda
>>> template instead of the full template in
>> `org-context-capture-alist'
>>> and `org-context-agenda-alist'.
>> 
>> Good idea! Adding it to my todo list with org-context ;-)
> 
> Actually I love your idea so much I just implemented it in core.
> 
> See these new options:
> 
>  org-agenda-custom-commands-contexts
>  org-capture-templates-contexts
> 
> The basic idea is the same than yours, except you only need to
> define rules for the agenda/capture keys.  It's also extending
> the notion of context by allowing to check against modes, not
> only files.
> 
> Please let me know what do you think.  And thanks again for this
> simple and beautiful idea.
> 
> -- 
> Bastien
> 

- Carsten

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

* Re: Best way to implement project specific captures
  2012-08-23 10:36           ` Carsten Dominik
@ 2012-08-23 11:09             ` Jambunathan K
  2012-08-23 15:08             ` Bastien
  2012-08-23 17:16             ` Sylvain Rousseau
  2 siblings, 0 replies; 20+ messages in thread
From: Jambunathan K @ 2012-08-23 11:09 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Bastien, Sylvain Rousseau, emacs-orgmode


May be dir local variables could be used?

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Sylvain and Bastien,
>
> this is an interesting idea!
>
> I am wondering if the following feature would be useful as well:
> Context sensitivity sounds most interesting to me if the same key
> would do different things in different contexts.  I am not sure if
> this is possible with the current implementation?  For example, I
> might want to have a bug recording key which creates an entry in a bug
> tracker file, but the file is different for different source files,
> and also the template and target type definitions might be different
> in different contexts.
>
> That would require a setup which defines a selection letter, and then
> an a list of (sets of) conditions and the corresponding template
> definition.
>
> Or am I going overboard here?
>
> - Carsten
>
> On 23 aug. 2012, at 11:13, Bastien <bzg@altern.org> wrote:
>
>> Sylvain Rousseau <thisirs@gmail.com> writes:
>> 
>>>> One possible enhancement: allow using only the capture/agenda
>>>> template instead of the full template in
>>> `org-context-capture-alist'
>>>> and `org-context-agenda-alist'.
>>> 
>>> Good idea! Adding it to my todo list with org-context ;-)
>> 
>> Actually I love your idea so much I just implemented it in core.
>> 
>> See these new options:
>> 
>>  org-agenda-custom-commands-contexts
>>  org-capture-templates-contexts
>> 
>> The basic idea is the same than yours, except you only need to
>> define rules for the agenda/capture keys.  It's also extending
>> the notion of context by allowing to check against modes, not
>> only files.
>> 
>> Please let me know what do you think.  And thanks again for this
>> simple and beautiful idea.
>> 
>> -- 
>> Bastien
>> 
>
> - Carsten
>
>
>
>
>

-- 

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

* Re: Best way to implement project specific captures
  2012-08-23 10:36           ` Carsten Dominik
  2012-08-23 11:09             ` Jambunathan K
@ 2012-08-23 15:08             ` Bastien
  2012-08-23 17:16             ` Sylvain Rousseau
  2 siblings, 0 replies; 20+ messages in thread
From: Bastien @ 2012-08-23 15:08 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Sylvain Rousseau, emacs-orgmode

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

Hi Carsten,

Carsten Dominik <carsten.dominik@gmail.com> writes:

> I am wondering if the following feature would be useful as well: Context
> sensitivity sounds most interesting to me if the same key would do
> different things in different contexts.  I am not sure if this is possible
> with the current implementation?  For example, I might want to have a bug
> recording key which creates an entry in a bug tracker file, but the file is
> different for different source files, and also the template and target type
> definitions might be different in different contexts.
>
> That would require a setup which defines a selection letter, and then an a
> list of (sets of) conditions and the corresponding template
> definition.

I implemented this, relying on the existing contexts options.

Please have a go with the attached patch.  I copy the comment
from the commit log:

In the setup below, X is not a real capture template, it is just
an alias to templates A and B in .txt and .el files.  A and B are
deactivated by default in all files.

(setq org-capture-templates
      '(("X" "Nothing but an alias")
	("A" "AAAA" entry (file+headline [...]))
	("B" "BBBB" entry (file+headline [...]))))

(setq org-capture-templates-contexts
      '(("A" "A" ((not-in-file . ".*")))
	("B" "B" ((not-in-file . ".*")))
	("X" "A" ((in-file . "\\.txt")))
	("X" "B" ((in-file . "\\.el")))))

I find this quite handy...  let me know what you think!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Implement-key-replacement-depending-on-the-contexts.patch --]
[-- Type: text/x-patch, Size: 8097 bytes --]

From c191d48aa1f2eb6c28fe2503b6b039265fb1da1e Mon Sep 17 00:00:00 2001
From: Bastien Guerry <bzg@altern.org>
Date: Thu, 23 Aug 2012 17:04:43 +0200
Subject: [PATCH] Implement key replacement depending on the contexts.

* org.el (org-contextualize-agenda-or-capture): Handle key
replacement depending on the contexts.

* org-capture.el (org-capture-templates-contexts): Allow to
use the context as a way to replace one capture template by
another one.

* org-agenda.el (org-agenda-custom-commands-contexts): Allow
to use the context as a way to replace one agenda custom
command by another one.

* org.texi (Templates in contexts): Document the new structure
of the variables `org-agenda-custom-commands-contexts' and
`org-capture-templates-contexts'.

In the setup below, X is not a real capture template, it is just
an alias to templates A and B in .txt and .el files.  A and B are
deactivated by default in all files.

(setq org-capture-templates
      '(("X" "Nothing but an alias")
	("A" "AAAA" entry (file+headline [...]))
	("B" "BBBB" entry (file+headline [...]))))

(setq org-capture-templates-contexts
      '(("A" "A" ((not-in-file . ".*")))
	("B" "B" ((not-in-file . ".*")))
	("X" "A" ((in-file . "\\.txt")))
	("X" "B" ((in-file . "\\.el")))))

Thanks to Carsten for suggesting this "key-replacement" idea!
---
 doc/org.texi        |   16 +++++++++++++---
 lisp/org-agenda.el  |   20 +++++++++++++++++---
 lisp/org-capture.el |   22 ++++++++++++++++++----
 lisp/org.el         |   40 +++++++++++++++++++++++++++++++---------
 4 files changed, 79 insertions(+), 19 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 897115c..3ec72b3 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6863,10 +6863,14 @@ for example that you have a capture template @code{"p"} for storing Gnus
 emails containing patches.  Then you would configure this option like this:
 
 @example
-(setq org-capture-templates-contexts '(("p" (in-mode . "message-mode"))))
+(setq org-capture-templates-contexts
+      '(("p" "p" (in-mode . "message-mode"))))
 @end example
 
-See the docstring of the variable for more information.
+The second @code{"p"} tells what template to really call in the specified
+context.  You can set this to another capture template, so that @code{p} will
+transparently fall back on it.  See the docstring of the variable for more
+information.
 
 @node Attachments, RSS Feeds, Capture, Capture - Refile - Archive
 @section Attachments
@@ -8778,9 +8782,15 @@ that you only need when reading emails.  Then you would configure this option
 like this:
 
 @example
-(setq org-agenda-custom-commands-contexts '(("o" (in-mode . "message-mode"))))
+(setq org-agenda-custom-commands-contexts
+      '(("o" "o" (in-mode . "message-mode"))))
 @end example
 
+The second @code{"o"} tells what command to really call in the specified
+context.  You can set this to another agenda custom command, so that @code{o}
+will transparently fall back on it.  See the docstring of the variable for
+more information.
+
 See the docstring of the variable for more information.
 
 @node Exporting Agenda Views, Agenda column view, Custom agenda views, Agenda Views
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 9c7f29b..563ed3f 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2341,9 +2341,22 @@ For example, if you have a custom agenda command \"p\" and you
 want this command to be accessible only from plain text files,
 use this:
 
-   '((\"p\" (in-file . \"\\.txt\")))
+   '((\"p\" \"p\" (in-file . \"\\.txt\")))
 
-Here are the available checks:
+If you replace the second \"p\" by another key (say \"q\"), then
+the \"p\" key will be associated with the \"q\" command in the
+valid contexts.  This is useful if you want to use the same key
+to reach multiple commands depending on the context:
+
+   '((\"p\" \"q\" (in-file . \"\\.txt\"))
+     (\"p\" \"r\" (in-file . \"\\.el\"))
+     (\"p\" \"s\" (in-file . \"\\.c\")))
+
+Here, the \"p\" key will be accessible from buffers visiting
+.txt, .el and .c files, and it will be a synonym for \"q\", \"r\"
+and \"s\" respectively.
+
+Here are the available contexts definition:
 
       in-file: command displayed only in matching files
       in-mode: command displayed only in matching modes
@@ -2354,8 +2367,9 @@ If you define several checks, the agenda command will be
 accessible if there is at least one valid check."
   ;; :version "24.3"
   :group 'org-agenda-custom-commands
-  :type '(repeat (cons :tag "Rule"
+  :type '(repeat (list :tag "Rule"
 		       (string :tag "Agenda key")
+		       (string :tag "Replace by command")
 		       (repeat :tag "Available when"
 			       (cons :tag "Condition"
 				     (choice
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 782e027..368894e 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -442,12 +442,25 @@ for a capture buffer.")
   "Bind capture keys with rules on where to display them.
 
 For example, if you have a capture template \"c\" and you want
-this template to be accessible only from message-mode buffers,
+this template to be accessible only from `message-mode' buffers,
 use this:
 
-   '((\"c\" (in-mode . \"message-mode\")))
+   '((\"c\" \"c\" (in-mode . \"message-mode\")))
 
-Here are the available checks:
+If you replace the second \"c\" by another key (say \"d\"), then
+the \"c\" key will be associated with the \"d\" template in the
+valid contexts.  This is useful if you want to use the same key
+for different templates depending on the context:
+
+   '((\"c\" \"d\" (in-file . \"\\.txt\"))
+     (\"c\" \"e\" (in-file . \"\\.el\"))
+     (\"c\" \"f\" (in-file . \"\\.c\")))
+
+Here, the \"c\" key will be accessible from buffers visiting
+.txt, .el and .c files, and it will be a synonym for \"d\", \"e\"
+and \"f\" respectively.
+
+Here are the available contexts definition:
 
       in-file: template displayed only in matching files
       in-mode: template displayed only in matching modes
@@ -458,8 +471,9 @@ If you define several checks, the capture template will be
 accessible if there is at least one valid check."
   ;; :version "24.3"
   :group 'org-capture
-  :type '(repeat (cons :tag "Rule"
+  :type '(repeat (list :tag "Rule"
 		       (string :tag "Capture key")
+		       (string :tag "Replace by template")
 		       (repeat :tag "Available when"
 			       (cons :tag "Condition"
 				     (choice
diff --git a/lisp/org.el b/lisp/org.el
index 96b5584..c8b6c54 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8623,15 +8623,37 @@ to execute outside of tables."
   "Return a subset of elements in ALIST depending on CONTEXTS.
 ALIST can be either `org-agenda-custom-commands' or
 `org-capture-templates'."
-  (let ((a alist) c r)
-    (while (setq c (pop a))
-      (when (or (not (assoc (car c) contexts))
-		(and (assoc (car c) contexts)
-		     (org-rule-validate
-		      (cdr (assoc (car c) contexts)))))
-	(push c r)))
-    ;; Return the limited ALIST
-    r))
+  (let ((a alist) c r s val repl)
+    (while (setq c (pop a))  ; loop over commands or templates
+      (cond ((not (assoc (car c) contexts))
+	     (push c r))
+	    ((and (assoc (car c) contexts)
+		  (let (rr)
+		    (setq val
+			  (org-rule-validate
+			   (and (mapc ; check all contexts associations
+				 (lambda (rl)
+				   (when (equal (car rl) (car c))
+				     (setq rr (delq nil (append rr (car (last rl)))))))
+				 contexts)
+				rr)))))
+	     (setq repl
+		   (car (delq nil
+			      (mapcar (lambda(cnt)
+					(when (and (member (car val) (caddr cnt))
+						   (equal (car c) (car cnt))) cnt))
+				      contexts))))
+	     (unless (equal (car c) (cadr repl))
+	       (push (cadr repl) s))
+	     (push (cons (car c) (cdr (assoc (cadr repl) alist))) r))))
+    ;; Return limited ALIST, possibly with keys modified, and deduplicated
+    (delq nil
+	  (mapcar (lambda(x)
+		    (let ((tpl (car x)))
+		      (when (not (delq nil
+				       (mapcar (lambda(y)
+						 (equal y tpl)) s))) x)))
+		  r))))
 
 (defun org-rule-validate (rules)
   "Check if one of RULES is valid in this buffer."
-- 
1.7.10.2


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


-- 
 Bastien

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

* Re: Best way to implement project specific captures
  2012-08-23 10:36           ` Carsten Dominik
  2012-08-23 11:09             ` Jambunathan K
  2012-08-23 15:08             ` Bastien
@ 2012-08-23 17:16             ` Sylvain Rousseau
  2 siblings, 0 replies; 20+ messages in thread
From: Sylvain Rousseau @ 2012-08-23 17:16 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Bastien, emacs-orgmode

2012/8/23 Carsten Dominik <carsten.dominik@gmail.com>:
> I am wondering if the following feature would be useful as well:  Context sensitivity sounds most interesting to me if the same key would do different things in different contexts.  I am not sure if this is possible with the current implementation?  For example, I might want to have a bug recording key which creates an entry in a bug tracker file, but the file is different for different source files, and also the template and target type definitions might be different in different contexts.

For what it's worth I have pushed changes to github implementing this
and offering the choice to override templates or put them in a submenu
as well as a "stealing" mechanism to modify existing templates'
target.

I do not have access to Bastien's changes yet but from what I
understood we might run out of letters to identify templates. For
example, if we have 10 projects with 3 different templates each, we
already have 30 items in `org-capture-templates'... Or did I miss
something?

Anyway, I'm glad to see that this feature will be in a future org release!

Sylvain.

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

* Re: Best way to implement project specific captures
  2012-08-23  8:52       ` Sylvain Rousseau
@ 2012-08-23 17:52         ` Richard Riley
  2012-08-24 12:25           ` Bastien
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Riley @ 2012-08-23 17:52 UTC (permalink / raw)
  To: emacs-orgmode

Sylvain Rousseau <thisirs@gmail.com> writes:

> It is an org-capture issue. You have to specify the full path of the org file in the template even if this file is an agenda
> file. Otherwise org-capture assumes that the file is located in
> `org-directory'.

with no path to use the "existing one" would be a real boon and
certainly works for the original journal template capture. I dont know
about the implementation details but "no path == loaded file" would make
sense with the user wanting specific files then hard code it. 

I see Bastien and Carsten are in on the thread too, I'll step back and
see in what direction this now goes ;) Thanks again for the great
feature!


>
>> Can you advise further? (Looks great regardless btw!)
>
> Thank you, building on Bastien's suggestion I'm working on a "stealing" feature, that steals templates from
> `org-capture-templates' and changes the target.
>
> Sylvain.
>

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

* Re: Best way to implement project specific captures
  2012-08-23 17:52         ` Richard Riley
@ 2012-08-24 12:25           ` Bastien
  2012-08-24 19:38             ` Richard Riley
  0 siblings, 1 reply; 20+ messages in thread
From: Bastien @ 2012-08-24 12:25 UTC (permalink / raw)
  To: emacs-orgmode

Richard Riley <rileyrg@gmail.com> writes:

> I see Bastien and Carsten are in on the thread too, I'll step back and
> see in what direction this now goes ;) Thanks again for the great
> feature!

This is how it works right now.

For each agenda custom command or capture template, you can define 
a context where it will be accessible.

E.g. you have these custom commands:

(setq org-agenda-custom-commands
      '(("A" "AAAA" ...)
	("B" "BBBB" ...)))

But you don't need "B" in .txt files:

(setq org-agenda-custom-commands-contexts
      '(("B" ((not-in-file . "\.txt")))))

That's it.

Or maybe you want "B" to be accessible with the "A" key (and 
don't want the "A" key):

(setq org-agenda-custom-commands-contexts
      '(("A" "B" ((not-in-file . "\.txt")))))

Or maybe you want "B" to be accessible only in your first two
hours of using Emacs...

(defun less-than-nhours-of-emacs-uptime (&optional n)
 (interactive "P")
 (let ((n (or n 2)))
   (< (time-to-seconds (time-subtract (current-time) before-init-time))
      (* n 3600))))

(setq org-agenda-custom-commands-contexts
      '(("B" (less-then-nhours-of-emacs-uptime))))

Enjoy,

-- 
 Bastien

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

* Re: Best way to implement project specific captures
  2012-08-24 12:25           ` Bastien
@ 2012-08-24 19:38             ` Richard Riley
  2012-08-24 20:00               ` Bastien
  2012-08-24 20:01               ` Bastien
  0 siblings, 2 replies; 20+ messages in thread
From: Richard Riley @ 2012-08-24 19:38 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@altern.org> writes:

> Richard Riley <rileyrg@gmail.com> writes:
>
>> I see Bastien and Carsten are in on the thread too, I'll step back and
>> see in what direction this now goes ;) Thanks again for the great
>> feature!
>
> This is how it works right now.
>
> For each agenda custom command or capture template, you can define 
> a context where it will be accessible.
>
> E.g. you have these custom commands:
>
> (setq org-agenda-custom-commands
>       '(("A" "AAAA" ...)
> 	("B" "BBBB" ...)))
>
> But you don't need "B" in .txt files:
>
> (setq org-agenda-custom-commands-contexts
>       '(("B" ((not-in-file . "\.txt")))))
>
> That's it.
>
> Or maybe you want "B" to be accessible with the "A" key (and 
> don't want the "A" key):

Im not sure I follow that.

>
> (setq org-agenda-custom-commands-contexts
>       '(("A" "B" ((not-in-file . "\.txt")))))
>
> Or maybe you want "B" to be accessible only in your first two
> hours of using Emacs...
>
> (defun less-than-nhours-of-emacs-uptime (&optional n)
>  (interactive "P")
>  (let ((n (or n 2)))
>    (< (time-to-seconds (time-subtract (current-time) before-init-time))
>       (* n 3600))))
>
> (setq org-agenda-custom-commands-contexts
>       '(("B" (less-then-nhours-of-emacs-uptime))))
>
> Enjoy,

Hi, my head isnt really in org "mode" (oops!) at the moment, how would I
then implement the template for "files under this directory" as
originally mentioned? ALso it would be really really nice if it would
use the existing org file if that file is on the agenda list and I dont
specify a path component on the destination file variable in the
template.

THanks!

r,

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

* Re: Best way to implement project specific captures
  2012-08-24 19:38             ` Richard Riley
@ 2012-08-24 20:00               ` Bastien
  2012-08-24 20:01               ` Bastien
  1 sibling, 0 replies; 20+ messages in thread
From: Bastien @ 2012-08-24 20:00 UTC (permalink / raw)
  To: emacs-orgmode

Hi Richard,

Richard Riley <rileyrg@gmail.com> writes:

> Hi, my head isnt really in org "mode" (oops!) at the moment, how would I
> then implement the template for "files under this directory" as
> originally mentioned?

The in-file and not-in-file conditions use regexp and expanded file
names.  You can use your directory as the regexp, it will be okay.

-- 
 Bastien

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

* Re: Best way to implement project specific captures
  2012-08-24 19:38             ` Richard Riley
  2012-08-24 20:00               ` Bastien
@ 2012-08-24 20:01               ` Bastien
  2012-08-26  6:18                 ` Richard Riley
  1 sibling, 1 reply; 20+ messages in thread
From: Bastien @ 2012-08-24 20:01 UTC (permalink / raw)
  To: emacs-orgmode

Hi Richard,

Richard Riley <rileyrg@gmail.com> writes:

> ALso it would be really really nice if it would
> use the existing org file if that file is on the agenda list and I dont
> specify a path component on the destination file variable in the
> template.

Mhh... can't parse this, sorry :/

Can you re-explain again what you want?

-- 
 Bastien

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

* Re: Best way to implement project specific captures
  2012-08-24 20:01               ` Bastien
@ 2012-08-26  6:18                 ` Richard Riley
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Riley @ 2012-08-26  6:18 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@altern.org> writes:

> Hi Richard,
>
> Richard Riley <rileyrg@gmail.com> writes:
>
>> ALso it would be really really nice if it would
>> use the existing org file if that file is on the agenda list and I dont
>> specify a path component on the destination file variable in the
>> template.
>
> Mhh... can't parse this, sorry :/
>
> Can you re-explain again what you want?

If you see my initial reply about which file is used to add the
capture, its explained there - does this make sense?

,----
| > I'm not sure if the error (?!) is mine or on your side - possibly error
| > is the wrong word. See this img here
| >
| > http://i.imgur.com/Tvdgx.png
| >
| > When I hit C-c c I then hit c for my customised "j" template  its
| > recreating shamrock/barwebs.org (see status line) as opposed to using
| > the existing barwebs.com which I have referenced via  org-agenda-files
|                ^^^^^^^^^^^ this should say barwebs.org of course, sorry for the confusion.  
| > '("~/.orgfiles" "~/webs/.orgfiles").
| >
| > Can you advise further? (Looks great regardless btw!)
`----

The reply is that I should hard code the path but I'm really averse to
this. 

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

end of thread, other threads:[~2012-08-26  6:18 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-22  3:00 Best way to implement project specific captures Richard Riley
2012-08-22 11:48 ` Sylvain Rousseau
2012-08-22 14:37   ` Bastien
2012-08-22 14:38     ` Bastien
2012-08-22 18:04       ` Sylvain Rousseau
2012-08-23  9:13         ` Bastien
2012-08-23 10:36           ` Carsten Dominik
2012-08-23 11:09             ` Jambunathan K
2012-08-23 15:08             ` Bastien
2012-08-23 17:16             ` Sylvain Rousseau
2012-08-22 21:12   ` Richard Riley
2012-08-22 22:04   ` Richard Riley
2012-08-22 22:54     ` Richard Riley
2012-08-23  8:52       ` Sylvain Rousseau
2012-08-23 17:52         ` Richard Riley
2012-08-24 12:25           ` Bastien
2012-08-24 19:38             ` Richard Riley
2012-08-24 20:00               ` Bastien
2012-08-24 20:01               ` Bastien
2012-08-26  6:18                 ` Richard Riley

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.