Org-mode mailing list
 help / color / mirror / Atom feed
* Fixes for org-capture-templates-contexts
@ 2013-01-10 21:04 Paul Sexton
  2013-01-11 13:44 ` Darlan Cavalcante Moreira
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Paul Sexton @ 2013-01-10 21:04 UTC (permalink / raw)
  To: emacs-orgmode

org-capture-templates-contexts currently appears not to work. The structure
that the function 'org-contextualize-validate-key' expects to find in the
variable seems quite different from the structure described in the docstring.

Here are fixed versions of the functions 'org-contextualize-validate-key'
and 'org-contextualize-keys', both from org.el. I have also added some
functionality:
- new context specifiers in-buffer and not-in-buffer
- in-mode and not-in-mode expect a symbol, not a regexp.
- if a rule specifies a template that has 'sub-templates', those sub-templates
  will also be affected by the rule. For example if you have templates 't',
  'ta', 'tb' and 'tc', you can specify a rule for 't' which will affect
  all of them.

I have also rewritten the docstring for org-capture-templates-contexts,
from org-capture.el.

--------------------


(defcustom org-capture-templates-contexts nil
  "Alist of capture templates and valid contexts.

Each entry in the alist takes the form:
   (KEY [USUAL-KEY] CONTEXT [CONTEXT...])

Where:
   KEY :: a string of one or more letters, identifying a
       capture template.
   USUAL-KEY :: if supplied, this is the string that identifies
       the capture template in `org-capture-templates', while KEY
       becomes the string which will be used to select the
       template only in the present context (see below).
   CONTEXT :: a context definition.

Each context definition (CONTEXT) takes the form:
       FUNCTION
   or  (SPECIFIER . ARGUMENT)

Where:
   FUNCTION :: either a lambda form or a symbol naming a function.
      The function must take no arguments.
   SPECIFIER :: a symbol matching one of the context specifiers listed
      below.
   ARGUMENT :: either a string regular expression (for in-file and
      in-buffer), or a symbol (for in-mode).

Here are the available context specifiers:

      in-file: command displayed in files matching regex
    in-buffer: command displayed in buffers matching regex
      in-mode: command displayed if major mode matches symbol
  not-in-file: command not displayed in files matching regex
not-in-buffer: command not displayed in buffers matching regex
  not-in-mode: command not displayed when major mode matches symbol

For example, if you have a capture template \"c\" and you want
this template to be accessible only from `message-mode' buffers,
use this:

   '((\"c\" (in-mode . message-mode)))

If you include several context definitions, the agenda command
will be accessible if at least one of them is valid.

If the template specified by KEY has sub-templates, they will also
be affected by the rule (unless they have their own rules). For
example, if you have a template `t' and sub-templates `ta', `tb'
and `tc', then a rule for `t' will affect whether all of those
contexts are accessible.

You can also bind a key to another agenda custom command
depending on contextual rules.

    '((\"c\" \"d\" (in-file . \"\\.el$\") (in-buffer \"scratch\")))

Here it means: in files ending in `.el' and in buffers whose
name contains `scratch', use \"c\" as the
key for the capture template otherwise associated with \"d\".
\(The template originally associated with \"q\" is not displayed
to avoid duplicates.)"
  :version "24.3"
  :group 'org-capture
  :type '(repeat (list :tag "Rule"
		       (string :tag "        Capture key")
		       (string :tag "Replace by template")
		       (repeat :tag "Available when"
			      (choice
			       (cons :tag "Condition"
				     (choice
				      (const :tag "In file" in-file)
				      (const :tag "Not in file" not-in-file)
				      (const :tag "In mode" in-mode)
				      (const :tag "Not in mode" not-in-mode))
				     (regexp))
			       (function :tag "Custom function"))))))


(defun org-contextualize-validate-key (key contexts)
  "Check CONTEXTS for agenda or capture KEY."
  (let (clause context res)
    (while (setq clause (pop contexts))
      (destructuring-bind (context-key old-key . context-list) clause
        (mapc
         (lambda (context)
           (when
               (cond
                ((and (>= (length context-key) (length key))
                      (not (equal key context-key)))
                 nil)
                ((and (< (length context-key) (length key))
                      (not (string-prefix-p context-key key)))
                 nil)
                ((functionp context)
                 (funcall context))
                (t
                 (destructuring-bind (context-spec . context-arg) context
                   (message "Considering context %s" context)
                   (or (and (eq context-spec 'in-file)
                            (buffer-file-name)
                            (string-match context-arg
                                          (buffer-file-name)))
                       (and (eq context-spec 'in-buffer)
                            (string-match context-arg
                                          (buffer-name)))
                       (and (eq context-spec 'in-mode)
                            (eq context-arg major-mode))
                       (when (and (eq context-spec 'not-in-file)
                                  (buffer-file-name))
                         (not (string-match context-arg
                                            (buffer-file-name))))
                       (and (eq context-spec 'not-in-buffer)
                            (not (string-match context-arg
                                               (buffer-name))))
                       (when (eq context-spec 'not-in-mode)
                         (not (eq context-arg major-mode)))))))
             (push clause res)))
         context-list)))
    (delete-dups (delq nil res))))


(defun org-contextualize-keys (alist contexts)
  "Return valid elements in ALIST depending on CONTEXTS.

`org-agenda-custom-commands' or `org-capture-templates' are the
values used for ALIST, and `org-agenda-custom-commands-contexts'
or `org-capture-templates-contexts' are the associated contexts
definitions."
  (let ((contexts
	 ;; normalize contexts
	 (mapcar
	  (lambda(c) (cond ((listp (cadr c))
			    (list (car c) (car c) (cadr c)))
			   ((string= "" (cadr c))
			    (list (car c) (car c) (caddr c)))
			   (t c))) contexts))
	(a alist) c r s)
    ;; loop over all commands or templates
    (while (setq c (pop a))
      (let (vrules repl)
	(cond
	 ((and (not (assoc (car c) contexts))
               (not (assoc (string (elt (car c) 0)) contexts)))
	  (push c r))
	 ((and (or (assoc (car c) contexts)
                   (assoc (string (elt (car c) 0)) contexts))
	       (setq vrules (org-contextualize-validate-key
			     (car c) contexts)))
	  (mapc (lambda (vr)
		  (when (not (equal (car vr) (cadr vr)))
		    (setq repl vr))) vrules)
	  (if (not repl) (push c r)
	    (push (cadr repl) s)
	    (push
	     (cons (car c)
		   (cdr (or (assoc (cadr repl) alist)
			    (error "Undefined key `%s' as contextual replacement for `%s'"
				   (cadr repl) (car c)))))
	     r))))))
    ;; Return limited ALIST, possibly with keys modified, and deduplicated
    (delq
     nil
     (delete-dups
      (mapcar (lambda (x)
		(let ((tpl (car x)))
		  (when (not (delq
			      nil
			      (mapcar (lambda(y)
					(equal y tpl)) s))) x)))
	      (reverse r))))))

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

* Re: Fixes for org-capture-templates-contexts
  2013-01-10 21:04 Fixes for org-capture-templates-contexts Paul Sexton
@ 2013-01-11 13:44 ` Darlan Cavalcante Moreira
  2013-01-12  8:47   ` Bastien
  2013-01-11 17:06 ` Bastien
  2013-01-12  8:45 ` Bastien
  2 siblings, 1 reply; 8+ messages in thread
From: Darlan Cavalcante Moreira @ 2013-01-11 13:44 UTC (permalink / raw)
  To: Paul Sexton; +Cc: emacs-orgmode


By a great coincidence I just discovered org-capture-templates-contexts
yesterday but could not make it work yet (didn't have much time to
investigate it). Is it possible to have capture templates that do not
appear in any buffer but can be called from lisp? The idea is that I'm
implementing some org-capture templates right now that I only intend to
call via "(org-capture nil 'some letter')" and never via "C-c c". Maybe
today is my luck day and it is exactly this new "not-in-buffer" context you
have just added?

ps: this rule affecting all sub-templates will also be very userful.

--
Darlan

At Thu, 10 Jan 2013 21:04:54 +0000 (UTC),
Paul Sexton wrote:
> 
> org-capture-templates-contexts currently appears not to work. The structure
> that the function 'org-contextualize-validate-key' expects to find in the
> variable seems quite different from the structure described in the docstring.
> 
> Here are fixed versions of the functions 'org-contextualize-validate-key'
> and 'org-contextualize-keys', both from org.el. I have also added some
> functionality:
> - new context specifiers in-buffer and not-in-buffer
> - in-mode and not-in-mode expect a symbol, not a regexp.
> - if a rule specifies a template that has 'sub-templates', those sub-templates
>   will also be affected by the rule. For example if you have templates 't',
>   'ta', 'tb' and 'tc', you can specify a rule for 't' which will affect
>   all of them.
> 
> I have also rewritten the docstring for org-capture-templates-contexts,
> from org-capture.el.
> 
> --------------------
> 
> 
> (defcustom org-capture-templates-contexts nil
>   "Alist of capture templates and valid contexts.
> 
> Each entry in the alist takes the form:
>    (KEY [USUAL-KEY] CONTEXT [CONTEXT...])
> 
> Where:
>    KEY :: a string of one or more letters, identifying a
>        capture template.
>    USUAL-KEY :: if supplied, this is the string that identifies
>        the capture template in `org-capture-templates', while KEY
>        becomes the string which will be used to select the
>        template only in the present context (see below).
>    CONTEXT :: a context definition.
> 
> Each context definition (CONTEXT) takes the form:
>        FUNCTION
>    or  (SPECIFIER . ARGUMENT)
> 
> Where:
>    FUNCTION :: either a lambda form or a symbol naming a function.
>       The function must take no arguments.
>    SPECIFIER :: a symbol matching one of the context specifiers listed
>       below.
>    ARGUMENT :: either a string regular expression (for in-file and
>       in-buffer), or a symbol (for in-mode).
> 
> Here are the available context specifiers:
> 
>       in-file: command displayed in files matching regex
>     in-buffer: command displayed in buffers matching regex
>       in-mode: command displayed if major mode matches symbol
>   not-in-file: command not displayed in files matching regex
> not-in-buffer: command not displayed in buffers matching regex
>   not-in-mode: command not displayed when major mode matches symbol
> 
> For example, if you have a capture template \"c\" and you want
> this template to be accessible only from `message-mode' buffers,
> use this:
> 
>    '((\"c\" (in-mode . message-mode)))
> 
> If you include several context definitions, the agenda command
> will be accessible if at least one of them is valid.
> 
> If the template specified by KEY has sub-templates, they will also
> be affected by the rule (unless they have their own rules). For
> example, if you have a template `t' and sub-templates `ta', `tb'
> and `tc', then a rule for `t' will affect whether all of those
> contexts are accessible.
> 
> You can also bind a key to another agenda custom command
> depending on contextual rules.
> 
>     '((\"c\" \"d\" (in-file . \"\\.el$\") (in-buffer \"scratch\")))
> 
> Here it means: in files ending in `.el' and in buffers whose
> name contains `scratch', use \"c\" as the
> key for the capture template otherwise associated with \"d\".
> \(The template originally associated with \"q\" is not displayed
> to avoid duplicates.)"
>   :version "24.3"
>   :group 'org-capture
>   :type '(repeat (list :tag "Rule"
> 		       (string :tag "        Capture key")
> 		       (string :tag "Replace by template")
> 		       (repeat :tag "Available when"
> 			      (choice
> 			       (cons :tag "Condition"
> 				     (choice
> 				      (const :tag "In file" in-file)
> 				      (const :tag "Not in file" not-in-file)
> 				      (const :tag "In mode" in-mode)
> 				      (const :tag "Not in mode" not-in-mode))
> 				     (regexp))
> 			       (function :tag "Custom function"))))))
> 
> 
> (defun org-contextualize-validate-key (key contexts)
>   "Check CONTEXTS for agenda or capture KEY."
>   (let (clause context res)
>     (while (setq clause (pop contexts))
>       (destructuring-bind (context-key old-key . context-list) clause
>         (mapc
>          (lambda (context)
>            (when
>                (cond
>                 ((and (>= (length context-key) (length key))
>                       (not (equal key context-key)))
>                  nil)
>                 ((and (< (length context-key) (length key))
>                       (not (string-prefix-p context-key key)))
>                  nil)
>                 ((functionp context)
>                  (funcall context))
>                 (t
>                  (destructuring-bind (context-spec . context-arg) context
>                    (message "Considering context %s" context)
>                    (or (and (eq context-spec 'in-file)
>                             (buffer-file-name)
>                             (string-match context-arg
>                                           (buffer-file-name)))
>                        (and (eq context-spec 'in-buffer)
>                             (string-match context-arg
>                                           (buffer-name)))
>                        (and (eq context-spec 'in-mode)
>                             (eq context-arg major-mode))
>                        (when (and (eq context-spec 'not-in-file)
>                                   (buffer-file-name))
>                          (not (string-match context-arg
>                                             (buffer-file-name))))
>                        (and (eq context-spec 'not-in-buffer)
>                             (not (string-match context-arg
>                                                (buffer-name))))
>                        (when (eq context-spec 'not-in-mode)
>                          (not (eq context-arg major-mode)))))))
>              (push clause res)))
>          context-list)))
>     (delete-dups (delq nil res))))
> 
> 
> (defun org-contextualize-keys (alist contexts)
>   "Return valid elements in ALIST depending on CONTEXTS.
> 
> `org-agenda-custom-commands' or `org-capture-templates' are the
> values used for ALIST, and `org-agenda-custom-commands-contexts'
> or `org-capture-templates-contexts' are the associated contexts
> definitions."
>   (let ((contexts
> 	 ;; normalize contexts
> 	 (mapcar
> 	  (lambda(c) (cond ((listp (cadr c))
> 			    (list (car c) (car c) (cadr c)))
> 			   ((string= "" (cadr c))
> 			    (list (car c) (car c) (caddr c)))
> 			   (t c))) contexts))
> 	(a alist) c r s)
>     ;; loop over all commands or templates
>     (while (setq c (pop a))
>       (let (vrules repl)
> 	(cond
> 	 ((and (not (assoc (car c) contexts))
>                (not (assoc (string (elt (car c) 0)) contexts)))
> 	  (push c r))
> 	 ((and (or (assoc (car c) contexts)
>                    (assoc (string (elt (car c) 0)) contexts))
> 	       (setq vrules (org-contextualize-validate-key
> 			     (car c) contexts)))
> 	  (mapc (lambda (vr)
> 		  (when (not (equal (car vr) (cadr vr)))
> 		    (setq repl vr))) vrules)
> 	  (if (not repl) (push c r)
> 	    (push (cadr repl) s)
> 	    (push
> 	     (cons (car c)
> 		   (cdr (or (assoc (cadr repl) alist)
> 			    (error "Undefined key `%s' as contextual replacement for `%s'"
> 				   (cadr repl) (car c)))))
> 	     r))))))
>     ;; Return limited ALIST, possibly with keys modified, and deduplicated
>     (delq
>      nil
>      (delete-dups
>       (mapcar (lambda (x)
> 		(let ((tpl (car x)))
> 		  (when (not (delq
> 			      nil
> 			      (mapcar (lambda(y)
> 					(equal y tpl)) s))) x)))
> 	      (reverse r))))))
> 
> 
> 

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

* Re: Fixes for org-capture-templates-contexts
  2013-01-10 21:04 Fixes for org-capture-templates-contexts Paul Sexton
  2013-01-11 13:44 ` Darlan Cavalcante Moreira
@ 2013-01-11 17:06 ` Bastien
  2013-01-12  8:45 ` Bastien
  2 siblings, 0 replies; 8+ messages in thread
From: Bastien @ 2013-01-11 17:06 UTC (permalink / raw)
  To: Paul Sexton; +Cc: emacs-orgmode

Hi Paul,

Paul Sexton <psexton.2a@gmail.com> writes:

> org-capture-templates-contexts currently appears not to work. The structure
> that the function 'org-contextualize-validate-key' expects to find in the
> variable seems quite different from the structure described in the docstring.

indeed, there are some bugs here -- thanks for looking into this,
and I'm glad people use/test capture templates.

May I ask you to send me two patches, one with the fix and one with
the new feature(e)?

Also, please don't use destructuring-bind, I'd rather not use cl.el 
functions.

Thanks for the (renewed) effort if you can, otherwise just let me
know and I'll fix things myself.

Best,

-- 
 Bastien

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

* Re: Fixes for org-capture-templates-contexts
  2013-01-10 21:04 Fixes for org-capture-templates-contexts Paul Sexton
  2013-01-11 13:44 ` Darlan Cavalcante Moreira
  2013-01-11 17:06 ` Bastien
@ 2013-01-12  8:45 ` Bastien
  2013-01-14 22:21   ` Paul Sexton
  2 siblings, 1 reply; 8+ messages in thread
From: Bastien @ 2013-01-12  8:45 UTC (permalink / raw)
  To: Paul Sexton; +Cc: emacs-orgmode

Hi Paul,

Paul Sexton <psexton.2a@gmail.com> writes:

> org-capture-templates-contexts currently appears not to work. 

Actually it works, but the docstring where misleading, I fixed them.

> - new context specifiers in-buffer and not-in-buffer
> - in-mode and not-in-mode expect a symbol, not a regexp.
> - if a rule specifies a template that has 'sub-templates', those sub-templates
>   will also be affected by the rule. For example if you have templates 't',
>   'ta', 'tb' and 'tc', you can specify a rule for 't' which will affect
>   all of them.

If you can send a patch against master for this, I'd be happy to apply
it!  Thanks again for pointing to these problems,

-- 
 Bastien

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

* Re: Fixes for org-capture-templates-contexts
  2013-01-11 13:44 ` Darlan Cavalcante Moreira
@ 2013-01-12  8:47   ` Bastien
  0 siblings, 0 replies; 8+ messages in thread
From: Bastien @ 2013-01-12  8:47 UTC (permalink / raw)
  To: Darlan Cavalcante Moreira; +Cc: emacs-orgmode, Paul Sexton

Hi Darlan,

Darlan Cavalcante Moreira <darcamo@gmail.com> writes:

> By a great coincidence I just discovered org-capture-templates-contexts
> yesterday but could not make it work yet (didn't have much time to
> investigate it). 

Please try to customize `org-capture-templates-contexts' using the
customize interface.  The docstring was giving wrong direction (it 
is fixed in latest git though.)

> Is it possible to have capture templates that do not
> appear in any buffer but can be called from lisp? 

(setq org-capture-templates-contexts 
      '(("c" ((not-in-mode . "emacs-lisp-mode")))))

> ps: this rule affecting all sub-templates will also be very userful.

+1!

HTH,

-- 
 Bastien

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

* Re: Fixes for org-capture-templates-contexts
  2013-01-12  8:45 ` Bastien
@ 2013-01-14 22:21   ` Paul Sexton
  2013-01-24 16:08     ` Bastien
  2013-01-31 10:07     ` Bastien
  0 siblings, 2 replies; 8+ messages in thread
From: Paul Sexton @ 2013-01-14 22:21 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg <at> altern.org> writes:

> If you can send a patch against master for this, I'd be happy to apply
> it!  Thanks again for pointing to these problems,
> 

Below are patches against org.el and org-capture.el.

Are you sure it works correctly? The following setting for the variable
does causes an error for me out of the box, but does work with the changes
in the patch.

(setq org-capture-templates-contexts
      '(("f" (not-in-file . "\\(espanol\\|verbs\\|nouns\\)\\.org"))
        ("t" (not-in-file . "\\(espanol\\|verbs\\|nouns\\)\\.org"))
        ("e" (in-file . "\\(espanol\\|verbs\\|nouns\\)\\.org"))
        ("m" (in-file . "maths.*\\.org"))
        ("M" (in-file . "med\\.org"))))

Also, very important. I updated to master in order to make the patch and found
the current orgmode does not compile or even load. This is because
ob-eval.el uses 'declare-function' which is undefined (it is defined in
org-macs.el but ob-eval.el does not require that file).


--- ./org.el	2013-01-15 10:54:43.000000000 +1300
+++ /Users/paul/org.el	2013-01-15 11:17:01.000000000 +1300
@@ -8682,9 +8682,11 @@
     (while (setq c (pop a))
       (let (vrules repl)
 	(cond
-	 ((not (assoc (car c) contexts))
+	 ((and (not (assoc (car c) contexts))
+               (not (assoc (string (elt (car c) 0)) contexts)))
 	  (push c r))
-	 ((and (assoc (car c) contexts)
+	 ((and (or (assoc (car c) contexts)
+                   (assoc (string (elt (car c) 0)) contexts))
 	       (setq vrules (org-contextualize-validate-key
 			     (car c) contexts)))
 	  (mapc (lambda (vr)
@@ -8712,27 +8714,49 @@
 
 (defun org-contextualize-validate-key (key contexts)
   "Check CONTEXTS for agenda or capture KEY."
-  (let (r rr res)
-    (while (setq r (pop contexts))
-      (mapc
-       (lambda (rr)
-	 (when
-	  (and (equal key (car r))
-	       (if (functionp rr) (funcall rr)
-		 (or (and (eq (car rr) 'in-file)
-			  (buffer-file-name)
-			  (string-match (cdr rr) (buffer-file-name)))
-		     (and (eq (car rr) 'in-mode)
-			  (string-match (cdr rr) (symbol-name major-mode)))
-		     (when (and (eq (car rr) 'not-in-file)
-				(buffer-file-name))
-		       (not (string-match (cdr rr) (buffer-file-name))))
-		     (when (eq (car rr) 'not-in-mode)
-		       (not (string-match (cdr rr) (symbol-name major-mode)))))))
-	  (push r res)))
-       (car (last r))))
+  (let (clause context res)
+    (while (setq clause (pop contexts))
+      (let ((context-key (first clause))
+	    (old-key (second clause))
+	    (context-list (cddr clause)))
+        (mapc
+         (lambda (context)
+           (when
+               (cond
+                ((and (>= (length context-key) (length key))
+                      (not (equal key context-key)))
+                 nil)
+                ((and (< (length context-key) (length key))
+                      (not (string-prefix-p context-key key)))
+                 nil)
+                ((functionp context)
+                 (funcall context))
+                (t
+                 (let ((context-spec (first context))
+		       (context-arg (rest context)))
+                   (or (and (eq context-spec 'in-file)
+                            (buffer-file-name)
+                            (string-match context-arg
+                                          (buffer-file-name)))
+                       (and (eq context-spec 'in-buffer)
+                            (string-match context-arg
+                                          (buffer-name)))
+                       (and (eq context-spec 'in-mode)
+                            (eq context-arg major-mode))
+                       (when (and (eq context-spec 'not-in-file)
+                                  (buffer-file-name))
+                         (not (string-match context-arg
+                                            (buffer-file-name))))
+                       (and (eq context-spec 'not-in-buffer)
+                            (not (string-match context-arg
+                                               (buffer-name))))
+                       (when (eq context-spec 'not-in-mode)
+                         (not (eq context-arg major-mode)))))))
+             (push clause res)))
+         context-list)))
     (delete-dups (delq nil res))))
 
+
 (defun org-context-p (&rest contexts)
   "Check if local context is any of CONTEXTS.
 Possible values in the list of contexts are `table', `headline', and `item'."


--- ./org-capture.el	2013-01-15 10:54:42.000000000 +1300
+++ /Users/paul/org-capture.el	2013-01-15 11:17:45.000000000 +1300
@@ -449,31 +449,63 @@
 (defcustom org-capture-templates-contexts nil
   "Alist of capture templates and valid contexts.
 
+Each entry in the alist takes the form:
+   (KEY [USUAL-KEY] CONTEXT [CONTEXT...])
+
+Where:
+   KEY :: a string of one or more letters, identifying a
+       capture template.
+   USUAL-KEY :: if supplied, this is the string that identifies
+       the capture template in `org-capture-templates', while KEY
+       becomes the string which will be used to select the
+       template only in the present context (see below).
+   CONTEXT :: a context definition.
+
+Each context definition (CONTEXT) takes the form:
+       FUNCTION
+   or  (SPECIFIER . ARGUMENT)
+
+Where:
+   FUNCTION :: either a lambda form or a symbol naming a function.
+      The function must take no arguments.
+   SPECIFIER :: a symbol matching one of the context specifiers listed
+      below.
+   ARGUMENT :: either a string regular expression (for in-file and
+      in-buffer), or a symbol (for in-mode).
+
+Here are the available context specifiers:
+
+      in-file: command displayed in files matching regex
+    in-buffer: command displayed in buffers matching regex
+      in-mode: command displayed if major mode matches symbol
+  not-in-file: command not displayed in files matching regex
+not-in-buffer: command not displayed in buffers matching regex
+  not-in-mode: command not displayed when major mode matches symbol
+
 For example, if you have a capture template \"c\" and you want
 this template to be accessible only from `message-mode' buffers,
 use this:
 
-   '((\"c\" ((in-mode . \"message-mode\"))))
-
-Here are the available contexts definitions:
+   '((\"c\" (in-mode . message-mode)))
 
-      in-file: command displayed only in matching files
-      in-mode: command displayed only in matching modes
-  not-in-file: command not displayed in matching files
-  not-in-mode: command not displayed in matching modes
-   [function]: a custom function taking no argument
+If you include several context definitions, the agenda command
+will be accessible if at least one of them is valid.
 
-If you define several checks, the agenda command will be
-accessible if there is at least one valid check.
+If the template specified by KEY has sub-templates, they will also
+be affected by the rule (unless they have their own rules). For
+example, if you have a template `t' and sub-templates `ta', `tb'
+and `tc', then a rule for `t' will affect whether all of those
+contexts are accessible.
 
 You can also bind a key to another agenda custom command
 depending on contextual rules.
 
-    '((\"c\" \"d\" ((in-mode . \"message-mode\"))))
+    '((\"c\" \"d\" (in-file . \"\\.el$\") (in-buffer \"scratch\")))
 
-Here it means: in `message-mode buffers', use \"c\" as the
+Here it means: in files ending in `.el' and in buffers whose
+name contains `scratch', use \"c\" as the
 key for the capture template otherwise associated with \"d\".
-\(The template originally associated with \"d\" is not displayed
+\(The template originally associated with \"q\" is not displayed
 to avoid duplicates.)"
   :version "24.3"
   :group 'org-capture

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

* Re: Fixes for org-capture-templates-contexts
  2013-01-14 22:21   ` Paul Sexton
@ 2013-01-24 16:08     ` Bastien
  2013-01-31 10:07     ` Bastien
  1 sibling, 0 replies; 8+ messages in thread
From: Bastien @ 2013-01-24 16:08 UTC (permalink / raw)
  To: Paul Sexton; +Cc: emacs-orgmode

Hi Paul,

Paul Sexton <psexton.2a@gmail.com> writes:

> Below are patches against org.el and org-capture.el.

it really helps to send patches with git format-patch, and to add a
ChangeLog... at least it speeds up the patch reviewing process for me!

> Are you sure it works correctly? 

Yes -- please re-read the docstring:

   '(("c" ((in-mode . "message-mode"))))
          ^^                        ^^

Notice the parentheses here.  Please have a go with this syntaxe and
let me know, but I tested again and it works for me.

If that's okay for you, I'm fine with just adding the
in-buffer/not-in-buffer feature.

Thanks!

-- 
 Bastien

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

* Re: Fixes for org-capture-templates-contexts
  2013-01-14 22:21   ` Paul Sexton
  2013-01-24 16:08     ` Bastien
@ 2013-01-31 10:07     ` Bastien
  1 sibling, 0 replies; 8+ messages in thread
From: Bastien @ 2013-01-31 10:07 UTC (permalink / raw)
  To: Paul Sexton; +Cc: emacs-orgmode

Hi Paul,

Paul Sexton <psexton.2a@gmail.com> writes:

> Bastien <bzg <at> altern.org> writes:
>
>> If you can send a patch against master for this, I'd be happy to apply
>> it!  Thanks again for pointing to these problems,
>> 
>
> Below are patches against org.el and org-capture.el.

I implemented the ability to check contexts against buffer names.

Thanks for triggering this,

-- 
 Bastien

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

end of thread, other threads:[~2013-01-31 11:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-10 21:04 Fixes for org-capture-templates-contexts Paul Sexton
2013-01-11 13:44 ` Darlan Cavalcante Moreira
2013-01-12  8:47   ` Bastien
2013-01-11 17:06 ` Bastien
2013-01-12  8:45 ` Bastien
2013-01-14 22:21   ` Paul Sexton
2013-01-24 16:08     ` Bastien
2013-01-31 10:07     ` Bastien

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git