No, we really did need the auto-mode-alist part at top-level
[muse-el.git] / lisp / muse-regexps.el
blob5404d4a3bbf919e20c4bbe0a2b4cde77baa43158
1 ;;; muse-regexps.el --- define regexps used by Muse
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
7 ;; Emacs Muse is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
12 ;; Emacs Muse is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Emacs Muse; 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 ;;; Deal with the lack of character classes for regexps in Emacs21 and
42 ;;; XEmacs
44 (defcustom muse-regexp-use-character-classes 'undecided
45 "Indicate whether to use extended character classes like [:space:].
46 If 'undecided, Muse will use them if your emacs is known to support them.
48 Emacs 22 and Emacs 21.3.50 are known to support them. XEmacs
49 does not support them.
51 Emacs 21.2 or higher support them, but with enough annoying edge
52 cases that the sanest default is to leave them disabled."
53 :type '(choice (const :tag "Yes" t)
54 (const :tag "No" nil)
55 (const :tag "Let Muse decide" undecided))
56 :group 'muse-regexp)
58 (defvar muse-regexp-emacs-revision
59 (save-match-data
60 (and (string-match "^[0-9]+\\.[0-9]+\\.\\([0-9]+\\)"
61 emacs-version)
62 (match-string 1 emacs-version)
63 (string-to-number (match-string 1 emacs-version))))
64 "The revision number of this version of Emacs.")
66 (defun muse-extreg-usable-p ()
67 "Return non-nil if extended character classes can be used,
68 nil otherwise.
70 This is used when deciding the initial values of the muse-regexp
71 options."
72 (cond
73 ((eq muse-regexp-use-character-classes t)
75 ((eq muse-regexp-use-character-classes nil)
76 nil)
77 ((featurep 'xemacs) nil) ; unusable on XEmacs
78 ((> emacs-major-version 21) t) ; usable if > 21
79 ((< emacs-major-version 21) nil)
80 ((< emacs-minor-version 3) nil)
81 ;; don't use if version is of format 21.x
82 ((null muse-regexp-emacs-revision) nil)
83 ;; only trust 21.3.50 or higher
84 ((>= muse-regexp-emacs-revision 50) t)
85 (t nil)))
87 (defcustom muse-regexp-blank
88 (if (muse-extreg-usable-p)
89 "[:blank:]"
90 " \t")
91 "Regexp to use in place of \"[:blank:]\".
92 This should be something that matches spaces and tabs.
94 It is like a regexp, but should be embeddable inside brackets.
95 Muse will detect the appropriate value correctly most of
96 the time."
97 :type 'string
98 :options '("[:blank:]" " \t")
99 :group 'muse-regexp)
101 (defcustom muse-regexp-alnum
102 (if (muse-extreg-usable-p)
103 "[:alnum:]"
104 "A-Za-z0-9")
105 "Regexp to use in place of \"[:alnum:]\".
106 This should be something that matches all letters and numbers.
108 It is like a regexp, but should be embeddable inside brackets.
109 muse will detect the appropriate value correctly most of
110 the time."
111 :type 'string
112 :options '("[:alnum:]" "A-Za-z0-9")
113 :group 'muse-regexp)
115 (defcustom muse-regexp-lower
116 (if (muse-extreg-usable-p)
117 "[:lower:]"
118 "a-z")
119 "Regexp to use in place of \"[:lower:]\".
120 This should match all lowercase characters.
122 It is like a regexp, but should be embeddable inside brackets.
123 muse will detect the appropriate value correctly most of
124 the time."
125 :type 'string
126 :options '("[:lower:]" "a-z")
127 :group 'muse-regexp)
129 (defcustom muse-regexp-upper
130 (if (muse-extreg-usable-p)
131 "[:upper:]"
132 "A-Z")
133 "Regexp to use in place of \"[:upper:]\".
134 This should match all uppercase characters.
136 It is like a regexp, but should be embeddable inside brackets.
137 muse will detect the appropriate value correctly most of
138 the time."
139 :type 'string
140 :options '("[:upper:]" "A-Z")
141 :group 'muse-regexp)
143 ;;; Regexps used to define Muse publishing syntax
145 (defcustom muse-list-item-regexp
146 (concat "^%s\\([" muse-regexp-blank "]-[" muse-regexp-blank
147 "]*\\|[" muse-regexp-blank "][0-9]+\\.["
148 muse-regexp-blank "]*\\|\\([^\n" muse-regexp-blank "].*?\\)?"
149 "::\\(?:[" muse-regexp-blank "]+\\|$\\)\\)")
150 "Regexp used to match the beginning of a list item.
151 The '%s' will be replaced with a whitespace regexp when publishing."
152 :type 'regexp
153 :group 'muse-regexp)
155 (defcustom muse-dl-term-regexp
156 (concat "[" muse-regexp-blank "]*\\(.+?\\)["
157 muse-regexp-blank "]+::\\(?:[" muse-regexp-blank "]+\\|$\\)")
158 "Regexp used to match a definition list term.
159 The first match string must contain the term."
160 :type 'regexp
161 :group 'muse-regexp)
163 (defcustom muse-table-field-regexp
164 (concat "[" muse-regexp-blank "]+\\(|+\\)\\(?:["
165 muse-regexp-blank "]\\|$\\)")
166 "Regexp used to match table separators when publishing."
167 :type 'regexp
168 :group 'muse-regexp)
170 (defcustom muse-table-line-regexp (concat ".*" muse-table-field-regexp ".*")
171 "Regexp used to match a table line when publishing."
172 :type 'regexp
173 :group 'muse-regexp)
175 (defcustom muse-table-hline-regexp (concat "[" muse-regexp-blank
176 "]*|[-+]+|[" muse-regexp-blank
177 "]*")
178 "Regexp used to match a horizontal separator line in a table."
179 :type 'regexp
180 :group 'muse-regexp)
182 (defcustom muse-table-el-border-regexp (concat "[" muse-regexp-blank "]*"
183 "\\+\\(-*\\+\\)+"
184 "[" muse-regexp-blank "]*")
185 "Regexp used to match the beginning and end of a table.el-style table."
186 :type 'regexp
187 :group 'muse-regexp)
189 (defcustom muse-tag-regexp
190 (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank
191 "</>\n]*\\)\\(\\s-+[^<>\n]+[^</>\n]\\)?\\(/\\)?>")
192 "A regexp used to find XML-style tags within a buffer when publishing.
193 Group 1 should be the tag name, group 2 the properties, and group
194 3 the optional immediate ending slash."
195 :type 'regexp
196 :group 'muse-regexp)
198 (defcustom muse-explicit-link-regexp
199 "\\[\\[\\([^][\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
200 "Regexp used to match [[target][description]] links.
201 Paren group 1 must match the URL, and paren group 2 the description."
202 :type 'regexp
203 :group 'muse-regexp)
205 (defcustom muse-implicit-link-regexp
206 (concat "\\([^" muse-regexp-blank "\n]+\\)")
207 "Regexp used to match an implicit link.
208 An implicit link is the largest block of text to be checked for
209 URLs and bare WikiNames by the `muse-link-at-point' function.
210 Paren group 1 is the text to be checked.
212 URLs are checked by default. To get WikiNames, load
213 muse-wiki.el.
215 This is only used when you are using muse-mode.el, but not
216 muse-colors.el.
218 If the above applies, and you want to match things with spaces in
219 them, you will have to modify this."
220 :type 'regexp
221 :group 'muse-regexp)
223 ;;; Regexps used to determine file types
225 (defcustom muse-file-regexp
226 (concat "\\`[~/]\\|\\?\\|/\\'\\|\\."
227 "\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)"
228 "\\(\\.\\(gz\\|bz2\\)\\)?\\'")
229 "A link matching this regexp will be regarded as a link to a file."
230 :type 'regexp
231 :group 'muse-regexp)
233 (defcustom muse-image-regexp
234 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
235 "A link matching this regexp will be published inline as an image.
236 For example:
238 [[./wife.jpg][A picture of my wife]]
240 If you omit the description, the alt tag of the resulting HTML
241 buffer will be the name of the file."
242 :type 'regexp
243 :group 'muse-regexp)
245 (provide 'muse-regexps)
247 ;;; muse-regexps.el ends here