Browse Source

org-mobile: Fix "Execution failed" message on pull

* lisp/org-mobile.el (org-mobile-action-alist): Use a function instead
  of a sexp.
(org-mobile-apply): Apply changes.

Reported-by: Ian Dunn <dunni@gnu.org>
<http://permalink.gmane.org/gmane.emacs.orgmode/108603>
Nicolas Goaziou 9 years ago
parent
commit
40d140c64c
1 changed files with 30 additions and 28 deletions
  1. 30 28
      lisp/org-mobile.el

+ 30 - 28
lisp/org-mobile.el

@@ -192,19 +192,22 @@ the editing types for which the mobile version should always dominate."
 	       (const body))))
 	       (const body))))
 
 
 (defcustom org-mobile-action-alist
 (defcustom org-mobile-action-alist
-  '(("edit" . (org-mobile-edit data old new)))
+  '(("edit" . #'org-mobile-edit))
   "Alist with flags and actions for mobile sync.
   "Alist with flags and actions for mobile sync.
 When flagging an entry, MobileOrg will create entries that look like
 When flagging an entry, MobileOrg will create entries that look like
 
 
   * F(action:data)  [[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 :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.
+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 function as the first argument
+variable.
+
+The car of each elements of the alist is an actions string.  The
+cdr is a function that is called with the cursor on the headline
+of that entry.  It should accept three arguments, the :data part,
+the old and new values for the entry.
 
 
 For now, it is not recommended to change this variable."
 For now, it is not recommended to change this variable."
   :group 'org-mobile
   :group 'org-mobile
@@ -829,16 +832,17 @@ If BEG and END are given, only do this in that region."
 	       (bos (point-at-bol))
 	       (bos (point-at-bol))
 	       (eos (save-excursion (org-end-of-subtree t t)))
 	       (eos (save-excursion (org-end-of-subtree t t)))
 	       (cmd (if (equal action "")
 	       (cmd (if (equal action "")
-			'(progn
-			   (cl-incf cnt-flag)
-			   (org-toggle-tag "FLAGGED" 'on)
-			   (and note
-				(org-entry-put nil "THEFLAGGINGNOTE" note)))
+			(lambda (_data _old _new)
+			  (cl-incf cnt-flag)
+			  (org-toggle-tag "FLAGGED" 'on)
+			  (when note
+			    (org-entry-put nil "THEFLAGGINGNOTE" note)))
 		      (cl-incf cnt-edit)
 		      (cl-incf cnt-edit)
 		      (cdr (assoc action org-mobile-action-alist))))
 		      (cdr (assoc action org-mobile-action-alist))))
 	       (note (and (equal action "")
 	       (note (and (equal action "")
 			  (buffer-substring (1+ (point-at-eol)) eos)))
 			  (buffer-substring (1+ (point-at-eol)) eos)))
-	       (org-inhibit-logging 'note) ;; Do not take notes interactively
+	       ;; Do not take notes interactively.
+	       (org-inhibit-logging 'note)
 	       old new)
 	       old new)
 
 
 	  (goto-char bos)
 	  (goto-char bos)
@@ -868,30 +872,28 @@ If BEG and END are given, only do this in that region."
 			 (progn (outline-next-heading)
 			 (progn (outline-next-heading)
 				(if (eobp) (org-back-over-empty-lines))
 				(if (eobp) (org-back-over-empty-lines))
 				(point)))))
 				(point)))))
-	  (setq old (and old (if (string-match "\\S-" old) old nil)))
-	  (setq new (and new (if (string-match "\\S-" new) new nil)))
+	  (setq old (org-string-nw-p old))
+	  (setq new (org-string-nw-p new))
 	  (if (and note (> (length note) 0))
 	  (if (and note (> (length note) 0))
 	      ;; Make Note into a single line, to fit into a property
 	      ;; Make Note into a single line, to fit into a property
 	      (setq note (mapconcat 'identity
 	      (setq note (mapconcat 'identity
 				    (org-split-string (org-trim note) "\n")
 				    (org-split-string (org-trim note) "\n")
 				    "\\n")))
 				    "\\n")))
 	  (unless (equal data "body")
 	  (unless (equal data "body")
-	    (setq new (and new (org-trim new))
-		  old (and old (org-trim old))))
+	    (setq new (and new (org-trim new)))
+	    (setq old (and old (org-trim old))))
 	  (goto-char (+ 2 bos-marker))
 	  (goto-char (+ 2 bos-marker))
 	  ;; Remember this place so that we can return
 	  ;; Remember this place so that we can return
 	  (move-marker marker (point))
 	  (move-marker marker (point))
 	  (setq org-mobile-error nil)
 	  (setq org-mobile-error nil)
-	  (save-excursion
-	    (condition-case msg
-		(org-with-point-at id-pos
-		  (progn
-		    (eval cmd)
-		    (unless (member data (list "delete" "archive" "archive-sibling" "addheading"))
-		      (if (member "FLAGGED" (org-get-tags))
-			  (add-to-list 'org-mobile-last-flagged-files
-				       (buffer-file-name))))))
-	      (error (setq org-mobile-error msg))))
+	  (condition-case msg
+	      (org-with-point-at id-pos
+		(funcall cmd data old new)
+		(unless (member data '("delete" "archive" "archive-sibling" "addheading"))
+		  (when (member "FLAGGED" (org-get-tags))
+		    (add-to-list 'org-mobile-last-flagged-files
+				 (buffer-file-name)))))
+	    (error (setq org-mobile-error msg)))
 	  (when org-mobile-error
 	  (when org-mobile-error
 	    (pop-to-buffer-same-window (marker-buffer marker))
 	    (pop-to-buffer-same-window (marker-buffer marker))
 	    (goto-char marker)
 	    (goto-char marker)