Fix publishing error with tables and initial whitespace.
[muse-el.git] / lisp / muse-regexps.el
blob794d2f1294a2fc9548b9ba0d9178f727fa745a63
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 (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
46 does not support them.
48 Emacs 21.2 or higher support them, but with enough annoying edge
49 cases that the sanest default is to leave them disabled."
50 :type '(choice (const :tag "Yes" t)
51 (const :tag "No" nil)
52 (const :tag "Let Muse decide" undecided))
53 :group 'muse-regexp)
55 (defvar muse-regexp-emacs-revision
56 (save-match-data
57 (and (string-match "^[0-9]+\\.[0-9]+\\.\\([0-9]+\\)"
58 emacs-version)
59 (match-string 1 emacs-version)
60 (string-to-number (match-string 1 emacs-version))))
61 "The revision number of this version of Emacs.")
63 (defun muse-extreg-usable-p ()
64 "Return non-nil if extended character classes can be used,
65 nil otherwise.
67 This is used when deciding the initial values of the muse-regexp
68 options."
69 (cond
70 ((eq muse-regexp-use-character-classes t)
72 ((eq muse-regexp-use-character-classes nil)
73 nil)
74 ((featurep 'xemacs) nil) ; unusable on XEmacs
75 ((> emacs-major-version 21) t) ; usable if > 21
76 ((< emacs-major-version 21) nil)
77 ((< emacs-minor-version 3) nil)
78 ;; don't use if version is of format 21.x
79 ((null muse-regexp-emacs-revision) nil)
80 ;; only trust 21.3.50 or higher
81 ((>= muse-regexp-emacs-revision 50) t)
82 (t nil)))
84 (defcustom muse-regexp-blank
85 (if (muse-extreg-usable-p)
86 "[:blank:]"
87 " \t")
88 "Regexp to use in place of \"[:blank:]\".
89 This should be something that matches spaces and tabs.
91 It is like a regexp, but should be embeddable inside brackets.
92 Muse will detect the appropriate value correctly most of
93 the time."
94 :type 'string
95 :options '("[:blank:]" " \t")
96 :group 'muse-regexp)
98 (defcustom muse-regexp-alnum
99 (if (muse-extreg-usable-p)
100 "[:alnum:]"
101 "A-Za-z0-9")
102 "Regexp to use in place of \"[:alnum:]\".
103 This should be something that matches all letters and numbers.
105 It is like a regexp, but should be embeddable inside brackets.
106 muse will detect the appropriate value correctly most of
107 the time."
108 :type 'string
109 :options '("[:alnum:]" "A-Za-z0-9")
110 :group 'muse-regexp)
112 (defcustom muse-regexp-lower
113 (if (muse-extreg-usable-p)
114 "[:lower:]"
115 "a-z")
116 "Regexp to use in place of \"[:lower:]\".
117 This should match all lowercase characters.
119 It is like a regexp, but should be embeddable inside brackets.
120 muse will detect the appropriate value correctly most of
121 the time."
122 :type 'string
123 :options '("[:lower:]" "a-z")
124 :group 'muse-regexp)
126 (defcustom muse-regexp-upper
127 (if (muse-extreg-usable-p)
128 "[:upper:]"
129 "A-Z")
130 "Regexp to use in place of \"[:upper:]\".
131 This should match all uppercase characters.
133 It is like a regexp, but should be embeddable inside brackets.
134 muse will detect the appropriate value correctly most of
135 the time."
136 :type 'string
137 :options '("[:upper:]" "A-Z")
138 :group 'muse-regexp)
140 (defcustom muse-list-item-regexp
141 (concat "^%s\\([" muse-regexp-blank "]-[" muse-regexp-blank
142 "]*\\|[" muse-regexp-blank "][0-9]+\\.["
143 muse-regexp-blank "]*\\|\\([^\n" muse-regexp-blank "].*?\\)?"
144 "::\\(?:[" muse-regexp-blank "]+\\|$\\)\\)")
145 "Regexp used to match the beginning of a list item.
146 The '%s' will be replaced with a whitespace regexp when publishing."
147 :type 'regexp
148 :group 'muse-regexp)
150 (defcustom muse-dl-term-regexp
151 (concat "[" muse-regexp-blank "]*\\(.+?\\)["
152 muse-regexp-blank "]+::\\(?:[" muse-regexp-blank "]+\\|$\\)")
153 "Regexp used to match a definition list term.
154 The first match string must contain the term."
155 :type 'regexp
156 :group 'muse-regexp)
158 (defcustom muse-table-field-regexp
159 (concat "[" muse-regexp-blank "]+\\(|+\\)\\(?:["
160 muse-regexp-blank "]+\\|$\\)")
161 "Regexp used to match table separators when publishing."
162 :type 'regexp
163 :group 'muse-regexp)
165 (defcustom muse-table-line-regexp (concat "^.*" muse-table-field-regexp ".*")
166 "Regexp used to match a table line when publishing."
167 :type 'regexp
168 :group 'muse-regexp)
170 (defcustom muse-tag-regexp
171 (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank
172 "</>\n]*\\)\\(\\s-+[^<>\n]+[^</>\n]\\)?\\(/\\)?>")
173 "A regexp used to find XML-style tags within a buffer when publishing.
174 Group 1 should be the tag name, group 2 the properties, and group
175 3 the optional immediate ending slash."
176 :type 'regexp
177 :group 'muse-regexp)
179 (defcustom muse-explicit-link-regexp
180 "\\[\\[\\([^][\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
181 "Regexp used to match [[target][description]] links.
182 Paren group 1 must match the URL, and paren group 2 the description."
183 :type 'regexp
184 :group 'muse-regexp)
186 (defcustom muse-implicit-link-regexp
187 (concat "\\([^" muse-regexp-blank "\n]+\\)")
188 "Regexp used to match an implicit link.
189 An implicit link is the largest block of text to be checked for
190 URLs and bare WikiNames by the `muse-link-at-point' function.
191 Paren group 1 is the text to be checked.
193 URLs are checked by default. To get WikiNames, load
194 muse-wiki.el.
196 This is only used when you are using muse-mode.el, but not
197 muse-colors.el.
199 If the above applies, and you want to match things with spaces in
200 them, you will have to modify this."
201 :type 'regexp
202 :group 'muse-regexp)
204 (defcustom muse-file-regexp
205 "[/?]\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)\\)?\\'"
206 "A link matching this regexp will be regarded as a link to a file."
207 :type 'regexp
208 :group 'muse-regexp)
210 (defcustom muse-image-regexp
211 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
212 "A link matching this regexp will be published inline as an image.
213 For example:
215 [[./wife.jpg][A picture of my wife]]
217 If you omit the description, the alt tag of the resulting HTML
218 buffer will be the name of the file."
219 :type 'regexp
220 :group 'muse-regexp)
222 (provide 'muse-regexps)
224 ;;; muse-regexps.el ends here