Make interwiki links work in a few more edge cases.
[muse-el.git] / lisp / muse-regexps.el
blobba7f22a69ebb5a6d7bb042bb12b47626bd75de3f
1 ;;; muse-regexps.el --- Define regexps used by Muse.
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
10 ;; version.
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ;; for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
22 ;;; Commentary:
24 ;; This file is the part of the Muse project that describes regexps
25 ;; that are used throughout the project.
27 ;;; Contributors:
29 ;;; Code:
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; Muse Regular Expressions
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 (defgroup muse-regexp nil
38 "Regular expressions used in publishing and syntax highlighting."
39 :group 'muse)
41 (defcustom muse-regexp-use-character-classes 'undecided
42 "Indicate whether to use extended character classes like [:space:].
43 If 'undecided, Muse will use them if your emacs is known to support them.
45 Emacs 22 and Emacs 21.3.50 are known to support them, XEmacs does
46 not support them
48 Emacs 21.2 or higher might support them, but the maintainer is
49 uncertain, so by default extended regexps are not used with these
50 versions of Emacs."
51 :type '(choice (const :tag "Yes" t)
52 (const :tag "No" nil)
53 (const :tag "Let Muse decide" undecided))
54 :group 'muse-regexp)
56 (defun muse-extreg-usable-p ()
57 "Return non-nil if extended character classes can be used,
58 nil otherwise.
60 This is used when deciding the initial values of the muse-regexp
61 options."
62 (cond
63 ((eq muse-regexp-use-character-classes t)
65 ((eq muse-regexp-use-character-classes nil)
66 nil)
68 (save-match-data
69 (string-match "^[0-9]+\\.[0-9]+\\.\\([0-9]+\\)"
70 emacs-version)
71 (cond ((featurep 'xemacs) nil) ; unusable on XEmacs
72 ((> emacs-major-version 21) t) ; usable if > 21
73 ((< emacs-major-version 21) nil)
74 ((< emacs-minor-version 3) nil)
75 ;; don't use if version is of format 21.x
76 ((null (match-string 1 emacs-version)) nil)
77 ;; don't trust the 21.3.1 release or its predecessors
78 ((> (string-to-number (match-string 1 emacs-version)) 1) t)
79 (t nil))))))
81 (defcustom muse-regexp-blank
82 (if (muse-extreg-usable-p)
83 "[:blank:]"
84 " \t")
85 "Regexp to use in place of \"[:blank:]\".
86 This should be something that matches spaces and tabs.
88 It is like a regexp, but should be embeddable inside brackets.
89 Muse will detect the appropriate value correctly most of
90 the time."
91 :type 'string
92 :options '("[:blank:]" " \t")
93 :group 'muse-regexp)
95 (defcustom muse-regexp-space
96 (if (muse-extreg-usable-p)
97 "[:space:]"
98 " \t\n")
99 "Regexp to use in place of \"[:space:]\".
100 This should be something that matches spaces, tabs, and newlines.
102 It is like a regexp, but should be embeddable inside brackets.
103 muse will detect the appropriate value correctly most of
104 the time."
105 :type 'string
106 :options '("[:space:]" " \t\n")
107 :group 'muse-regexp)
109 (defcustom muse-regexp-alnum
110 (if (muse-extreg-usable-p)
111 "[:alnum:]"
112 "A-Za-z0-9")
113 "Regexp to use in place of \"[:alnum:]\".
114 This should be something that matches all letters and numbers.
116 It is like a regexp, but should be embeddable inside brackets.
117 muse will detect the appropriate value correctly most of
118 the time."
119 :type 'string
120 :options '("[:alnum:]" "A-Za-z0-9")
121 :group 'muse-regexp)
123 (defcustom muse-regexp-lower
124 (if (muse-extreg-usable-p)
125 "[:lower:]"
126 "a-z")
127 "Regexp to use in place of \"[:lower:]\".
128 This should match all lowercase characters.
130 It is like a regexp, but should be embeddable inside brackets.
131 muse will detect the appropriate value correctly most of
132 the time."
133 :type 'string
134 :options '("[:lower:]" "a-z")
135 :group 'muse-regexp)
137 (defcustom muse-regexp-upper
138 (if (muse-extreg-usable-p)
139 "[:upper:]"
140 "A-Z")
141 "Regexp to use in place of \"[:upper:]\".
142 This should match all uppercase characters.
144 It is like a regexp, but should be embeddable inside brackets.
145 muse will detect the appropriate value correctly most of
146 the time."
147 :type 'string
148 :options '("[:upper:]" "A-Z")
149 :group 'muse-regexp)
151 (defcustom muse-tag-regexp
152 (concat "<\\([^/" muse-regexp-space "][^" muse-regexp-space
153 "</>]*\\)\\(\\s-+[^<>]+[^</>]\\)?\\(/\\)?>")
154 "A regexp used to find XML-style tags within a buffer when publishing.
155 Group 1 should be the tag name, group 2 the properties, and group
156 3 the optional immediate ending slash."
157 :type 'regexp
158 :group 'muse-regexp)
160 (defcustom muse-explicit-link-regexp
161 "\\[\\[\\([^][\t\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
162 "Regexp used to match [[target][description]] links.
163 Paren group 1 must match the URL, and paren group 2 the description."
164 :type 'regexp
165 :group 'muse-regexp)
167 (defcustom muse-implicit-link-regexp
168 (concat "\\([^" muse-regexp-space "]+\\)")
169 "Regexp used to match an implicit link.
170 An implicit link is the largest block of text to be checked for
171 URLs and bare WikiNames by the `muse-link-at-point' function.
172 Paren group 1 is the text to be checked.
174 URLs are checked by default. To get WikiNames, load
175 muse-wiki.el.
177 If you want to match things with spaces in them, you will have to
178 modify this."
179 :type 'regexp
180 :group 'muse-regexp)
182 (defcustom muse-url-regexp
183 (concat "\\<\\(?:https?:/?/?\\|ftp:/?/?\\|gopher://\\|"
184 "telnet://\\|wais://\\|file:/\\|s?news:\\|"
185 "mailto:\\)"
186 "[^]" muse-regexp-space "\"'()<>[^`{}]*[^]"
187 muse-regexp-space "\"'()<>[^`{}.,;]+")
188 "A regexp used to match URLs within a Muse page."
189 :type 'regexp
190 :group 'muse-regexp)
192 (defcustom muse-file-regexp
193 "[/?]\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)\\)?\\'"
194 "A link matching this regexp will be regarded as a link to a file."
195 :type 'regexp
196 :group 'muse-regexp)
198 (defcustom muse-image-regexp
199 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
200 "A link matching this regexp will be published inline as an image.
201 For example:
203 [[./wife.jpg][A picture of my wife]]
205 If you omit the description, the alt tag of the resulting HTML
206 buffer will be the name of the file."
207 :type 'regexp
208 :group 'muse-regexp)
210 (provide 'muse-regexps)
212 ;;; muse-regexps.el ends here