emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] Re: How to add macros or shortcuts in emacs-wiki?


From: Michael Olson
Subject: [emacs-wiki-discuss] Re: How to add macros or shortcuts in emacs-wiki?
Date: Wed, 10 Aug 2005 14:13:37 -0500
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Mark Triggs <address@hidden> writes:

> Sounds useful.  I was inspired to try a rough sketch of this.  It's
> a bit hacky but just to give an idea:
>
> (defvar macro-names
>   '(("coffee" . (lambda () "<p>Went for a <b>coffee</b> break</p>"))
>     ("meeting" . (lambda (&rest people)
>                    (format "Had a meeting with: <ul>%s</ul>"
>                            (mapconcat (lambda (person) (concat "<li>" person))
>                                       people "\n"))))))
>
> (defun markup-macro ()
>   "Call the markup function for a macro with any applicable arguments."
>   (save-match-data
>     (let ((macro (match-string 1)))
>       (let* ((pos (position (string-to-char " ") macro))
>              (name (subseq macro 0 pos))
>              (args (if pos
>                        (read-strings (subseq macro (1+ pos)))
>                      '())))
>         (let ((fn (cdr (assoc name macro-names))))
>           (if fn
>               (apply fn args)
>             ""))))))
>
> (defun read-strings (string)
>   "Return a list of the substrings in STRING."
>   (let ((start 0)
>         (strings '()))
>     (while (< start (length string))
>       (let ((next-string (read-from-string string start)))
>         (push (car next-string) strings)
>         (setq start (cdr next-string))))
>     (nreverse strings)))
>
> ;; To enable them
> (push ["@{\\(.*\\)}@" 0 markup-macro] emacs-wiki-publishing-markup)
>
> Then, for example, stuff in your wiki pages like:
>
>   @{coffee}@
>
>   @{meeting "Totoro" "Catbus"}@
>
> should be expanded.

This looks useful.  Do you mind if I add it to emacs-wiki-macro.el?

-- 
Michael Olson -- FSF Associate Member #652 -- http://www.mwolson.org/
Interests: anime, Debian, XHTML, wiki, Emacs Lisp
  /` |\ | | | IRC: mwolson on freenode.net: #hcoop, #muse, #pulug
 |_] | \| |_| Jabber: mwolson_at_hcoop.net

Attachment: pgpm5zK0awREK.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]