2008-08-18 define-derived-mode

Maybe I should post little snippets from my `.emacs` every now and then. Here’s a simple use of DerivedMode and a basic introduction to FontLock.

(define-derived-mode campaign-wiki-mode fundamental-mode
  "Campaign"
  "Campaign Wiki stuff including Creole Markup and BBCode."
  (setq font-lock-defaults '(campaign-wiki-font-lock-keywords)))

(defvar campaign-wiki-font-lock-keywords
  '(("\\[b\\].*?\\[/b\\]" . 'bold)
    ("\\[i\\].*?\\[/i\\]" . 'italic)
    ("\\*\\*.*?\\*\\*" . 'bold)
    ("\\*.*?\\*" . 'bold)
    ("\\_</.*?/" . 'italic)
    ("|+=?" . font-lock-string-face)
    ("\\\\\\\\[ \t]+" . font-lock-warning-face))
  "Keywords for Campaign Wiki mode.")

This gives me very basic font-locking for Campaign Wiki texts which use a mix of WikiCreole and BBCode. It implements the following:

Campaign Wiki

BBCode

[b]bold[/b]
[i]italic[/i]

/italic/
this/that/there is not italic
| foo
| bar
\\ followed by whitespace gets a warning

It’s not much, but it got me started.

​#Emacs

Comments

(Please contact me if you want to remove your comment.)

Your .emacs always looked useful, it was always to confusing to tell what it did. Great idea to write small articles about it. Look forward to more.

– AaronHawley 2008-08-20 19:32 UTC

AaronHawley

---

Cool. Let’s see how long I can keep it up! 😄

– Alex Schroeder 2008-08-21 08:31 UTC

Alex Schroeder