[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [emacs-wiki-discuss] How to add macros or shortcuts in emacs-wiki?
From: |
Mark Triggs |
Subject: |
Re: [emacs-wiki-discuss] How to add macros or shortcuts in emacs-wiki? |
Date: |
Wed, 10 Aug 2005 15:49:20 +1000 |
User-agent: |
No Gnus v0.4 |
Adrian Tritschler <address@hidden> writes:
> I'm in the middle of migrating a website that used to be managed by
> Blogmax to planner/emacs-wiki and have a few queries.
>
> In my old markup, I could add "shortcuts" so that something like
> "address@hidden" or "{shortcut "par1" "par2"}" in the source text could
> be expanded to arbitrary HTML in the output, some with parameters,
> some without.
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.
Cheers,
Mark
--
Mark Triggs
<address@hidden>