emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [emacs-wiki-discuss] patch: planner-experimental.el: cross pages not


From: Dryice Liu
Subject: Re: [emacs-wiki-discuss] patch: planner-experimental.el: cross pages note link support
Date: Thu, 23 Dec 2004 15:47:16 +0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (berkeley-unix)

Dryice Liu <address@hidden> wrote:

> Hi,
>
> I tried to make notes link across multiple pages, and here is what I
> get:

Sorry to follow myself. There's a bug in the patch that it won't work
if there's no timestamp in the note headline. Here is a new diff to
fix that. Looks I need to setup my own arch server :)

======================================================================
--- planner-experimental.el.orig        Fri Dec 17 22:04:30 2004
+++ planner-experimental.el     Thu Dec 23 10:30:47 2004
@@ -13,6 +13,30 @@
 ;;;_ + Linking through emacs-wiki links
 
 ;;; Code:
+(defun ddliu-planner-current-note-info (&optional include-body)
+  "Parse the current note and return the note information as a list.
+The list is of the form (PAGE ANCHOR TITLE TIMESTAMP LINK BODY).
+If INCLUDE-BODY is non-nil, the list will include the body of the
+note."
+  (save-excursion
+    (save-restriction
+      (when (planner-narrow-to-note)
+        (goto-char (point-min))
+        (when (looking-at "^\\.#\\([0-9]+\\)\\s-+\\(.+\\)")
+          (let ((anchor (match-string-no-properties 1))
+                (title (match-string-no-properties 2))
+                timestamp link)
+            (while (string-match "\\s-+(\\([^()]+\\))" title)
+              (add-to-list 'link (match-string-no-properties 1 title))
+              (setq title (replace-match "" nil t title)))
+            (when (string-match "\\s-*\\([0-9]+:[0-9][0-9]\\)" title)
+              (setq timestamp (match-string-no-properties 1 title))
+              (setq title (replace-match "" nil t title)))
+            (list (planner-page-name) anchor title timestamp link
+                  (and include-body (buffer-substring-no-properties
+                                     (line-end-position)
+                                     (point-max))))))))))
+
 (defun planner-update-note ()
   "Copy the text from this note to the linked note, if any."
   (interactive)
@@ -20,27 +44,80 @@
     (save-excursion
       (save-window-excursion
         (when (planner-narrow-to-note)
-          (let ((body (buffer-substring-no-properties (point-min) (point-max)))
-                (info (planner-current-note-info)))
-            ;; Get rid of the anchor.
-            (when (string-match "^\\.#[0-9]+\\s-+" body)
-              (setq body (replace-match "" nil t body)))
-            ;; Get rid of the link
-            (when (string-match "\\s-+(\\[\\[.+?\\]\\])" body)
-              (setq body (replace-match "" nil t body)))
+          (let* ((info (ddliu-planner-current-note-info t))
+                (page (planner-note-page info))
+                (anchor (planner-note-anchor info))
+                (title (planner-note-title info))
+                (timestamp (planner-note-timestamp info))
+                (links (planner-note-link info))
+                (body (planner-note-body info))
+                (loop-links links)
+                link)
             ;; Insert the new body
-            (when (planner-jump-to-linked-note)
-              (save-restriction
-                (save-excursion
-                  (when (planner-narrow-to-note)
-                    (goto-char (point-min))
-                    (skip-chars-forward ".#0-9")
-                    (delete-region (point) (point-max))
-                    (insert " " body)
-                    (goto-char (point-min))
-                    (goto-char (line-end-position))
-                    (insert " ([[" (planner-note-page info) "#"
-                            (planner-note-anchor info) "]])")))))))))))
+           (while loop-links
+             (setq link (car loop-links))
+             (when (planner-jump-to-note link)
+               (save-restriction
+                 (save-excursion
+                   (when (planner-narrow-to-note)
+                     (goto-char (point-min))
+                     (skip-chars-forward ".#[0-9]+")
+                     (delete-region (point) (point-max))
+                     (insert " "
+                             title
+                             (if timestamp
+                                 (concat " " timestamp)
+                               "")
+                             (concat " ([[" page "#" anchor "]])")
+                             (mapconcat (lambda (arg)
+                                          (if (string-equal link arg)
+                                              ""
+                                            (concat " (" arg ")")))
+                                        links
+                                        "")
+                             body))
+                   (when remember-save-after-remembering
+                     (save-buffer)))))
+             (setq loop-links (cdr loop-links)))))))))
+
+(defun planner-jump-to-note (note)
+  "Display the note."
+  (emacs-wiki-visit-link note)
+  (widen)
+  t)
+
+(defun planner-add-note-xref (&optional page)
+  "Link the current note to page."
+  (interactive (list (planner-read-name (planner-file-alist) 
+                                       "link to page: ")))
+  (let (anchor)
+    (save-restriction
+      (save-excursion
+       (save-window-excursion
+         (setq anchor (number-to-string (planner-create-note page))))))
+    (save-restriction
+      (save-excursion
+       (save-window-excursion
+         (planner-narrow-to-note)
+         (goto-char (point-min))
+         (goto-char (line-end-position))
+         (insert " ([["
+                 page
+                 "#"
+                 anchor
+                 "]])")))))
+  (planner-update-note))
+
+(defun planner-update-notes ()
+  "update all notes on the current page to their links pages."
+  (interactive)
+    (save-restriction
+      (save-excursion
+       (save-window-excursion
+         (when (planner-narrow-to-section "Notes")
+           (while (re-search-forward "^.\\(#[0-9]+\\)\\s-+\\(.+\\)"
+                                     nil t)
+             (planner-update-note)))))))
 
 ;;;_ + Searching
 
======================================================================

-- 
Cheers,
Dryice

http://dryice.3322.org





reply via email to

[Prev in Thread] Current Thread [Next in Thread]