muse-latex2png: Don't touch preceding blank line unless Latex style
[muse-el.git] / examples / mwolson / muse-init.el
blobe8d63993797af9c5a281a20558753f8dcf0522a0
1 ;;; muse-init.el --- Initialize Emacs Muse
3 ;; Author: Michael Olson
5 ;; In order to see the scripts that I use to publish my website to a
6 ;; remote webserver, check out
7 ;; http://www.mwolson.org/projects/SiteScripts.html.
9 ;;; Setup
11 ;; Add to load path
12 (add-to-list 'load-path "/home/mwolson/proj/emacs/muse/mwolson/lisp")
13 (add-to-list 'load-path "/home/mwolson/proj/emacs/muse/mwolson/experimental")
15 ;; Initialize
16 (require 'outline) ; I like outline-style faces
17 (require 'muse) ; load generic module
18 (require 'muse-colors) ; load coloring/font-lock module
19 (require 'muse-mode) ; load authoring mode
20 (require 'muse-blosxom) ; load blosxom module
21 (require 'muse-docbook) ; load DocBook publishing style
22 (require 'muse-html) ; load (X)HTML publishing style
23 (require 'muse-latex) ; load LaTeX/PDF publishing styles
24 (require 'muse-latex2png) ; publish <latex> tags
25 (require 'muse-texinfo) ; load Info publishing style
26 (require 'muse-wiki) ; load Wiki support
27 (require 'muse-xml) ; load XML support
28 ;;(require 'muse-message) ; load message support (experimental)
30 ;; Setup projects
32 ;; Here is an example of making a customized version of your favorite
33 ;; publisher. All this does is run `my-muse-blosoxm-finalize' on the
34 ;; published file immediately after saving it.
35 (muse-derive-style "my-blosxom" "blosxom-xhtml"
36 :final 'my-muse-blosxom-finalize)
38 ;; This turns relative links into absolute links
39 (muse-derive-style "my-pdf" "pdf"
40 :before 'my-muse-pdf-prepare-buffer)
42 ;; This uses a different header and footer than normal
43 (muse-derive-style "my-xhtml" "xhtml"
44 :header "~/personal-site/muse/header.html"
45 :footer "~/personal-site/muse/footer.html")
47 ;; Here is my master project listing.
49 (setq muse-project-alist
51 ("Website" ("~/proj/wiki/web/" "~/proj/wiki/web/testdir/"
52 :force-publish ("WikiIndex")
53 :default "WelcomePage")
54 (:base "my-xhtml"
55 :include "/web/[^/]+"
56 :path "~/personal-site/site/web")
57 (:base "my-xhtml"
58 :include "/testdir/[^/]+"
59 :path "~/personal-site/site/web/testdir")
60 (:base "my-pdf"
61 :path "~/personal-site/site/web"
62 :include "/CurriculumVitae[^/]*$"))
64 ("Projects" ("~/proj/wiki/projects/"
65 :force-publish ("WikiIndex")
66 :default "WelcomePage")
67 (:base "my-xhtml"
68 :path "~/personal-site/site/projects"))
70 ("Blog" (,@(muse-project-alist-dirs "~/proj/wiki/blog")
71 :default "index")
73 ;; Publish this directory and its subdirectories. Arguments
74 ;; are as follows. The above `muse-project-alist-dirs' part
75 ;; is also needed, using Argument 1.
77 ;; 1. Source directory
78 ;; 2. Output directory
79 ;; 3. Publishing style
80 ,@(muse-project-alist-styles "~/proj/wiki/blog"
81 "~/personal-site/site/blog"
82 "my-blosxom"))
84 ("MyNotes" ("~/proj/wiki/notes/"
85 :force-publish ("index")
86 :default "index")
87 (:base "xhtml"
88 :path "~/personal-site/site/notes")
89 (:base "my-pdf"
90 :path "~/personal-site/site/notes"))
92 ("Private" ("~/Documents" "~/Documents/work-school"
93 :default "movielist")
94 ,@(muse-project-alist-styles "~/Documents"
95 "~/Documents"
96 "pdf"))
98 ("Classes" (,@(muse-project-alist-dirs "~/proj/wiki/classes")
99 :default "index")
100 ,@(muse-project-alist-styles "~/proj/wiki/classes"
101 "~/personal-site/site/classes"
102 "xhtml"))
104 ("Plans" ("~/proj/wiki/plans/"
105 :default "TaskPool"
106 :major-mode planner-mode
107 :visit-link planner-visit-link)
108 (:base "planner-xhtml"
109 :path "~/proj/notmine/planner-out"))
112 ;; Wiki settings
113 (setq muse-wiki-interwiki-alist
114 '(("PlugWiki" . "http://plug.student-orgs.purdue.edu/wiki/")
115 ("EmacsWiki" . "http://www.emacswiki.org/cgi-bin/wiki/")
116 ("ArchWiki" . "http://gnuarch.org/gnuarchwiki/")
117 ;; abbreviations
118 ("CERIAS" . "http://www.cerias.purdue.edu/")
119 ("PlannerMode" . "http://www.emacswiki.org/cgi-bin/wiki/PlannerMode")
120 ("RememberMode" . "http://www.emacswiki.org/cgi-bin/wiki/RememberMode")
121 ("GP2X" . "http://www.gp2x.co.uk/")
122 ("UbuntuLinux" . "http://ubuntulinux.org/")
123 ("PLUG" . "http://plug.student-orgs.purdue.edu/wiki/")
124 ("PAC" . "http://web.ics.purdue.edu/~pac/")))
126 ;;; Functions
128 ;; Turn relative links into absolute ones
129 (defun my-muse-pdf-make-links-absolute (str &rest ignored)
130 "Make relative links absolute."
131 (when str
132 (save-match-data
133 (if (string-match "\\`[/.]+" str)
134 (replace-match "http://www.mwolson.org/" nil t str)
135 str))))
137 ;; Make sure my interproject links become absolute when published in
138 ;; PDFs
139 (defun my-muse-pdf-prepare-buffer ()
140 (set (make-local-variable 'muse-publish-url-transforms)
141 (cons 'my-muse-pdf-make-links-absolute muse-publish-url-transforms)))
143 ;; Switch to the given project and prompt for a file
144 (defun my-muse-project-find-file (project)
145 (interactive)
146 (let ((muse-current-project (muse-project project)))
147 (call-interactively 'muse-project-find-file)))
149 ;; Determine whether we are publishing a certain kind of output
150 (defun my-muse-format-p (format)
151 (let ((base (muse-get-keyword :base muse-publishing-current-style)))
152 (when base (string-match format base))))
154 (defun my-muse-blosxom-finalize (file output-path target)
155 ;; (my-muse-prepare-entry-for-xanga output-path)
156 ;; For now, do nothing.
159 ;; Make the current file display correctly in Xanga
160 ;; I call this using C-c p x now.
161 (defun my-muse-prepare-entry-for-xanga (file)
162 "Mangle FILE so that Xanga doesn't bug out, saving to X clipboard.
164 If FILE is not specified, use the published version of the current file."
165 (interactive
166 (list
167 (expand-file-name (concat (muse-page-name) muse-blosxom-extension)
168 (muse-style-element
169 :path (car (muse-project-applicable-styles
170 buffer-file-name
171 (cddr (muse-project-of-file))))))))
172 (save-match-data
173 (muse-with-temp-buffer
174 (insert-file-contents file)
175 ;; surround first line in <h3></h3>
176 (goto-char (point-min))
177 (insert "<h3>")
178 (end-of-line)
179 (insert "</h3>")
180 ;; treat example regions properly
181 (let (beg end)
182 (while (re-search-forward "<pre[^>]*>" nil t)
183 (setq beg (match-end 0))
184 (setq end (if (re-search-forward "</pre>" nil 1)
185 (match-beginning 0)
186 (point)))
187 (save-restriction
188 (narrow-to-region beg end)
189 ;; change initial spaces to &nbsp;
190 (goto-char (point-min))
191 (while (re-search-forward "^ +" nil t)
192 (replace-match (apply 'concat (make-list
193 (length (match-string 0))
194 "&nbsp;"))))
195 ;; change newline to <br />
196 (goto-char (point-min))
197 (while (re-search-forward "\n" nil t)
198 (replace-match "<br />")))))
199 ;; get rid of 2 spaces together and merge lines
200 (goto-char (point-min))
201 (while (re-search-forward (concat "[" muse-regexp-blank "\n]+") nil t)
202 (replace-match " "))
203 ;; remove trailing space
204 (goto-char (point-min))
205 (while (re-search-forward " *</p> *" nil t)
206 (replace-match "</p>"))
207 ;; make relative links work
208 (goto-char (point-min))
209 (while (re-search-forward "href=\"[/.]+" nil t)
210 (replace-match "href=\"http://www.mwolson.org/" nil t))
211 ;; copy entry to clipboard
212 (clipboard-kill-ring-save (point-min) (point-max))
213 (message "Copied blog entry to clipboard"))))
215 ;; Turn a word or phrase into a clickable Wikipedia link
216 (defun my-muse-dictize (beg end)
217 (interactive "r")
218 (let* ((text (buffer-substring-no-properties beg end))
219 (link (concat "dict:" (replace-regexp-in-string " " "_" text t t))))
220 (delete-region beg end)
221 (insert "[[" link "][" text "]]")))
223 ;;; Key customizations
225 (global-set-key "\C-cpl" 'muse-blosxom-new-entry)
226 (global-set-key "\C-cpL" #'(lambda () (interactive)
227 (my-muse-project-find-file "Blog")))
228 (global-set-key "\C-cpi" #'(lambda () (interactive)
229 (my-muse-project-find-file "Private")))
230 (global-set-key "\C-cpn" #'(lambda () (interactive)
231 (my-muse-project-find-file "MyNotes")))
232 (global-set-key "\C-cpp" #'(lambda () (interactive)
233 (my-muse-project-find-file "Plans")))
234 (global-set-key "\C-cpr" #'(lambda () (interactive)
235 (my-muse-project-find-file "Projects")))
236 (global-set-key "\C-cps" #'(lambda () (interactive)
237 (my-muse-project-find-file "Classes")))
238 (global-set-key "\C-cpw" #'(lambda () (interactive)
239 (my-muse-project-find-file "Website")))
240 (global-set-key "\C-cpW" 'my-muse-dictize)
241 (global-set-key "\C-cpx" 'my-muse-prepare-entry-for-xanga)
243 ;;; Custom variables
245 (custom-set-variables
246 '(muse-blosxom-base-directory "~/proj/wiki/blog/")
247 '(muse-colors-autogen-headings (quote outline))
248 '(muse-colors-inline-image-method (quote muse-colors-use-publishing-directory))
249 '(muse-html-charset-default "utf-8")
250 '(muse-html-encoding-default (quote utf-8))
251 '(muse-html-footer "~/personal-site/muse/generic-footer.html")
252 '(muse-html-header "~/personal-site/muse/generic-header.html")
253 '(muse-html-meta-content-encoding (quote utf-8))
254 '(muse-html-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/common.css\" />
255 <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"screen\" href=\"/screen.css\" />
256 <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"print\" href=\"/print.css\" />")
257 '(muse-latex-header "~/personal-site/muse/header.tex")
258 '(muse-mode-hook (quote (flyspell-mode footnote-mode)))
259 '(muse-publish-comments-p t)
260 '(muse-publish-desc-transforms (quote (muse-wiki-publish-pretty-title muse-wiki-publish-pretty-interwiki)))
261 '(muse-wiki-publish-small-title-words (quote ("the" "and" "at" "on" "of" "for" "in" "an" "a" "page")))
262 '(muse-xhtml-footer "~/personal-site/muse/generic-footer.html")
263 '(muse-xhtml-header "~/personal-site/muse/generic-header.html")
264 '(muse-xhtml-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/common.css\" />
265 <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"screen\" href=\"/screen.css\" />
266 <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"print\" href=\"/print.css\" />"))
267 (custom-set-faces
268 '(muse-bad-link ((t (:foreground "DeepPink" :underline "DeepPink" :weight bold)))))
270 ;;; muse-init.el ends here