[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emacs-wiki-discuss] patch: planner-experimental.el: cross pages note li
From: |
Dryice Liu |
Subject: |
[emacs-wiki-discuss] patch: planner-experimental.el: cross pages note link support |
Date: |
Wed, 22 Dec 2004 15:15:05 +0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (berkeley-unix) |
Hi,
I tried to make notes link across multiple pages, and here is what I
get:
planner-update-note: Copy the text from this note to the linked note,
if any.
planner-add-note-xref: Link the current note to a given page.
planner-update-notes: update all notes on the current page to their
links pages.
So now I can use planner-add-note-xref to link the current note to the
page I want, no matter the note is linked or not. Then if I modify the
note later, I can call planner-update-note to update it on the linked
page, or call planner-update-notes to update all the notes on the
current page.
Please note that ddliu-planner-current-note-info is intended to
replace planner-current-note-info, but if we do this, a lot of things
will need to change:
planner-jump-to-linked-note: we have multiple notes linked together, I
can't think off a meaning of this. Maybe we can use
planner-jump-to-note.
planner-authz.el and planner-report.el: these two packages expect
planner-note-link to return a string, with
ddliu-planner-current-note-info, planner-note-link will return a
list. I'm not familiar with these two packages. (well, I haven't use
them yet). Maybe someone can help on this?
And here is the diffs, welcome your comments
======================================================================
--- planner-experimental.el.orig Fri Dec 17 22:04:30 2004
+++ planner-experimental.el Wed Dec 22 14:29:16 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,79 @@
(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
- [emacs-wiki-discuss] patch: planner-experimental.el: cross pages note link support,
Dryice Liu <=