Manual: Begin documenting muse-project-alist options
[muse-el.git] / lisp / muse-regexps.el
blob6bd2f40df9c781e141289dea9956efc7eb4642f2
1 ;;; muse-regexps.el --- define regexps used by Muse
3 ;; Copyright (C) 2004, 2005, 2006, 2007 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\\(\\([^\n" muse-regexp-blank "].*?\\)?::"
147 "\\(?:[" muse-regexp-blank "]+\\|$\\)"
148 "\\|[" muse-regexp-blank "]-[" muse-regexp-blank "]*"
149 "\\|[" muse-regexp-blank "][0-9]+\\.[" 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-ol-item-regexp (concat "\\`[" muse-regexp-blank "]+[0-9]+\\.")
156 "Regexp used to match an ordered list item."
157 :type 'regexp
158 :group 'muse-regexp)
160 (defcustom muse-ul-item-regexp (concat "\\`[" muse-regexp-blank "]+-")
161 "Regexp used to match an unordered list item."
162 :type 'regexp
163 :group 'muse-regexp)
165 (defcustom muse-dl-term-regexp
166 (concat "[" muse-regexp-blank "]*\\(.+?\\)["
167 muse-regexp-blank "]+::\\(?:[" muse-regexp-blank "]+\\|$\\)")
168 "Regexp used to match a definition list term.
169 The first match string must contain the term."
170 :type 'regexp
171 :group 'muse-regexp)
173 (defcustom muse-dl-entry-regexp (concat "\\`[" muse-regexp-blank "]*::")
174 "Regexp used to match a definition list entry."
175 :type 'regexp
176 :group 'muse-regexp)
178 (defcustom muse-table-field-regexp
179 (concat "[" muse-regexp-blank "]+\\(|+\\)\\(?:["
180 muse-regexp-blank "]\\|$\\)")
181 "Regexp used to match table separators when publishing."
182 :type 'regexp
183 :group 'muse-regexp)
185 (defcustom muse-table-line-regexp (concat ".*" muse-table-field-regexp ".*")
186 "Regexp used to match a table line when publishing."
187 :type 'regexp
188 :group 'muse-regexp)
190 (defcustom muse-table-hline-regexp (concat "[" muse-regexp-blank
191 "]*|[-+]+|[" muse-regexp-blank
192 "]*")
193 "Regexp used to match a horizontal separator line in a table."
194 :type 'regexp
195 :group 'muse-regexp)
197 (defcustom muse-table-el-border-regexp (concat "[" muse-regexp-blank "]*"
198 "\\+\\(-*\\+\\)+"
199 "[" muse-regexp-blank "]*")
200 "Regexp used to match the beginning and end of a table.el-style table."
201 :type 'regexp
202 :group 'muse-regexp)
204 (defcustom muse-tag-regexp
205 (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank
206 "</>\n]*\\)\\(\\s-+[^<>\n]+[^</>\n]\\)?\\(/\\)?>")
207 "A regexp used to find XML-style tags within a buffer when publishing.
208 Group 1 should be the tag name, group 2 the properties, and group
209 3 the optional immediate ending slash."
210 :type 'regexp
211 :group 'muse-regexp)
213 (defcustom muse-explicit-link-regexp
214 "\\[\\[\\([^][\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
215 "Regexp used to match [[target][description]] links.
216 Paren group 1 must match the URL, and paren group 2 the description."
217 :type 'regexp
218 :group 'muse-regexp)
220 (defcustom muse-implicit-link-regexp
221 (concat "\\([^" muse-regexp-blank "\n]+\\)")
222 "Regexp used to match an implicit link.
223 An implicit link is the largest block of text to be checked for
224 URLs and bare WikiNames by the `muse-link-at-point' function.
225 Paren group 1 is the text to be checked.
227 URLs are checked by default. To get WikiNames, load
228 muse-wiki.el.
230 This is only used when you are using muse-mode.el, but not
231 muse-colors.el.
233 If the above applies, and you want to match things with spaces in
234 them, you will have to modify this."
235 :type 'regexp
236 :group 'muse-regexp)
238 ;;; Regexps used to determine file types
240 (defcustom muse-file-regexp
241 (concat "\\`[~/]\\|\\?\\|/\\'\\|\\."
242 "\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)"
243 "\\(\\.\\(gz\\|bz2\\)\\)?\\'")
244 "A link matching this regexp will be regarded as a link to a file."
245 :type 'regexp
246 :group 'muse-regexp)
248 (defcustom muse-image-regexp
249 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
250 "A link matching this regexp will be published inline as an image.
251 For example:
253 [[./wife.jpg][A picture of my wife]]
255 If you omit the description, the alt tag of the resulting HTML
256 buffer will be the name of the file."
257 :type 'regexp
258 :group 'muse-regexp)
260 (provide 'muse-regexps)
262 ;;; muse-regexps.el ends here