Minor code cleanup to address elint issues.
[muse-el.git] / examples / johnw / muse-johnw.el
blob379d42197ae1d7061c44a9718ed3fb57dd19b97f
1 (require 'muse)
2 (require 'muse-mode)
3 (require 'muse-colors)
4 (require 'muse-project)
5 (require 'muse-book)
7 (require 'muse-html)
8 (require 'muse-latex)
9 (require 'muse-texinfo)
11 (require 'muse-journal)
12 (require 'muse-poem)
13 (require 'muse-message)
15 (require 'muse-http)
17 ;;(require 'muse-arabic)
18 ;;(require 'muse-cite)
20 (eval-after-load "whitespace"
21 '(add-to-list 'whitespace-modes 'muse-mode))
23 (defun muse-maybe-convert-poem ()
24 (if (string-match "/poems" muse-publishing-current-file)
25 (muse-poem-prepare-buffer)))
27 (defun muse-insert-reset-chapter ()
28 (insert "\n\\setcounter{chapter}{1}\n"))
30 (defun muse-insert-all-poems-header ()
31 (insert "\n\\renewcommand{\\poemtoc}{chapter}
32 \\settocdepth{chapter}\n"))
34 ;; I use my own sectioning commands in conjunction with memoir.cls
35 (setcdr (assq 'chapter muse-latex-markup-strings) "\\mychapter{")
36 (setcdr (assq 'section muse-latex-markup-strings) "\\mysection{")
37 (setcdr (assq 'subsection muse-latex-markup-strings) "\\mysubsection{")
38 (setcdr (assq 'subsubsection muse-latex-markup-strings) "\\mysubsubsection{")
40 ;; Relocate the images directory
41 ;(setcdr (assq 'image-with-desc muse-latex-markup-strings)
42 ; "\\includegraphics[width=\\textwidth]{../%s}")
43 (setcdr (assq 'image-with-desc muse-latex-markup-strings)
44 "\\includegraphics[scale=0.6]{../%s}")
45 (setcdr (assq 'image-link muse-latex-markup-strings)
46 "\\includegraphics[scale=0.6]{../%s}")
47 (setcdr (assq 'url-with-image muse-latex-markup-strings)
48 "%% %s\n\\includegraphics[scale=0.6]{../%s}")
50 (unless (assoc "site-html" muse-publishing-styles)
51 (muse-derive-style "site-html" "html"
52 :maintainer "jwiegley@hotmail.com"
53 :before 'muse-maybe-convert-poem
54 :after 'muse-my-html-finalize-buffer
55 :header "~/Documents/site/header.html"
56 :footer "~/Documents/site/footer.html")
57 (muse-derive-style "site-journal-html" "journal-html"
58 :maintainer "jwiegley@hotmail.com"
59 :before 'muse-my-journal-find-entries
60 :after 'muse-my-journal-insert-contents
61 :header "~/Documents/site/header.html"
62 :footer "~/Documents/site/footer.html")
63 (muse-derive-style "newartisans-html" "html"
64 :maintainer "johnw@newartisans.com"
65 :header "~/Sites/newartisans/header.html"
66 :footer "~/Sites/newartisans/footer.html")
67 (muse-derive-style "newartisans-journal-html" "journal-html"
68 :maintainer "johnw@newartisans.com"
69 :header "~/Sites/newartisans/header.html"
70 :footer "~/Sites/newartisans/footer.html"))
72 (custom-set-variables
73 '(muse-project-alist
74 (quote
75 (("website" ; my various writings
76 (:book-part "Essays"
77 :book-funcall muse-insert-reset-chapter
78 "~/Documents/essays"
79 :book-part "Stories"
80 :book-funcall muse-insert-reset-chapter
81 "~/Documents/stories"
82 :book-part "Journal"
83 :book-style "journal-book-pdf"
84 :book-funcall muse-insert-reset-chapter
85 "~/Documents/journal/early"
86 "~/Documents/journal/summer2003"
87 "~/Documents/journal/j2003"
88 "~/Documents/journal/j2004"
89 "~/Documents/journal/journal"
90 :book-part "Poems"
91 :book-style "chapbook-pdf"
92 :book-funcall muse-insert-all-poems-header
93 :book-funcall muse-insert-reset-chapter
94 :nochapters t ; do automatically add chapters
95 :book-chapter "Mystical"
96 "~/Documents/poems/mystical"
97 :book-chapter "Romance"
98 "~/Documents/poems/romantic"
99 :book-chapter "Nature"
100 "~/Documents/poems/natural"
101 :book-chapter "Melancholoy"
102 "~/Documents/poems/melancholy"
103 :book-chapter "Commentary"
104 "~/Documents/poems/commentary"
105 :book-end t
106 "~/Documents/contents"
107 :default "journal")
109 (:base "html" :path "~/Sites/johnw"
110 :include "/contents/recent")
111 (:base "pdf" :path "~/Sites/johnw/pdf"
112 :include "/\\(essays\\|stories\\)/")
113 (:base "poem-pdf" :path "~/Sites/johnw/pdf"
114 :include "/poems/")
115 (:base "site-html" :path "~/Sites/johnw"
116 :exclude "/journal/")
117 (:base "journal-pdf" :path "~/Sites/johnw/pdf"
118 :include "/journal/")
119 (:base "site-journal-html" :path "~/Sites/johnw"
120 :include "/journal/")
121 (:base "journal-rdf" :path "~/Sites/johnw"
122 :include "/journal/journal"
123 :base-url "http://www.newartisans.com/johnw/")
124 (:base "journal-rss" :path "~/Sites/johnw"
125 :include "/journal/journal"
126 :base-url "http://www.newartisans.com/johnw/"))
127 ("newartisans" ; my company
128 ("~/Documents/newartisans"
129 :default "index")
130 (:base "newartisans-html" :path "~/Sites/newartisans"
131 :exclude "/news")
132 (:base "newartisans-journal-html" :path "~/Sites/newartisans"
133 :include "/news")))))
134 '(muse-mode-highlight-p t nil (muse-colors))
135 '(muse-mode-auto-p t nil (muse-project))
136 '(muse-latex-header "~/Documents/site/header.tex")
137 '(muse-latex-footer "~/Documents/site/footer.tex")
138 '(muse-book-latex-header "~/Documents/site/book-header.tex")
139 '(muse-poem-latex-header "~/Documents/site/poem-header.tex")
140 '(muse-poem-latex-footer "~/Documents/site/poem-footer.tex")
141 '(muse-chapbook-latex-header "~/Documents/site/chapbook-header.tex")
142 ;;'(muse-before-publish-hook (quote (muse-cite-munge-footnotes)))
143 '(muse-mode-hook (quote (list footnote-mode turn-on-auto-fill flyspell-mode))))
145 (defun muse-publish-my-books (&optional force)
146 (interactive "P")
147 (muse-book-publish-project
148 '("essays" ("~/Documents/essays"))
149 "essays" "Collected Essays" "book-pdf" "~/Sites/johnw/pdf" force)
150 (muse-book-publish-project
151 '("stories" ("~/Documents/stories"))
152 "stories" "Collected Stories" "book-pdf" "~/Sites/johnw/pdf" force)
153 (muse-book-publish-project
154 '("journal"
155 ("~/Documents/journal/early"
156 "~/Documents/journal/summer2003"
157 "~/Documents/journal/j2003"
158 "~/Documents/journal/j2004"
159 "~/Documents/journal/journal"
160 :book-end t
161 "~/Documents/poems/mystical"
162 "~/Documents/poems/romantic"
163 "~/Documents/poems/natural"
164 "~/Documents/poems/melancholy"
165 "~/Documents/poems/commentary"))
166 "thoughts" "Thought Journal" "journal-book-pdf" "~/Sites/johnw/pdf" force)
167 (muse-book-publish-project
168 '("poems"
169 (:nochapters t ; do automatically add chapters
170 :book-chapter "Mystical"
171 "~/Documents/poems/mystical"
172 :book-chapter "Romance"
173 "~/Documents/poems/romantic"
174 :book-chapter "Nature"
175 "~/Documents/poems/natural"
176 :book-chapter "Melancholoy"
177 "~/Documents/poems/melancholy"
178 :book-chapter "Commentary"
179 "~/Documents/poems/commentary"))
180 "poems" "Collected Poems" "chapbook-pdf" "~/Sites/johnw/pdf" force)
181 (muse-book-publish-project
182 "website" "writings" "Collected Writings" "book-pdf"
183 "~/Sites/johnw/pdf" force))
185 (defun modules-get-version-and-date (module)
186 (let (version date)
187 (with-temp-buffer
188 (insert-file-contents-literally module nil 0 1000)
189 (if (re-search-forward "Version:\\s-+\\(.*\\)" nil t)
190 (setq version (match-string 1))))
191 (setq date (format-time-string "%Y-%m-%d"
192 (nth 5 (file-attributes module))))
193 (concat (and muse-publishing-p "<span class=\"version\">")
194 (if version
195 (format "%s (%s)" date version)
196 date)
197 (and muse-publishing-p "</span>"))))
199 (defun muse-blog-add-entry ()
200 (interactive)
201 (muse-project-find-file "journal" "website")
202 (goto-char (point-min))
203 (forward-line 2)
204 (insert "* " (format-time-string "%Y%m%d: ")
205 (read-string "Journal entry title: ")
206 "\n\n\n\n")
207 (forward-line -2))
209 (defun muse-my-html-insert-contents (&optional ignore)
210 (let ((index 1)
211 base contents l)
212 (save-excursion
213 (goto-char (point-min))
214 (search-forward "Page published by Emacs Muse begins here" nil t)
215 (catch 'done
216 (while (re-search-forward "^<h\\([0-9]+\\)>\\(.+?\\)</h\\1>" nil t)
217 (unless (get-text-property (point) 'read-only)
218 (setq l (1- (string-to-number (match-string 1))))
219 (if (null base)
220 (setq base l)
221 (if (< l base)
222 (throw 'done t)))
223 (when (<= l 1)
224 (setq contents (cons (cons l (match-string-no-properties 2))
225 contents))
226 (goto-char (match-beginning 2))
227 (muse-html-insert-anchor (concat "sec" (int-to-string index)))
228 (setq index (1+ index)))))))
229 (setq index 1 contents (reverse contents))
230 (when (> (length contents) 0)
231 (goto-char (point-min))
232 (search-forward "<h2>Archives</h2>")
233 (beginning-of-line)
234 (insert "<h2>Contents</h2>\n\n<ul>\n")
235 (dolist (item contents)
236 (insert "<li><a href=\"" (muse-publish-output-name)
237 "#sec" (int-to-string index) "\">"
238 (muse-publish-strip-tags (cdr item))
239 "</a></li>\n")
240 (setq index (1+ index)))
241 (insert "</ul>\n"))))
243 (defun muse-my-html-finalize-buffer ()
244 (when muse-publish-generate-contents
245 (muse-my-html-insert-contents (cdr muse-publish-generate-contents))
246 (setq muse-publish-generate-contents nil)))
248 (defvar muse-my-journal-entries nil)
250 (defun muse-my-journal-find-entries ()
251 (goto-char (point-min))
252 (let ((heading-regexp (concat "^\\* " muse-journal-heading-regexp "$"))
253 (inhibit-read-only t)
254 entries)
255 (while (re-search-forward heading-regexp nil t)
256 (let ((date (match-string 1))
257 (title (match-string-no-properties 2))
258 qotd desc)
259 (save-match-data
260 (when (and date
261 (string-match
262 (concat "\\([1-9][0-9][0-9][0-9]\\)[./]?"
263 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date))
264 (setq date (encode-time 0 0 0
265 (string-to-number (match-string 3 date))
266 (string-to-number (match-string 2 date))
267 (string-to-number (match-string 1 date))
268 (current-time-zone)))))
269 (when title
270 (while (string-match "\\*" title)
271 (setq title (replace-match "" nil nil title)))
272 (set (make-local-variable 'muse-my-journal-entries)
273 (cons (cons title date)
274 muse-my-journal-entries)))))))
276 (defun muse-my-journal-insert-contents ()
277 (goto-char (point-min))
278 (search-forward "<h2>Archives</h2>")
279 (beginning-of-line)
280 (if (string= "journal" (muse-page-name))
281 (insert "<h2>Recent Entries</h2>\n\n<ul>\n")
282 (insert "<h2>Contents</h2>\n\n<ul>\n"))
283 (dolist (entry (nreverse muse-my-journal-entries))
284 ;;(setq date (format-time-string "%m/%d" date))
285 ;;(if (= ?0 (aref date 0))
286 ;; (setq date (substring date 1)))
287 (insert (format "<li><a href=\"%s#%s\">%s</a></li>\n"
288 (muse-publish-output-name)
289 (muse-journal-anchorize-title (car entry))
290 (car entry))))
291 (insert "</ul>\n\n"))
293 ;; (eval-when-compile
294 ;; (defvar muse-current-project))
296 ;; (defvar muse-ref-tag '("ref" nil t muse-ref-markup-tag))
298 ;; (defun muse-ref-markup-tag (beg end attrs)
299 ;; "This markup tag allows a poem to be included from another project page.
300 ;; The form of usage is:
301 ;; <ref title=\"page.name[#subtitle]\">"
302 ;; (let ((page (cdr (assoc (cdr (assoc "title" attrs))
303 ;; (muse-project-file-alist))))
304 ;; beg start end text)
305 ;; (if (null page)
306 ;; (insert " *Reference to\n unknown page \""
307 ;; (cdr (assoc "title" attrs)) "\".*\n")
308 ;; (setq beg (point))
309 ;; (let (title)
310 ;; (if (string-match "html" muse-publishing-current-style)
311 ;; t
312 ;; (insert
313 ;; (with-temp-buffer
314 ;; (insert-file-contents page)
315 ;; (goto-char (point-min))
316 ;; (forward-paragraph)
317 ;; (forward-line)
318 ;; (buffer-substring-no-properties (point) (point-max)))))))))
320 ;; (add-to-list 'muse-publish-markup-tags muse-ref-tag)
322 (when (and window-system (load "httpd" t))
323 (require 'muse-http)
324 ;;(add-hook 'after-init-hook 'httpd-start)
325 (setq httpd-document-root (expand-file-name "~/Sites/johnw")))
327 ;;(setq
328 ;; muse-cite-titles
329 ;; '(("Bahá'u'lláh"
330 ;; ("Kitáb-i-Íqán"
331 ;; "http://bahai-library.com/?file=bahaullah_kitab_iqan.html"
332 ;; "http://bahai-library.com/?file=bahaullah_kitab_iqan.html#%d"))
333 ;; ("`Abdu'l-Bahá"
334 ;; ("Promulgation of Universal Peace"
335 ;; "http://bahai-library.com/?file=abdulbaha_promulgation_universal_peace.html"
336 ;; "http://www.bahai-library.com/writings/abdulbaha/pup/pup.html#%d"))))
338 (provide 'muse-init)