From 4b90c30da3e62f9b9ee4661ec38c76507830b3e6 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Wed, 3 Jan 2007 23:38:07 +0000 Subject: [PATCH] Make tag work with markup="src" 2007-01-03 Michael Olson * lisp/muse-html.el (muse-html-src-tag): Document. * lisp/muse-publish.el (muse-publish-call-tag-on-buffer): New command that calls a given tag on the current buffer. Attributes may be passed. (muse-publish-examplify-buffer, muse-publish-versify-buffer): Use it. (muse-publish-srcify-buffer): New function that allows markup="src" in the tag. (muse-publish-get-and-delete-attr): New macro that gets an attribute from a list and removes the first instance of that attribute from said list. (muse-publish-markup-attribute): Handle markup="src". (muse-publish-command-tag, muse-publish-include-tag): Use muse-publish-get-and-delete-attr. This allows the remaining attributes to be passed. * texi/muse.texi (Tag Summary): Update for new tag as well as changes to and . git-archimport-id: mwolson@gnu.org--2006/muse--main--1.0--patch-264 --- ChangeLog | 22 ++++++++++++++++++ lisp/muse-html.el | 7 ++++++ lisp/muse-publish.el | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- texi/muse.texi | 19 +++++++++++++++ 4 files changed, 103 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e1ee12..c039437 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2007-01-03 Michael Olson + + * lisp/muse-html.el (muse-html-src-tag): Document. + + * lisp/muse-publish.el (muse-publish-call-tag-on-buffer): New + command that calls a given tag on the current buffer. Attributes + may be passed. + (muse-publish-examplify-buffer, muse-publish-versify-buffer): Use + it. + (muse-publish-srcify-buffer): New function that allows + markup="src" in the tag. + (muse-publish-get-and-delete-attr): New macro that gets an + attribute from a list and removes the first instance of that + attribute from said list. + (muse-publish-markup-attribute): Handle markup="src". + (muse-publish-command-tag, muse-publish-include-tag): Use + muse-publish-get-and-delete-attr. This allows the remaining + attributes to be passed. + + * texi/muse.texi (Tag Summary): Update for new tag as well + as changes to and . + 2006-12-30 Michael Olson * NEWS: Update. diff --git a/lisp/muse-html.el b/lisp/muse-html.el index 1680f6f..ac6b167 100644 --- a/lisp/muse-html.el +++ b/lisp/muse-html.el @@ -547,6 +547,13 @@ This will be used if no special characters are found." (muse-insert-markup "")) (defun muse-html-src-tag (beg end attrs) + "Publish the region using htmlize. +The language to use may be specified by the \"lang\" attribute. + +Muse will look for a function named LANG-mode, where LANG is the +value of the \"lang\" attribute. + +This tag requires htmlize 1.34 or later in order to work." (if (condition-case nil (progn (require 'htmlize) diff --git a/lisp/muse-publish.el b/lisp/muse-publish.el index a28a666..c1df092 100644 --- a/lisp/muse-publish.el +++ b/lisp/muse-publish.el @@ -1549,19 +1549,58 @@ This is usually applied to explicit links." (defalias 'muse-publish-class-tag 'ignore) -(defun muse-publish-examplify-buffer () +(defun muse-publish-call-tag-on-buffer (tag &optional attrs) + "Transform the current buffer as if it were surrounded by the tag TAG. +If attributes ATTRS are given, pass them to the tag function." + (let ((tag-info (if muse-inhibit-style-tags + (assoc tag muse-publish-markup-tags) + (muse-markup-tag-info tag)))) + (when tag-info + (let* ((end (progn (goto-char (point-max)) (point-marker))) + (args (list (point-min) end)) + (muse-inhibit-style-tags nil)) + (when (nth 2 tag-info) + (nconc args (list attrs))) + (apply (nth 4 tag-info) args))))) + +(defun muse-publish-examplify-buffer (&optional attrs) "Transform the current buffer as if it were an region." - (let ((end (progn (goto-char (point-max)) (point-marker)))) - (muse-publish-example-tag (point-min) end))) + (muse-publish-call-tag-on-buffer "example" attrs)) -(defun muse-publish-versify-buffer () +(defun muse-publish-srcify-buffer (&optional attrs) + "Transform the current buffer as if it were a region." + (muse-publish-call-tag-on-buffer "src" attrs)) + +(defun muse-publish-versify-buffer (&optional attrs) "Transform the current buffer as if it were a region." - (muse-publish-verse-tag (point-min) (point-max)) + (muse-publish-call-tag-on-buffer "verse" attrs) (muse-publish-markup "" `((100 ,(concat "^[" muse-regexp-blank "]*> ") 0 muse-publish-markup-verse))) (goto-char (point-min))) +(defmacro muse-publish-get-and-delete-attr (attr attrs) + "Delete attribute ATTR from ATTRS only once, destructively. + +This function returns the matching attribute value, if found." + (let ((last (make-symbol "last")) + (found (make-symbol "found")) + (vals (make-symbol "vals"))) + `(let ((,vals ,attrs)) + (if (string= (caar ,vals) ,attr) + (prog1 (cdar ,vals) + (setq ,attrs (cdr ,vals))) + (let ((,last ,vals) + (,found nil)) + (while ,vals + (setq ,vals (cdr ,vals)) + (when (string= (caar ,vals) ,attr) + (setq ,found (cdar ,vals)) + (setcdr ,last (cdr ,vals)) + (setq ,vals nil)) + (setq ,last ,vals)) + ,found))))) + (defmacro muse-publish-markup-attribute (beg end attrs reinterp &rest body) "Evaluate BODY within the bounds of BEG and END. ATTRS is an alist. Only the \"markup\" element of ATTRS is acted @@ -1578,14 +1617,18 @@ being further interpreted by Muse. If \"example\", treat the region as if it was surrounded by the tag. +If \"src\", treat the region as if it was surrounded by the + tag. + If \"verse\", treat the region as if it was surrounded by the tag, to preserve newlines. Otherwise, it should be the name of a function to call in the -narrowed region after evaluating BODY." +narrowed region after evaluating BODY. The function should +take the ATTRS parameter." (let ((markup (make-symbol "markup")) (markup-function (make-symbol "markup-function"))) - `(let ((,markup (cdr (assoc "markup" ,attrs)))) + `(let ((,markup (muse-publish-get-and-delete-attr "markup" ,attrs))) (save-restriction (narrow-to-region ,beg ,end) (goto-char (point-min)) @@ -1598,13 +1641,15 @@ narrowed region after evaluating BODY." (let ((,markup-function (read ,markup))) (cond ((eq ,markup-function 'example) (setq ,markup-function #'muse-publish-examplify-buffer)) + ((eq ,markup-function 'src) + (setq ,markup-function #'muse-publish-srcify-buffer)) ((eq ,markup-function 'verse) (setq ,markup-function #'muse-publish-versify-buffer)) ((and ,markup-function (not (functionp ,markup-function))) (error "Invalid markup function `%s'" ,markup)) (t nil)) (if ,markup-function - (funcall ,markup-function) + (funcall ,markup-function ,attrs) (muse-publish-mark-read-only (point-min) (point-max)) (goto-char (point-max))))))))) @@ -1629,7 +1674,7 @@ narrowed region after evaluating BODY." (muse-publish-markup-attribute beg end attrs nil (while (looking-at "\\s-*$") (forward-line)) - (let ((interp (cdr (assoc "interp" attrs)))) + (let ((interp (muse-publish-get-and-delete-attr "interp" attrs))) (if interp (shell-command-on-region (point) (point-max) interp t t) (shell-command @@ -1677,7 +1722,7 @@ narrowed region after evaluating BODY." The `markup' attribute controls how this file is marked up after being inserted. See `muse-publish-markup-attribute' for an explanation of how it works." - (let ((filename (cdr (assoc "file" attrs))) + (let ((filename (muse-publish-get-and-delete-attr "file" attrs)) (muse-publishing-directives muse-publishing-directives)) (if filename (setq filename (expand-file-name diff --git a/texi/muse.texi b/texi/muse.texi index be44f1b..f727a0c 100644 --- a/texi/muse.texi +++ b/texi/muse.texi @@ -1064,6 +1064,10 @@ further interpreting it. If "example", treat the region as if it was surrounded by the @verb{||} tag. +If "src", treat the included text as if it was surrounded by the +@verb{||} tag. You should also specify the ``lang'' attribute if +doing this. + If "verse", treat the region as if it was surrounded by the @verb{||} tag, to preserve newlines. @@ -1108,6 +1112,10 @@ If "nil", do not mark up the included text at all. If "example", treat the included text as if it was surrounded by the @verb{||} tag. +If "src", treat the included text as if it was surrounded by the +@verb{||} tag. You should also specify the ``lang'' attribute if +doing this. + If "verse", treat the included text as if it was surrounded by the @verb{||} tag, to preserve newlines. @@ -1169,6 +1177,17 @@ region with the result of the command. This tag takes the ``markup'' argument. See the description of @verb{||} for details. +@item +Publish the region using htmlize. +The language to use may be specified by the ``lang'' attribute. + +Muse will look for a function named @var{lang}-mode, where @var{lang} is +the value of the ``lang'' attribute. + +This tag requires htmlize 1.34 or later in order to work. If this is +not satisfied, or the current publishing style is not HTML-based, Muse +will publish the region like an @verb{||} tag. + @item This is used when you want to prevent Muse from trying to interpret some markup. Surround the markup in @verb{||} and -- 2.11.4.GIT