Emacs, muse and htmlize

It looks like I missed an interesting discussion on humane markup langages last week. Obviously I use emacs to write my blog posts with muse and htmlize. A tiny bit of Juan wrap makes it a pleasure. I wouldn’t write at all if I had to use raw HTML (although maybe it wouldn’t be so bad if I used nxml-mode).

I like the comments about normalizing HTML. Show me the code. Until there is something available I’ll stick to my regex based humane markup translator thank you very much. Of course I know that comments require a different level of trust than your own publishing system (unless for some reason it is not the case that you trust yourself but you don’t trust ‘them‘). However, you should still minimise the effort required or far fewer people will leave comments.

JG

Note: in the code below we could redefine muse-html-header and muse-html-footer to get the exact output that we want but in fact it is handy to have the html available so you can load it into a browser.

Update: I found that this guy said something similar to what I wanted to say, but he said it much more elegantly.

;; ———————————————————————- ;;

(requiremuse-mode)
(requiremuse-publish)
(requiremuse-html)

;; ———————————————————————- ;;

(defconst *muse-start* “Page published by Emacs Muse begins here”)
(defconst *muse-end* “Page published by Emacs Muse ends here”)

(defun my-muse-publish ()
  “Publish the current page as html and copy the html into the clipboard”
  (interactive)
  (let* ((cb (current-buffer))
         (filename (buffer-file-name))
         (extpos (string-match “.muse$” filename))
         (html-file (concat (substring filename 0 extpos) “.html”)))
    (muse-publish-file filename “html”)
    (let ((b (get-file-buffer html-file))
          (kill-buffer-query-functions nil))
      (when b (kill-buffer b)))
    (find-file html-file)

    (goto-char (point-min))
    (re-search-forward *muse-start*)
    (move-beginning-of-line 2)
    (let ((begin (point)))
      (re-search-forward *muse-end*)
      (move-beginning-of-line -1)
      (copy-region-as-kill begin (point)))

    (switch-to-buffer cb)
    (message “file published”)))

(define-key muse-mode-map [f7] ‘my-muse-publish)

;; ———————————————————————- ;;

(defun muse-minor-modes ()
  (longlines-mode 1)
  (font-lock-mode nil))

(add-hook ‘muse-mode-hook ‘muse-minor-modes)

;; ———————————————————————- ;;

(providemuse-config)

;; ———————————————————————- ;;

One Response to “Emacs, muse and htmlize”

  1. Jeremy Bowers Says:

    “Show me the code” - Python or Perl? The Perl one is a bit more sophisticated, because it picked up a couple of small features when I ported it from the Python one, but… it’s perl.

    Either way, the code in question isn’t quite “done” simply because it hasn’t had people beating on it, but it’s decent.

    (If you really are interested, please respond to my email, but be aware it may take me a day or three; I don’t check it often anymore.)

Leave a Reply