Play nicely with fill, adaptive-fill, and flyspell.
[muse-el.git] / lisp / muse-wiki.el
blobd10870a0feac77778b62814bc709d7b509b1e059
1 ;;; muse-wiki.el --- wiki features for muse
3 ;; Copyright (C) 2005 Free Software Foundation, Inc.
5 ;; Author: Yann Hodique <Yann.Hodique@lifl.fr>
6 ;; Keywords:
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
23 ;;; Commentary:
25 ;;; Code:
27 (require 'muse-regexps)
28 (require 'muse-mode)
30 (defgroup muse-wiki nil
31 "Options controlling the behavior of Emacs Muse Wiki features."
32 :group 'muse-mode)
34 (defcustom muse-wiki-wikiword-regexp
35 (concat "\\<\\(\\(?:[" muse-regexp-upper
36 "][" muse-regexp-lower "]+\\)\\(?:["
37 muse-regexp-upper "][" muse-regexp-lower "]+\\)+\\)\\>")
38 "Regexp used to match WikiWords"
39 :type 'regexp
40 :group 'muse-wiki)
42 (defcustom muse-wiki-interwiki-alist
43 '(("emacswiki" . "http://www.emacswiki.org/cgi-bin/wiki/"))
44 "A table of WikiNames that refer to external entities.
45 The format of this table is an alist, or series of cons cells.
46 Each cons cell must be of the form:
48 (WIKINAME . STRING-OR-FUNCTION)
50 The second part of the cons cell may either be a STRING, which in most
51 cases should be a URL, or a FUNCTION. If a function, it will be
52 called with one argument: the tag applied to the Interwiki name, or
53 nil if no tag was used. If the cdr was a STRING and a tag is used,
54 the tag is simply appended.
56 Here are some examples:
58 (\"JohnWiki\" . \"http://alice.dynodns.net/wiki?\")
60 Referring to [[JohnWiki::EmacsModules]] then really means:
62 http://alice.dynodns.net/wiki?EmacsModules
64 If a function is used for the replacement text, you can get creative
65 depending on what the tag is. Tags may contain any alphabetic
66 character, any number, % or _. If you need other special characters,
67 use % to specify the hex code, as in %2E. All browsers should support
68 this."
69 :type '(repeat (cons (string :tag "WikiName")
70 (or (string :tag "URL") function)))
71 :group 'muse-wiki)
73 (defvar muse-wiki-interwiki-regexp
74 (concat "\\(" (mapconcat 'car muse-wiki-interwiki-alist "\\|") "\\)"))
76 (defun muse-wiki-wikiword-at-point ()
77 (and (looking-at muse-wiki-wikiword-regexp)
78 (match-string 1)))
80 (defun muse-wiki-interwiki-expand (url)
81 (setq url (or (muse-wiki-interwiki-handle url)
82 url))
83 (muse-publish-read-only url))
85 (defun muse-wiki-interwiki-handle (url)
86 (save-match-data
87 (when (string-match (concat muse-wiki-interwiki-regexp "::\\(.*\\)") url)
88 (let ((subst (cdr (assoc (match-string 1 url)
89 muse-wiki-interwiki-alist)))
90 (word (match-string 2 url)))
91 (if (functionp subst)
92 (funcall subst word)
93 (concat subst word))))))
95 (eval-after-load 'muse-colors
96 '(progn
97 (defun muse-wiki-colors-wikiword ()
98 ;; remove flyspell overlays
99 (when (fboundp 'flyspell-unhighlight-at)
100 (let ((cur (match-beginning 0)))
101 (while (> (match-end 0) cur)
102 (flyspell-unhighlight-at cur)
103 (setq cur (1+ cur)))))
104 (let* ((link (match-string-no-properties 1))
105 (props (muse-link-properties
106 (match-string-no-properties 1)
107 (muse-link-face (match-string 1)))))
108 (add-text-properties (match-beginning 1) (match-end 0) props)))
110 (add-to-list 'muse-colors-markup
111 '(muse-wiki-wikiword-regexp t muse-wiki-colors-wikiword)
114 (muse-configure-highlighting 'muse-colors-markup muse-colors-markup)))
116 (eval-after-load 'muse-publish
117 '(progn
118 (add-to-list 'muse-publish-markup-regexps
119 '(3100 muse-wiki-wikiword-regexp 0 url)
121 (add-to-list 'muse-publish-url-transforms
122 'muse-wiki-interwiki-expand)))
124 (eval-after-load 'muse-mode
125 '(progn
126 (add-to-list 'muse-mode-link-functions 'muse-wiki-wikiword-at-point t)
127 (add-to-list 'muse-mode-handler-functions 'muse-wiki-interwiki-handle)))
129 (provide 'muse-wiki)
130 ;;; muse-wiki.el ends here