emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Henning Weiss <hdweiss@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: [Feature Request] org-mobile edit:add nodes
Date: Tue, 22 May 2012 14:20:10 +0200	[thread overview]
Message-ID: <CAKq33ud0aPFG2jmGfBKXnVhF-oS_bLW6=SyomgC47nNuwT6p4w@mail.gmail.com> (raw)
In-Reply-To: <87vckqdp1j.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 891 bytes --]

Hi,

On Tue, Apr 24, 2012 at 1:08 AM, Bastien <bzg@gnu.org> wrote:

> Henning Weiss <hdweiss@gmail.com> writes:
>
> > it turns out that there are a couple of problems with that particular
> > patch. Some issues have already been fixed with the help of someone
> > else from the mobileorg community, but more work is required. As soon
> > as it is functional (and hopefully stable) I will post a new patch.
>
> Please do -- thanks for the follow up!
>
> --
>  Bastien
>

I have refined the edit nodes patch. Aaron Peromsik has helped me with
developing and testing it. He hasn't reported any problems with it and I
have been using it for a couple of weeks now without experiencing any
problems.

According to the contribution guidelines this patch doesn't qualify as a
TINYCHANGE. Assuming this patch qualifies for inclusion, do I need to fill
out the FSF copyright assignment form?

Henning

[-- Attachment #1.2: Type: text/html, Size: 1362 bytes --]

[-- Attachment #2: 0001-org-mobile-Added-five-new-targets-for-edit-nodes.patch --]
[-- Type: application/octet-stream, Size: 7005 bytes --]

From daa86abebed7f5e1be4b6c2ec5027cb00694a98a Mon Sep 17 00:00:00 2001
From: Henning Weiss <hdweiss@gmail.com>
Date: Tue, 22 May 2012 13:32:27 +0200
Subject: [PATCH] org-mobile: Added five new targets for edit nodes

* lisp/org-mobile.el (org-mobile-edit): Added handling of
  addheading, refile, archive, archive-sibling and delete edit nodes.
(org-mobile-locate-entry): olp links containing only a file are now be
  located correctly.
(org-mobile-apply): Instead of finding the location of all target
  headings for edit nodes in a separate loop, they will be found
  immediately before applying edits.

org-mobile-apply needed to be changed, as the new edit nodes can
insert new headings or delete them, thereby changing the locations
of the target headings. Thanks to Aaron Peromsik for helping with
this patch.
---
 lisp/org-mobile.el |  104 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 67 insertions(+), 37 deletions(-)

diff --git a/lisp/org-mobile.el b/lisp/org-mobile.el
index 946e821..82b2029 100644
--- a/lisp/org-mobile.el
+++ b/lisp/org-mobile.el
@@ -829,37 +829,16 @@ If BEG and END are given, only do this in that region."
 	   (not (equal (downcase (substring (match-string 1) 0 2)) "f("))
 	   (incf cnt-new)))
 
+    ;; Find and apply the edits
     (goto-char beg)
     (while (re-search-forward
 	    "^\\*+[ \t]+F(\\([^():\n]*\\)\\(:\\([^()\n]*\\)\\)?)[ \t]+\\[\\[\\(\\(id\\|olp\\):\\([^]\n]+\\)\\)" end t)
-      (setq id-pos (condition-case msg
-		       (org-mobile-locate-entry (match-string 4))
-		     (error (nth 1 msg))))
-      (when (and (markerp id-pos)
-		 (not (member (marker-buffer id-pos) buf-list)))
-	(org-mobile-timestamp-buffer (marker-buffer id-pos))
-	(push (marker-buffer id-pos) buf-list))
-
-      (if (or (not id-pos) (stringp id-pos))
-	  (progn
-	    (goto-char (+ 2 (point-at-bol)))
-	    (insert id-pos " ")
-	    (incf cnt-error))
-	(add-text-properties (point-at-bol) (point-at-eol)
-			     (list 'org-mobile-marker
-				   (or id-pos "Linked entry not found")))))
-
-    ;; OK, now go back and start applying
-    (goto-char beg)
-    (while (re-search-forward "^\\*+[ \t]+F(\\([^():\n]*\\)\\(:\\([^()\n]*\\)\\)?)" end t)
       (catch 'next
-	(setq id-pos (get-text-property (point-at-bol) 'org-mobile-marker))
-	(if (not (markerp id-pos))
-	    (progn
-	      (incf cnt-error)
-	      (insert "UNKNOWN PROBLEM"))
 	  (let* ((action (match-string 1))
 		 (data (and (match-end 3) (match-string 3)))
+		 (id-pos (condition-case msg
+			     (org-mobile-locate-entry (match-string 4))
+			   (error (nth 1 msg))))
 		 (bos (point-at-bol))
 		 (eos (save-excursion (org-end-of-subtree t t)))
 		 (cmd (if (equal action "")
@@ -874,7 +853,23 @@ If BEG and END are given, only do this in that region."
 			    (buffer-substring (1+ (point-at-eol)) eos)))
 		 (org-inhibit-logging 'note) ;; Do not take notes interactively
 		 old new)
+
 	    (goto-char bos)
+	    (when (and (markerp id-pos)
+		       (not (member (marker-buffer id-pos) buf-list)))
+	      (org-mobile-timestamp-buffer (marker-buffer id-pos))
+	      (push (marker-buffer id-pos) buf-list))
+	    (unless (markerp id-pos)
+	      (goto-char (+ 2 (point-at-bol)))
+	      (if (stringp id-pos)
+		  (insert id-pos " ")
+		(insert "BAD REFERENCE "))
+		(incf cnt-error)
+		(throw 'next t))
+	    (unless cmd
+	      (insert "BAD FLAG ")
+	      (incf cnt-error)
+	      (throw 'next t))
 	    (move-marker bos-marker (point))
 	    (if (re-search-forward "^** Old value[ \t]*$" eos t)
 		(setq old (buffer-substring
@@ -897,14 +892,6 @@ If BEG and END are given, only do this in that region."
 	      (setq new (and new (org-trim new))
 		    old (and old (org-trim old))))
 	    (goto-char (+ 2 bos-marker))
-	    (unless (markerp id-pos)
-	      (insert "BAD REFERENCE ")
-	      (incf cnt-error)
-	      (throw 'next t))
-	    (unless cmd
-	      (insert "BAD FLAG ")
-	      (incf cnt-error)
-	      (throw 'next t))
 	    ;; Remember this place so that we can return
 	    (move-marker marker (point))
 	    (setq org-mobile-error nil)
@@ -913,9 +900,10 @@ If BEG and END are given, only do this in that region."
 		  (org-with-point-at id-pos
 		    (progn
 		  (eval cmd)
-		  (if (member "FLAGGED" (org-get-tags))
+		  (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 (current-buffer))))))
+				   (buffer-file-name (current-buffer)))))))
 		(error (setq org-mobile-error msg))))
 	    (when org-mobile-error
 	      (org-pop-to-buffer-same-window (marker-buffer marker))
@@ -929,7 +917,7 @@ If BEG and END are given, only do this in that region."
 	    ;; If we get here, the action has been applied successfully
 	    ;; So remove the entry
 	    (goto-char bos-marker)
-	    (delete-region (point) (org-end-of-subtree t t))))))
+	    (delete-region (point) (org-end-of-subtree t t)))))
     (save-buffer)
     (move-marker marker nil)
     (move-marker end nil)
@@ -990,7 +978,19 @@ is currently a noop.")
   (if (string-match "\\`id:\\(.*\\)$" link)
       (org-id-find (match-string 1 link) 'marker)
     (if (not (string-match "\\`olp:\\(.*?\\):\\(.*\\)$" link))
-	nil
+	; not found with path, but maybe it is to be inserted
+	; in top level of the file?
+	(if (not (string-match "\\`olp:\\(.*?\\)$" link))
+	    nil
+	  (let ((file (match-string 1 link)))
+	    (setq file (org-link-unescape file))
+	    (setq file (expand-file-name file org-directory))
+	    (save-excursion
+	      (find-file file)
+	      (goto-char (point-max))
+	      (newline)
+	      (goto-char (point-max))
+	      (move-marker (make-marker) (point)))))
       (let ((file (match-string 1 link))
 	    (path (match-string 2 link)))
 	(setq file (org-link-unescape file))
@@ -1064,6 +1064,36 @@ be returned that indicates what went wrong."
 	  (org-set-tags nil 'align))
 	 (t (error "Heading changed in MobileOrg and on the computer")))))
 
+     ((eq what 'addheading)
+      (if (org-on-heading-p) ; if false we are in top-level of file
+	  (progn
+	    (end-of-line 1)
+	    (org-insert-heading-respect-content)
+	    (org-demote))
+	(beginning-of-line)
+	(insert "* "))
+      (insert new))
+
+     ((eq what 'refile)
+      (org-copy-subtree)
+      (org-with-point-at (org-mobile-locate-entry new)
+	(if (org-on-heading-p) ; if false we are in top-level of file
+	    (progn
+	      (setq level (org-get-valid-level (funcall outline-level) 1))
+	      (org-end-of-subtree t t)
+	      (org-paste-subtree level))
+	(org-paste-subtree 1)))
+	(org-cut-subtree))
+
+     ((eq what 'delete)
+      (org-cut-subtree))
+
+     ((eq what 'archive)
+      (org-archive-subtree))
+
+     ((eq what 'archive-sibling)
+      (org-archive-to-archive-sibling))
+
      ((eq what 'body)
       (setq current (buffer-substring (min (1+ (point-at-eol)) (point-max))
 				      (save-excursion (outline-next-heading)
-- 
1.7.10


  reply	other threads:[~2012-05-22 12:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-04 18:20 [Feature Request] org-mobile edit:add nodes Henning Weiss
2012-04-20 11:55 ` Bastien
2012-04-23 18:25   ` Henning Weiss
2012-04-23 23:08     ` Bastien
2012-05-22 12:20       ` Henning Weiss [this message]
2012-05-22 17:54         ` Bastien
2012-05-23  0:09           ` Henning Weiss
2012-06-21  4:11             ` Aaron Peromsik
2012-06-22 18:24               ` Henning Weiss
2012-07-05 15:47         ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKq33ud0aPFG2jmGfBKXnVhF-oS_bLW6=SyomgC47nNuwT6p4w@mail.gmail.com' \
    --to=hdweiss@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).