From 5fe5e5de63a207ff658dae6a2fcc0224d523e84b Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Tue, 25 Apr 2006 22:29:14 +0000 Subject: [PATCH] Merged from mwolson@gnu.org--2006 (patch 34) Patches applied: * mwolson@gnu.org--2006/planner--main--1.0--patch-34 Fix a paragraph publishing problem near end of file. git-archimport-id: mwolson@gnu.org--2006-planner-el/planner-el--devel--0--patch-30 --- planner-publish.el | 114 ++++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/planner-publish.el b/planner-publish.el index 264d787..2448818 100644 --- a/planner-publish.el +++ b/planner-publish.el @@ -203,7 +203,7 @@ This may be text or a filename." (planner-begin-note-link . " ") (planner-end-note-link . "") (planner-begin-note-categories . " ") - (planner-end-note-categories . "\n")) + (planner-end-note-categories . "")) "Strings used for marking up text as HTML. These cover the most basic kinds of markup, the handling of which differs little between the various styles. @@ -238,7 +238,7 @@ table.muse-table tbody td { border: 1px solid #ccdeed; } background: #fffffc; border: 1px solid #ccdeed; } -/* enabled with planner-sectionalize.el */ +/* nested sections */ .section { margin: 0; padding: 10px; margin-bottom: 15px; font-size: 12px; } @@ -387,9 +387,10 @@ This may be text or a filename." ;;;_ + Publishing hooks (defun planner-publish-prepare-buffer () - "Return nil to allow hook to continue" - (planner-sectionalize-page) - nil) + (goto-char (point-min)) + (muse-publish-markup "sections" + '((100 "^\\(\\*+\\)\\s-+" 0 + planner-publish-section)))) ;;;_ + Markup @@ -418,7 +419,7 @@ This may be text or a filename." (defun planner-publish-markup-note () "Replace note with XML representation of note data. Borrowed - heavily from Sacha's personal configs." +heavily from Sacha's personal configs." (save-restriction (narrow-to-region (save-excursion (beginning-of-line) (point)) @@ -447,11 +448,12 @@ This may be text or a filename." (apply 'insert args))) (defun planner-publish-nested-section-tag (beg end) - "Generated by `sectionalize', the nested section tag now takes - in TITLE and LEVEL attributes. Do not get this confused with - MUSE specific `section', `subsection', etc. tags. The MUSE - specific sections are more like title/heading tags than this - nested section block version." + "Generated by `planner-publish-section', the nested section tag +now takes in TITLE and LEVEL attributes. + +This is related to the Muse concept of sections, but done before +marking up the buffer, and with special actions done on the title +of each section." (save-excursion (goto-char beg) (planner-insert-markup (muse-markup-text 'planner-begin-nested-section)) @@ -509,6 +511,7 @@ This may be text or a filename." (planner-insert-markup (muse-markup-text 'planner-begin-note-section)) (forward-line 1) (planner-insert-markup (muse-markup-text 'planner-begin-body)) + (insert ?\n) (goto-char end) (planner-insert-markup (muse-markup-text 'planner-end-body)) (planner-insert-markup (muse-markup-text 'planner-end-note-section)))) @@ -579,8 +582,9 @@ DIRECTORY and START." (planner-insert-markup (muse-markup-text 'planner-end-note-link) (muse-markup-text 'planner-begin-note-categories)) (insert categories) - (planner-insert-markup (muse-markup-text 'planner-end-note-categories) - (muse-markup-text 'planner-end-note-details)) + (planner-insert-markup (muse-markup-text 'planner-end-note-categories)) + (insert ?\n) + (planner-insert-markup (muse-markup-text 'planner-end-note-details)) (planner-insert-markup (muse-markup-text 'planner-end-note))))) ;;;_ + helper routine @@ -605,55 +609,47 @@ DIRECTORY and START." ((string= status "cancelled") "C") (t "?"))) -(defvar planner-sectionalize-delimiter "*" - "The delimiter used to sectionalize.") - -(defun planner-sectionalize-page () - "A wrapper around `sectionalize' that calls it on the - entire page. Uses the `planner-sectionalize-delimiter' - variable value. Should not have to call directly. Should be a - part of before-publish-hook." - (interactive) - (let ((delim planner-sectionalize-delimiter)) +(defun planner-publish-section-close (depth text) + "Find where the closing tag of DEPTH should go, and insert TEXT." + (let (not-end) (save-excursion - (goto-char (point-min)) - (sectionalize delim) - t))) - -(defvar sectionalize-markup-tagname - '(("* Tasks" . "tasks-section") - ("* Notes" . "notes-section"))) - -(defun sectionalize-markup-tagname (text) - "A routine that checks `sectionalize-markup-tagname' for tagname." - (let ((tagname (cdr (assoc text sectionalize-markup-tagname)))) + (while (and (setq not-end (re-search-forward + (concat "^\\*\\{1," (number-to-string depth) + "\\}\\s-+") + nil t)) + (get-text-property (match-beginning 0) 'read-only))) + (if not-end + (forward-line 0) + (goto-char (point-max))) + (cond ((not (eq (char-before) ?\n)) + (insert "\n\n")) + ((not (eq (char-before (1- (point))) ?\n)) + (insert "\n"))) + (insert text) + (insert "\n")))) + +(defvar planner-section-tagnames + "Alist of sections and their tag name." + '(("Tasks" . "tasks-section") + ("Notes" . "notes-section"))) + +(defun planner-publish-section-tagname (text) + "A routine that checks `planner-section-tagnames' for tagname." + (let ((tagname (cdr (assoc text planner-section-tagnames)))) (if tagname tagname - "nested-section"))) - -(defun sectionalize (delim &optional n) - "A routine that envelops regions of the buffer based on areas -bound by the DELIM character. - -optional parameter N is used *internally* to denote the current -recursion depth." - (unless n (setq n 0)) - (let ((regexp (concat "^\\(\\" delim "+\\)\\s-+"))) - (while (and regexp (re-search-forward regexp nil t)) - (let ((depth (length (match-string 1))) - (title (buffer-substring (match-end 0) (point-at-eol))) - (tagname (sectionalize-markup-tagname - (buffer-substring (match-beginning 0) (point-at-eol))))) - (cond ((> depth n) - (delete-region (match-beginning 0) (point-at-eol)) - (when (not (string= title "")) - (insert (format "<%s level=\"%s\">%s" - tagname depth title)) - (sectionalize delim depth) - (insert (format "\n" tagname)))) - (t (setq regexp nil) - (goto-char (match-beginning 0)))))) - (if regexp (goto-char (point-max))))) + "nested-section"))) + +(defun planner-publish-section () + "Publish the current heading as a section." + (let* ((depth (length (match-string 1))) + (title (buffer-substring (match-end 0) (planner-line-end-position))) + (tagname (planner-publish-section-tagname title))) + (delete-region (match-beginning 0) (match-end 0)) + (insert (format "<%s level=\"%s\">" tagname depth)) + (end-of-line) + (insert "") + (planner-publish-section-close depth (format "" tagname)))) ;;;_ + Planner Style Definitions -- 2.11.4.GIT