Browse Source

Allow to contextualize capture and agenda commands by checking the name of the buffer

* org.el (org-contextualize-validate-key): Check against two
new context predicates [not-]in-buffer.

* org-capture.el (org-capture-templates-contexts):
* org-agenda.el (org-agenda-custom-commands-contexts):
Document the new [not-]in-buffer context predicates.

Thanks to Paul Sexton for triggering this and for proposing a patch.
Bastien Guerry 12 years ago
parent
commit
bbea8d348b
3 changed files with 13 additions and 1 deletions
  1. 4 0
      lisp/org-agenda.el
  2. 4 0
      lisp/org-capture.el
  3. 5 1
      lisp/org.el

+ 4 - 0
lisp/org-agenda.el

@@ -2423,6 +2423,8 @@ Here are the available contexts definitions:
       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
+    in-buffer: command displayed only in matching buffers
+not-in-buffer: command not displayed in matching buffers
    [function]: a custom function taking no argument
 
 If you define several checks, the agenda command will be
@@ -2448,6 +2450,8 @@ duplicates.)"
 				      (choice
 				       (const :tag "In file" in-file)
 				       (const :tag "Not in file" not-in-file)
+				       (const :tag "In buffer" in-buffer)
+				       (const :tag "Not in buffer" not-in-buffer)
 				       (const :tag "In mode" in-mode)
 				       (const :tag "Not in mode" not-in-mode))
 				      (regexp))

+ 4 - 0
lisp/org-capture.el

@@ -461,6 +461,8 @@ Here are the available contexts definitions:
       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
+    in-buffer: command displayed only in matching buffers
+not-in-buffer: command not displayed in matching buffers
    [function]: a custom function taking no argument
 
 If you define several checks, the agenda command will be
@@ -486,6 +488,8 @@ to avoid duplicates.)"
 				     (choice
 				      (const :tag "In file" in-file)
 				      (const :tag "Not in file" not-in-file)
+				      (const :tag "In buffer" in-buffer)
+				      (const :tag "Not in buffer" not-in-buffer)
 				      (const :tag "In mode" in-mode)
 				      (const :tag "Not in mode" not-in-mode))
 				     (regexp))

+ 5 - 1
lisp/org.el

@@ -8729,11 +8729,15 @@ definitions."
 			  (string-match (cdr rr) (buffer-file-name)))
 		     (and (eq (car rr) 'in-mode)
 			  (string-match (cdr rr) (symbol-name major-mode)))
+		     (and (eq (car rr) 'in-buffer)
+			  (string-match (cdr rr) (buffer-name)))
 		     (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)))))))
+		       (not (string-match (cdr rr) (symbol-name major-mode))))
+		     (when (eq (car rr) 'not-in-buffer)
+		       (not (string-match (cdr rr) (buffer-name)))))))
 	  (push r res)))
        (car (last r))))
     (delete-dups (delq nil res))))