Merged from hodique@lifl.fr--2005 (patch 0-1)
[muse-el.git] / muse-message.el
blob5e8d94716ef80a0017b63f9bda8f1ad013951659
1 ;;; muse-message.el --- Publish a file as an email message.
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
10 ;; version.
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ;; for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 ;; MA 02111-1307, USA.
22 ;;; Commentary:
24 ;; To make use of this file, put (require 'muse-message) in your .emacs.
26 ;; By default, the way to mark up an email message is to do the
27 ;; following.
29 ;; - Enter Message mode. This is usually done automatically when you
30 ;; compose an email message using your Emacs mail client of choice.
32 ;; - Use standard Muse markup instead of plain text for your message.
34 ;; - When you are ready to see what the email message will look like,
35 ;; do `M-x muse-message-markup'. This will make two versions of
36 ;; your message: plaintext and HTML.
38 ;; - If you want to do further editing, simply undo your changes,
39 ;; edit some more, and run `muse-message-markup' when you're ready
40 ;; to send.
42 ;; - Send the message.
44 ;; If you wish the markup to be automatic at the time of sending you
45 ;; message (a risky proposition), just add `muse-message-markup' to
46 ;; `message-send-hook'.
48 ;;; Contributors:
50 ;;; Code:
52 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54 ;; Muse E-Mail Publishing (via alternative/html)
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 (require 'message)
59 (require 'footnote)
61 (require 'muse-publish)
62 (require 'muse-html)
64 (defgroup muse-message nil
65 "Options controlling the behaviour of Emacs Wiki Mail Markup."
66 :group 'hypermedia
67 :group 'muse-publish)
69 (defcustom muse-message-publishing-style "message"
70 "Style used for publishing the alternative/text section of a message."
71 :type 'string
72 :group 'muse-message)
74 (defcustom muse-message-html-publishing-style "message-html"
75 "Style used for publishing the alternative/html section of a message."
76 :type 'string
77 :group 'muse-message)
79 (defcustom muse-message-indent " "
80 "String used to pad indentend text."
81 :type 'string
82 :group 'muse-message)
84 (defcustom muse-message-style-sheet
85 "body {
86 background: white; color: black;
87 margin-left: 3%; margin-right: 7%;
90 p { margin-top: 1% }
91 p.verse { margin-left: 3% }
93 .example { margin-left: 3% }
95 h2 {
96 margin-top: 25px;
97 margin-bottom: 0px;
99 h3 { margin-bottom: 0px; }"
100 "Text to prepend to a Muse mail message being published.
101 This text may contain <lisp> markup tags."
102 :type 'string
103 :group 'muse-message)
105 (defcustom muse-message-html-header
106 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">
107 <html>
108 <head>
109 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
110 <meta name=\"generator\" content=\"muse-message.el\">
111 <link rev=\"made\" href=\"<lisp>user-mail-address</lisp>\">
112 <style type=\"text/css\">
113 <lisp>muse-message-style-sheet</lisp>
114 </style>
115 </head>
116 <body>
117 <!-- Mail published by Emacs Muse begins here -->\n"
118 "Text to prepend to a Muse mail message being published.
119 This text may contain <lisp> markup tags."
120 :type 'string
121 :group 'muse-message)
123 (defcustom muse-message-html-footer
124 "\n <!-- Mail published by Emacs Muse ends here -->
125 </body>
126 </html>\n"
127 "Text to append to a Muse mail message being published.
128 This text may contain <lisp> markup tags."
129 :type 'string
130 :group 'muse-message)
132 (defcustom muse-message-markup-functions
133 '((link . muse-message-markup-link))
134 "An alist of style types to custom functions for that kind of text.
135 For more on the structure of this list, see
136 `muse-publish-markup-functions'."
137 :type '(alist :key-type symbol :value-type function)
138 :group 'muse-message)
140 (defcustom muse-message-markup-strings
141 '((rule . " * * * *")
142 (begin-verse . " ")
143 (end-verse-line . "\n ")
144 (verse-space . " ")
145 (end-verse . "")
146 (begin-underline . "_")
147 (end-underline . "_")
148 (begin-literal . "`")
149 (end-literal . "'")
150 (begin-emph . "/")
151 (end-emph . "/")
152 (begin-more-emph . "*")
153 (end-more-emph . "*")
154 (begin-most-emph . "*/")
155 (end-most-emph . "/*"))
156 "Strings used for marking up message text."
157 :type '(alist :key-type symbol :value-type string)
158 :group 'muse-message)
160 (defcustom muse-message-markup-tags
161 '(("example" t nil muse-message-example-tag)
162 ("contents" nil t muse-message-contents-tag))
163 "A list of tag specifications, for specially marking up text.
164 See the documentation for `muse-publish-markup-tags'."
165 :type '(repeat (list (string :tag "Markup tag")
166 (boolean :tag "Expect closing tag" :value t)
167 (boolean :tag "Parse attributes" :value nil)
168 function))
169 :group 'muse-message)
171 (defcustom muse-message-markup-specials nil
172 "A table of characters which must be represented specially."
173 :type '(alist :key-type character :value-type string)
174 :group 'muse-message)
176 (defun muse-message-markup-link ()
177 (let ((desc (match-string 2))
178 (url (match-string 1)))
179 (save-match-data
180 (delete-region (match-beginning 0) (match-end 0))
181 (when desc (insert desc))
182 (save-excursion
183 (Footnote-add-footnote)
184 (insert url))
185 "")))
187 (defun muse-message-example-tag (beg end)
188 "Mark up example and code by simply indenting them."
189 (muse-publish-escape-specials beg end)
190 (kill-line 1)
191 (goto-char end)
192 (kill-line -1)
193 (string-rectangle beg (point) muse-message-indent)
194 (muse-publish-mark-read-only beg (point)))
196 ;;;###autoload
197 (defun muse-message-markup ()
198 "Markup a wiki-ish e-mail message as HTML alternative e-mail.
199 This step is manual by default, to give the author a chance to review
200 the results and ensure they are appropriate.
201 If you wish it to be automatic (a risky proposition), just add this
202 function to `message-send-hook'."
203 (interactive)
204 (save-excursion
205 (message-goto-body)
206 (let ((text (buffer-substring-no-properties (point) (point-max)))
207 (subject (message-fetch-field "subject"))
208 (encoding (muse-html-encoding)))
209 (delete-region (point) (point-max))
210 (insert
211 "<#multipart type=alternative>\n"
212 "<#part type=text/plain charset=\"" encoding "\" nofile=yes>\n"
213 (with-temp-buffer
214 (insert text)
215 (muse-publish-markup-buffer
216 subject muse-message-publishing-style)
217 (buffer-substring-no-properties (point-min) (point-max)))
218 "\n<#part type=text/html charset=\"" encoding "\" nofile=yes>\n"
219 (with-temp-buffer
220 (insert text)
221 (muse-publish-markup-buffer
222 subject muse-message-html-publishing-style)
223 (buffer-substring-no-properties (point-min) (point-max)))
224 "<#/multipart>\n"))))
226 (unless (assoc "message" muse-publishing-styles)
227 (muse-define-style "message"
228 :functions 'muse-message-markup-functions
229 :strings 'muse-message-markup-strings
230 :tags 'muse-message-markup-tags)
232 (muse-derive-style "message-html" "html"
233 :header 'muse-message-html-header
234 :footer 'muse-message-html-footer)
236 (muse-derive-style "message-xhtml" "xhtml"
237 :header 'muse-message-html-header
238 :footer 'muse-message-html-footer))
240 (provide 'muse-message)
242 ;;; muse-message.el ends here