BbCode

BBCode is a lightweight markup language used in web forums (typically PHP-based ones) for things like bolding text, title, links, etc. There is no official standard for BBCode, but it is generally agreed that [b][/b] boldens text, [i][/i] italicizes it, etc.

BBCode modes

Here are three major modes for editing BBCode:

Other tips

If you don’t want to use a major mode, you can use the following code together with SkeletonMode. Bind to appropriate keys (below) and use together with VisualLineMode.

    (setq skeleton-end-newline nil)
    (define-skeleton bb-italic
      "Make italic text."
      nil "[i]" _ "[/i]")
    (define-skeleton bb-bold
      "Make bold text."
      nil "[b]" _ "[/b]")
    (define-skeleton bb-underline
      "Make underlined text."
      nil "[u]" _ "[/u]")
    (define-skeleton bb-tt
      "Typewriter font."
      nil "[font=\"Courier New\"]" _ "[/font]")
    (define-skeleton bb-url
      "Prompt for URL and insert link."
      "URL: " "[url=\"" str "\"]" _ "[/url]")
    (define-skeleton bb-list
      "Start an unordered list."
      nil "[list][*] " _ "\n[/list]")
    (define-skeleton bb-point
      "Make a new list point."
      nil (unless (bolp) "\n") "[*] ")
    (define-skeleton bb-img
      "Insert [img] ... [/img] tags."
      nil "[img]" _ "[/img]")
    (define-skeleton bb-indent
      "Insert [indent] ... [/indent] tags."
      nil "[indent]" _ "[/indent]")
    (define-skeleton bb-youtube
      "Insert [youtube] ... [/youtube] tags."
      nil "[youtube]" _ "[/youtube]")

As for key bindings, the following roughly matches AUCTeX’s scheme:

    (global-set-key "\C-c\C-f\C-e" 'bb-italic)
    (global-set-key "\C-c\C-f\C-u" 'bb-underline)
    (global-set-key "\C-c\C-f\C-b" 'bb-bold)
    (global-set-key "\C-c\C-f\C-t" 'bb-tt)
    (global-set-key "\C-c\C-fu"    'bb-url)
    (global-set-key "\C-c\C-f\C-l" 'bb-list)
    (global-set-key "\C-cj"        'bb-point)
    (global-set-key "\C-c\C-j"     'bb-point)
    (global-set-key "\C-c\C-fi"    'bb-img)
    (global-set-key "\C-c\C-f\C-i" 'bb-indent)
    (global-set-key "\C-c\C-f\C-y" 'bb-youtube)
    (global-set-key "\C-c\C-fy"    'bb-youtube)

You might want to piece together a minor mode if AUCTeX’s keys are foreign to you. Suggestions are welcome.

See also


CategoryMarkup?