Feeds:
Posts
Comments

Posts Tagged ‘muse customization’

Customizing Emacs Muse – Part 3

This is part 3 in the customizing emacs muse series.

In part 1 (Creating Squidoo Lenses With Emacs Muse) we talked about adding hooks to transform the generated HTML to cope with the impoverished tag set that Squidoo provides.

In part 2 (Updating Elements Within Association Lists) we talked about adding a function that can replace values in association lists to manipulate muse-html-markup-strings.

In this post, we will talk about how to select between different output styles if you’re writing for, say, a wordpress.com blog, an article directory and squidoo.

Note: muse already allows for different styles, but I’m not aware of a sub-style mechanism which is what I am really describing here.


Let’s get started. First of all, it is handy to have a mechanism for getting back to the default state. I provide a variable to store a function that will undo the changes that made the current sub-style. Returning to the default is just a matter of calling this function if it is defined.

(defvar muse-style-remove-fn nil)

(defun muse-style-default ()
  (when muse-style-remove-fn (funcall muse-style-remove-fn))
  (setq muse-style-remove-fn nil))

muse-style-select enables me to choose between the various styles using ido. You may recognise this selection mechanism from my directory aliases post.

(defconst muse-style-mapping
  (list (cons "squidoo" 'muse-style-squidoo-enable)
        (cons "curious" 'muse-style-curious-enable)
        (cons "default" 'muse-style-default)))

(defconst muse-style-aliases
  (mapcar (lambda (e) (car e)) muse-style-mapping))

(defun muse-style-select (&optional style)
  (interactive)
  (unless style
    (setq style
          (ido-completing-read "Muse Style: "
                               muse-style-aliases
                               nil t)))
  (if (and (stringp style) (> (length style) 0 ))
      (let ((pair (assoc style muse-style-mapping)))
        (if pair
            (funcall (cdr pair))
          (error "Invalid style %s" style)))
    (error "Invalid style %s" style)))

I have a helper function to replace the keys within muse-html-markup-strings.

(defun muse-strings-replace (mapping)
  (setq muse-html-markup-strings
        (assoc-replace muse-html-markup-strings mapping)))

The disable function resets begin-literal and end-literal to the original state. Possibly I should have copied the entire original associative list instead. It also removes the hooks which have been added.

(defun muse-style-squidoo-disable ()
  (interactive)
  (muse-strings-replace (list (kv 'begin-literal "<code>")
                              (kv 'end-literal "</code>")))
  (remove-hook 'muse-html-after-htmlize-hook 'squidoo-htmlize)
  (remove-hook 'muse-after-publish-hook 'squidoo-fix-para))

The enable function returns us to the default style first, just in case there is already a sub-style selected. It then overwrites begin-literal and end-literal and adds the hooks.

(defun muse-style-squidoo-enable ()
  (interactive)
  (muse-style-default)

  (when muse-style-remove-fn (funcall muse-style-remove-fn))
  (setq muse-style-remove-fn 'muse-style-squidoo-disable)

  (muse-strings-replace (list (kv 'begin-literal sq-code-prefix)
                              (kv 'end-literal "</b>")))
  (add-hook 'muse-html-after-htmlize-hook 'squidoo-htmlize)
  (add-hook 'muse-after-publish-hook 'squidoo-fix-para))

Read Full Post »

Follow

Get every new post delivered to your Inbox.