Browse Source

Add new capabilities to org-mobile.el

- Allow to set any TODO keyword
- Allow to replace the local tags
Carsten Dominik 15 years ago
parent
commit
ec302d2a7a
3 changed files with 54 additions and 9 deletions
  1. 6 0
      lisp/ChangeLog
  2. 16 9
      lisp/org-mobile.el
  3. 32 0
      lisp/org.el

+ 6 - 0
lisp/ChangeLog

@@ -1,5 +1,11 @@
 2009-09-30  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org.el (org-set-tags-to): New command.
+
+	* org-mobile.el (org-mobile-action-alist): Add more options and
+	update the docstring.
+	(org-mobile-apply-flags): Parse for and use the data.
+
 	* org-latex.el (org-export-latex-set-initial-vars): Also check in
 	the plist.
 

+ 16 - 9
lisp/org-mobile.el

@@ -91,16 +91,21 @@ should point to this file."
 (defcustom org-mobile-action-alist
   '(("d" . (org-todo 'done))
     ("a" . (org-archive-subtree-default))
-    ("d-a" . (progn (org-todo 'done) (org-archive-subtree-default))))
+    ("d-a" . (progn (org-todo 'done) (org-archive-subtree-default)))
+    ("todo" . (org-todo data))
+    ("tags" . (org-set-tags-to data)))
   "Alist with flags and actions for mobile sync.
 When flagging an entry, MobileOrg will create entries that look like
 
-  * F(action)  [[id:entry-id][entry title]]
+  * F(action:data)  [[id:entry-id][entry title]]
 
-This alist defines that the action in the parentheses of F() should mean,
-i.e. what action should be taken.  The car of each elements of the alist
-is an actions string.  The cdr is an Emacs Lisp form that will be evaluated
-with the cursor on the headline of that entry."
+This alist defines that the ACTION in the parentheses of F() should mean,
+i.e. what action should be taken.  The :data part in the parenthesis is
+optional.  If present, the string after the colon will be passed to the
+action form as the `data' variable.
+The car of each elements of the alist is an actions string.  The cdr is
+an Emacs Lisp form that will be evaluated with the cursor on the headline
+of that entry."
   :group 'org-mobile
   :type '(repeat
 	  (cons (string :tag "Action flag")
@@ -413,14 +418,16 @@ If BEG and END are given, only do this in that region."
   (setq beg (or beg (point-min)) end (or end (point-max)))
   (goto-char beg)
   (let ((marker (make-marker))
+	(org-inhibit-logging 'note)
 	(end (move-marker (make-marker) end))
-	action id id-pos cmd text)
+	action data id id-pos cmd text)
     (while (re-search-forward
-	    "^\\*+[ \t]+F(\\([^()\n]*\\))[ \t]+\\[\\[id:\\([^]\n ]+\\)" end t)
+	    "^\\*+[ \t]+F(\\([^():\n]*\\)\\(:\\([^()\n]*\\)\\)?)[ \t]+\\[\\[id:\\([^]\n ]+\\)" end t)
       (goto-char (- (match-beginning 1) 2))
       (catch 'next
 	(setq action (match-string 1)
-	      id (match-string 2)
+	      data (and (match-end 3) (match-string 3))
+	      id (match-string 4)
 	      cmd (if (equal action "")
 		      '(progn
 			 (org-toggle-tag "FLAGGED" 'on)

+ 32 - 0
lisp/org.el

@@ -11251,6 +11251,38 @@ If ONOFF is `on' or `off', don't toggle but set to this state."
       (org-back-to-heading t)
       (org-set-tags arg just-align))))
 
+(defun org-set-tags-to (data)
+  "Set the tags of the current entry to DATA, replacing the current tags.
+DATA may be a tags string like :aa:bb:cc:, or a list of tags.
+If DATA is nil or the empty string, any tags will be removed."
+  (interactive "sTags: ")
+  (setq data
+	(cond
+	 ((eq data nil) "")
+	 ((equal data "") "")
+	 ((stringp data)
+	  (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
+		  ":"))
+	 ((listp data)
+	  (concat ":" (mapconcat 'identity data ":") ":"))
+	 t nil))
+  (when data
+    (save-excursion
+      (org-back-to-heading t)
+      (when (looking-at org-complex-heading-regexp)
+	(if (match-end 5)
+	    (progn
+	      (goto-char (match-beginning 5))
+	      (insert data)
+	      (delete-region (point) (point-at-eol))
+	      (org-set-tags nil 'align))
+	  (goto-char (point-at-eol))
+	  (insert " " data)
+	  (org-set-tags nil 'align)))
+      (beginning-of-line 1)
+      (if (looking-at ".*?\\([ \t]+\\)$")
+	  (delete-region (match-beginning 1) (match-end 1))))))
+
 (defun org-set-tags (&optional arg just-align)
   "Set the tags for the current headline.
 With prefix ARG, realign all tags in headings in the current buffer."