;;; Muse (require 'muse-mode) (require 'muse-project) (require 'muse-publish) (require 'muse-html) (require 'muse-wiki) (require 'muse-latex) (require 'muse-book) (muse-derive-style "cke-xhtml" "xhtml" :header 'muse-cke-xhtml-header :footer 'muse-cke-xhtml-footer) ;;; Project Configuration (setq muse-project-alist '(("unknownlamer.org" ("~/html/muse/src/unknownlamer.org" :default "index") (:base "cke-xhtml" :path "~/html/muse/site/unknownlamer.org-test")) ("unknownlamer.org-clean" ("~/html/muse/site/unknownlamer.org-repo" :default "index") (:base "cke-xhtml" :path "~/html/muse/site/unknownlamer.org")) ("clintons-plans" ("~/plans" :major-mode planner-mode :visit-link planner-visit-link :default "TaskPool") (:base "planner-html" :path "~/html/plan-pages")))) (setq muse-html-charset-default "utf-8") ; utf-8 is the only true way ; for the enlightened hacker (setq muse-cke-xhtml-header "~/html/muse/templates/header.html") (setq muse-cke-xhtml-footer "~/html/muse/templates/footer.html") ;;; Footer helper functions (require 'randomsig) (require 'psgml-html) (defun cke-muse-randomsig-signature () "Return randomsig from normal and web only collection" (with-temp-buffer (insert (randomsig-signature (cons "web-only" randomsig-files))) (html-quote-region (point-min) (point-max)) (buffer-substring-no-properties (point-min) (point-max)))) ;;; Hyperspec integration (require 'hyperspec) (defvar cke-clhs-root common-lisp-hyperspec-root "Root of clhs for interwiki links") (defun cke-clhs-get-urls (entry) "Hack to get a list of urls from `common-lisp-hyperspec'" (let ((cke-clhs-urls (list))) (flet ((browse-url (url) (add-to-list 'cke-clhs-urls url))) (common-lisp-hyperspec entry) cke-clhs-urls))) (defun cke-clhs-interwiki (entry) "Returns url to be used for muse interwiki link lookup up Hyperspec entries" (let ((common-lisp-hyperspec-root cke-clhs-root)) (let ((clhs-urls (cke-clhs-get-urls entry))) ;; todo: if more than one url be returned ;; fixme: use all urls (car clhs-urls)))) (add-to-list 'muse-wiki-interwiki-alist (cons "clhs" #'cke-clhs-interwiki)) (setq cke-clhs-root "http://www.lispworks.com/reference/HyperSpec/") ;;; Easy links to my darcsweb (defvar cke-darcsweb-root "http://unknownlamer.org/darcsweb/browse") (defun cke-darcsweb-interwiki (project/file) (destructuring-bind (project &rest files) (split-string project/file '"/" nil) (cond ((null files) (format "%s?r=%s;a=summary" cke-darcsweb-root (url-insert-entities-in-string project))) (files (format "%s?r=%s;a=%s;f=%s" cke-darcsweb-root (url-insert-entities-in-string project) (if (string= (car (last files)) "") "tree" "headblob") (url-insert-entities-in-string (apply #'concat (mapcan (lambda (e) (list "/" e)) files)))))))) (add-to-list 'muse-wiki-interwiki-alist (cons "darcsweb" #'cke-darcsweb-interwiki)) ;;; Latex2png ;;; This is a suboptimal solution for displaying math, but will have ;;; to do until I figure out how to embed mathml with an img and raw ;;; latex source backup... (require 'muse-latex2png) (setq muse-latex2png-img-dest "img/latex" muse-latex2png-scale-factor 1.5) ;;; this differs from Muse 3.12 in that it calls dvipng ;;; with call-process so as to avoid issues with filenames with spaces ;;; in them (patch has been sent upstream and merged for 3.13) (defun muse-latex2png (code prefix preamble) "Convert the LaTeX CODE into a png file beginning with PREFIX. PREAMBLE indicates extra packages and definitions to include." (unless preamble (setq preamble "")) (unless prefix (setq prefix "muse-latex2png")) (let* ((tmpdir (cond ((boundp 'temporary-file-directory) temporary-file-directory) ((fboundp 'temp-directory) (temp-directory)) (t "/tmp"))) (texfile (expand-file-name (concat prefix "__" (format "%d" (abs (sxhash code)))) tmpdir)) (defalt-directory default-directory)) (with-temp-file (concat texfile ".tex") (insert muse-latex2png-template) (goto-char (point-min)) (while (search-forward "%preamble%" nil t) (replace-match preamble nil t)) (goto-char (point-min)) (while (search-forward "%code%" nil t) (replace-match code nil t))) (setq default-directory tmpdir) (call-process "latex" nil nil nil texfile) (if (file-exists-p (concat texfile ".dvi")) (progn (call-process "dvipng" nil nil nil "-E" "-fg" muse-latex2png-fg "-bg" muse-latex2png-bg "-T" "tight" "-x" (format "%s" (* muse-latex2png-scale-factor 1000)) "-y" (format "%s" (* muse-latex2png-scale-factor 1000)) "-o" (concat texfile ".png") (concat texfile ".dvi")) (if (file-exists-p (concat texfile ".png")) (progn (delete-file (concat texfile ".dvi")) (delete-file (concat texfile ".tex")) (delete-file (concat texfile ".aux")) (delete-file (concat texfile ".log")) (concat texfile ".png")) (message "Failed to create png file") nil)) (message (concat "Failed to create dvi file " texfile)) nil))) ;;; This differs from Muse 3.12 in that it inserts

in html ;;; derived styles for non-inline blocks ;;; fixme: send patch (defun muse-latex2png-region (beg end attrs) "Generate an image for the Latex code between BEG and END. If a Muse page is currently being published, replace the given region with the appropriate markup that displays the image. Otherwise, just return the path of the generated image. Valid keys for the ATTRS alist are as follows. prefix: The prefix given to the image file. preamble: Extra text to add to the Latex preamble. inline: Display image as inline, instead of a block." (let ((end-marker (set-marker (make-marker) (1+ end))) (pubdir (expand-file-name muse-latex2png-img-dest (file-name-directory muse-publishing-current-output-path)))) (save-restriction (narrow-to-region beg end) (let* ((text (buffer-substring-no-properties beg end)) ;; the prefix given to the image file. (prefix (cdr (assoc "prefix" attrs))) ;; preamble (for extra options) (preamble (cdr (assoc "preamble" attrs))) ;; display inline or as a block (display (car (assoc "inline" attrs)))) (when muse-publishing-p (delete-region beg end) (goto-char (point-min))) (unless (file-directory-p pubdir) (make-directory pubdir)) (let ((path (muse-latex2png-move2pubdir (muse-latex2png text prefix preamble) prefix pubdir))) (when path (when muse-publishing-p (muse-insert-markup (if (muse-style-derived-p "html") (concat (if (not display) "

" "") "\"latex2png" ">") (muse-insert-markup "") (if (not display) "

" "")) (let ((ext (or (file-name-extension path) "")) (path (muse-path-sans-extension path))) (muse-markup-text 'image path ext)))) (goto-char (point-max))) path)))))) ;;; Local Keybindings (define-key muse-mode-map [?\C-j] #'muse-insert-list-item) (define-key muse-mode-map [?\C-c ?\C-c] #'comment-region) ;;; xhtml backend customizations (setq muse-xhtml-style-sheet "") ;;; Console Keybindings (when (null window-system) (define-key muse-mode-map [?\C-c ?>] #'muse-increase-list-item-indentation) (define-key muse-mode-map [?\C-c ?<] #'muse-decrease-list-item-indentation)) (setq htmlize-css-name-prefix "emacs-face-") (defun htmlize-region-for-paste (beg end) "Htmlize the region and return just the HTML as a string. This forces the `inline-css' style and only returns the HTML body, but without the BODY tag. This should make it useful for inserting the text to another HTML buffer." (let* ((htmlize-output-type 'css) (htmlbuf (htmlize-region beg end))) (unwind-protect (with-current-buffer htmlbuf (buffer-substring (plist-get htmlize-buffer-places 'content-start) (plist-get htmlize-buffer-places 'content-end))) (kill-buffer htmlbuf))))