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

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

[emacs-wiki-discuss] Nesting Sections in Muse.


From: Phillip Lord
Subject: [emacs-wiki-discuss] Nesting Sections in Muse.
Date: Fri, 28 Oct 2005 10:45:55 +0100


I've knocked up this package which supports nested
sections for muse. At the moment, it only does unordered
lists, but it's relatively naturally extensible to 
ordered as well. 

For it to work properly, it really needs changes to 
core muse, and, in particular, the publishing model, 
which means that all styles would have to be supported
(to differentiate, "start list", "list item" and "end list"). 

Would there be any interest in this? I'm quite happy
to contribute the work. 

Cheers

Phil



;;; muse-nested.el -- Nested Sections hack for muse

;; $Revision:  $
;; $Date:  $

;; This file is not part of Emacs

;; Author: Phillip Lord <address@hidden>
;; Maintainer: Phillip Lord <address@hidden>
;; Website: http://www.russet.org.uk

;; COPYRIGHT NOTICE
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA. 

;;: Status:
;; 
;; Nearly done now. The current system doesn't differentiate between
;; start of list and list item. Making this differentiate properly
;; should enable nested lists with a reasonable syntax. 

;; Need to check that this markup doesn't confuse everything else. 

;; I've modified both latex and html styles, but all styles would be
;; required to get this to work properly. 

;; I'm going to need to modify the markup some what however. I need
;; >-, I think, so that I can also do >1 for enumerated lists.

;; I don't understand why I need to put a new line before the >
;; markup, but you do. 


(require 'assoc)

;; regexp for nested markup's
(add-to-list 
 'muse-publish-markup-regexps
 `(2250
   ,(concat "^["
            muse-regexp-blank
            "]+\\([>]\\)")
   0 ul-list-open))

(add-to-list
 'muse-publish-markup-regexps
 `(2251
   ,(concat "^["
            muse-regexp-blank
            "]+\\([<]\\)")
   0 ul-list-close))


;; store the new functions to deal with publication of the extra
;; markup. 

(aput 'muse-publish-markup-functions
      'ul-list-open 'muse-nested-list-open)


(aput 'muse-publish-markup-functions
      'ul-list-close 'muse-nested-list-close)


             
;; insert the ul open and close tags
(defun muse-nested-list-open ()
  (delete-region (match-beginning 0)(match-end 0))
  (insert (muse-markup-text 'begin-ul)))

(defun muse-nested-list-close ()
  (delete-region (match-beginning 0)(match-end 0))
  (insert (muse-markup-text 'end-ul)))


;; put the mark up strings to cope with unordered lists.
(aput 'muse-html-markup-strings
      'begin-ul "<ul>")

(aput 'muse-html-markup-strings
      'end-ul "</ul>")

(aput 'muse-html-markup-strings
      'begin-li "<li>")

(aput 'muse-html-markup-strings
      'end-li "</li>")

;; delete the existing stuff, so that I know I don't need it. 
(adelete 'muse-html-markup-strings 'begin-uli)
(adelete 'muse-html-markup-strings 'end-uli)


(aput 'muse-latex-markup-strings
      'begin-ul "\\begin{itemize}")

(aput 'muse-latex-markup-strings
      'end-ul "\\end{itemize}")

(aput 'muse-latex-markup-strings
      'begin-li "\\item ")

(aput 'muse-latex-markup-strings
      'end-li "")

(adelete 'muse-latex-markup-strings 'begin-uli)
(adelete 'muse-latex-markup-strings 'end-uli)



;; this is a copy of the existing function stolen from
muse-publish-markup
;; modified to cope with ul's
(defun muse-publish-markup-list ()
  "Markup a list entry or quoted paragraph.
The reason this function is so funky, is to prevent text properties
like read-only from being inadvertently deleted."
  (let ((str (match-string 1)))
    (cond
     ((and (eq (aref str 0) ?-))
      (delete-region (match-beginning 0) (match-end 0))
      (muse-publish-surround-text
       (concat 
        (muse-markup-text 'begin-ul)
        "\n"
        (muse-markup-text 'begin-li))
       (concat
        (muse-markup-text 'end-li)
        "\n"
        (muse-markup-text 'end-ul))
       (function
        (lambda ()
          (muse-forward-paragraph (concat "["
                                          muse-regexp-blank
                                          "]+-"))))))
     ((and (>= (aref str 0) ?0)
           (<= (aref str 0) ?9))
      (delete-region (match-beginning 0) (match-end 0))
      (muse-publish-surround-text
       (muse-markup-text 'begin-oli)
       (muse-markup-text 'end-oli)
       (function
        (lambda ()
          (muse-forward-paragraph (concat "["
                                          muse-regexp-blank
                                          "]+[0-9]+\\."))))))
     (t
      (goto-char (match-beginning 1))
      (insert (muse-markup-text 'begin-ddt))
      (save-match-data
        (save-excursion
          (forward-line 1)
          (while (looking-at (concat "^\\(["
                                     muse-regexp-blank
                                     "]*\\)[^"
                                     muse-regexp-space
                                     "]"))
            (delete-region (match-beginning 1) (match-end 1))
            (forward-line 1))))
      (save-match-data
        (when (re-search-forward (concat "["
                                         muse-regexp-space
                                         "]+::["
                                         muse-regexp-space
                                         "]+")
                                 nil t)
          (replace-match (muse-markup-text 'start-dde))))
      (muse-forward-paragraph)
      (insert (muse-markup-text 'end-ddt) ?\n)))))



;; Here is the test document.

;;  - Level 1 a
;;  - Level 1 b

;;  >
;;  - Level 2 a
;;  - Level 2 b

;;  >
;;  - Level 3 a

;;  <
;;  - Level 2 c
;;  - Level 2 d
 
;;  <
;;  - Level 1 c
;;  - Level 1 d

       

;; There needs to be some new markup here. 

;;  - A new list
 

(provide 'muse-nested)




reply via email to

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