From 10afba90ff6ad7db74b01893ab549082bb7761c2 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Sat, 28 Oct 2006 21:37:14 +0000 Subject: [PATCH] Checkpoint my definition list publishing changes 2006-10-28 Michael Olson * lisp/muse-publish.el (muse-publish-determine-dl-indent): New function that is used as a callback to determine the initial amount of indentation that the current dl item has. (muse-publish-surround-dl): Use it. Pass the initial indent value and the post-indent value, instead of trying to determine them both. (muse-publish-strip-list-indentation): New function stripped from `muse-publish-surround-text' for readability. (muse-publish-surround-text): Instead of taking a determine-indent value, take a determine-indent-func function, which is called just after finding the next list item. There are still some definition list bugs with this implementation, but I need to checkpoint it. git-archimport-id: mwolson@gnu.org--2006/muse--main--1.0--patch-225 --- ChangeLog | 15 +++++++++ lisp/muse-publish.el | 95 +++++++++++++++++++++++++++++----------------------- 2 files changed, 68 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b5e602..5f3536e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2006-10-28 Michael Olson + + * lisp/muse-publish.el (muse-publish-determine-dl-indent): New + function that is used as a callback to determine the initial + amount of indentation that the current dl item has. + (muse-publish-surround-dl): Use it. Pass the initial indent value + and the post-indent value, instead of trying to determine them + both. + (muse-publish-strip-list-indentation): New function stripped from + `muse-publish-surround-text' for readability. + (muse-publish-surround-text): Instead of taking a determine-indent + value, take a determine-indent-func function, which is called just + after finding the next list item. There are still some definition + list bugs with this implementation, but I need to checkpoint it. + 2006-10-16 Michael Olson * lisp/muse.el: Provide the 'muse-nested-tags feature so that diff --git a/lisp/muse-publish.el b/lisp/muse-publish.el index f52bcdb..e4e78e5 100644 --- a/lisp/muse-publish.el +++ b/lisp/muse-publish.el @@ -1005,6 +1005,22 @@ The following contexts exist in Muse. (add-text-properties beg (point) '(end-list t)) (muse-publish-mark-read-only beg (point)))) +(defun muse-publish-determine-dl-indent (continue indent-sym determine-sym) + ;; If the caller doesn't know how much indentation to use, figure it + ;; out ourselves. It is assumed that `muse-forward-list-item' has + ;; been called just before this to set the match data. + (when (and continue + (symbol-value determine-sym)) + (save-match-data + ;; snarf all leading whitespace + (let ((indent (and (match-beginning 2) + (buffer-substring (match-beginning 1) + (match-beginning 2))))) + (when (and indent + (not (string= indent ""))) + (set indent-sym indent) + (set determine-sym nil)))))) + (defun muse-publish-surround-dl (indent post-indent) (let* ((beg-item (muse-markup-text 'begin-dl-item)) (end-item (muse-markup-text 'end-dl-item)) @@ -1042,20 +1058,46 @@ The following contexts exist in Muse. (muse-publish-surround-text beg-dde end-dde (lambda (indent) (muse-forward-list-item 'dl-entry indent)) - nil nil t) + indent post-indent + #'muse-publish-determine-dl-indent) (goto-char (point-max)) (skip-chars-backward (concat muse-regexp-blank "\n")) (muse-insert-markup-end-list end-item) (when continue (goto-char (point-max))))))) -(defun muse-publish-surround-text (beg-tag end-tag move-func &optional indent post-indent determine-indent list-item) +(defun muse-publish-strip-list-indentation (list-item empty-line indent post-indent) + (let ((list-nested nil) + (indent-found nil)) + (while (< (point) (point-max)) + (when (and (looking-at list-item) + (not (or (get-text-property + (muse-list-item-critical-point) 'read-only) + (get-text-property + (muse-list-item-critical-point) 'muse-link)))) + ;; if we encounter a list item, allow no post-indent space + (setq list-nested t)) + (when (and (not (looking-at empty-line)) + (looking-at (concat indent "\\(" + (or (and list-nested "") + post-indent) + "\\)"))) + ;; if list is not nested, remove indentation + (unless indent-found + (setq post-indent (match-string 1) + indent-found t)) + (replace-match "")) + (forward-line 1)))) + +(defun muse-publish-surround-text (beg-tag end-tag move-func &optional indent post-indent determine-indent-func list-item) (unless list-item (setq list-item (format muse-list-item-regexp (concat "[" muse-regexp-blank "]*")))) (let ((continue t) (empty-line (concat "^[" muse-regexp-blank "]*\n")) - init-indent beg) + (determine-indent (if determine-indent-func t nil)) + (new-indent indent) + beg) (unless indent (setq indent (concat "[" muse-regexp-blank "]+"))) (if post-indent @@ -1068,54 +1110,23 @@ The following contexts exist in Muse. ;; move past current item; continue is non-nil if there ;; are more like items to be processed continue (funcall move-func indent)) - (save-restriction - (when determine-indent - ;; if the caller doesn't know how much indentation - ;; to use, figure it out ourselves - (if (not continue) - (setq indent "") - (save-match-data - ;; snarf all leading whitespace - (let ((this-indent (and (match-beginning 2) - (buffer-substring (match-beginning 1) - (match-beginning 2))))) - (when (and this-indent - (not (string= this-indent ""))) - (setq indent this-indent - determine-indent nil)))))) - (when continue + (when determine-indent-func + (funcall determine-indent-func continue 'new-indent 'determine-indent)) + (when continue ;; remove list markup if we encountered another item of the ;; same type (replace-match "" t t nil 1)) + (save-restriction (narrow-to-region beg (point)) ;; narrow to current item (goto-char (point-min)) (forward-line 1) - (let ((list-nested nil) - (indent-found nil) - (post-indent post-indent)) - (while (< (point) (point-max)) - (when (and (looking-at list-item) - (not (or (get-text-property - (muse-list-item-critical-point) 'read-only) - (get-text-property - (muse-list-item-critical-point) 'muse-link)))) - ;; if we encounter a list item, allow no post-indent - ;; space - (setq list-nested t)) - (when (and (not (looking-at empty-line)) - (looking-at (concat indent "\\(" - (or (and list-nested "") - post-indent) - "\\)"))) - ;; if list is not nested, remove indentation - (unless indent-found - (setq post-indent (match-string 1) - indent-found t)) - (replace-match "")) - (forward-line 1))) + (muse-publish-strip-list-indentation list-item empty-line + indent post-indent) (skip-chars-backward (concat muse-regexp-blank "\n")) (muse-insert-markup-end-list end-tag) + (when determine-indent-func + (setq indent new-indent)) (when continue (goto-char (point-max))))))) -- 2.11.4.GIT