Merged from mwolson@gnu.org--2006-muse-el (patch 92)
[muse-el.git] / lisp / muse-regexps.el
blob3f84b10aaf4a11c34d9602657f20f3619572ce48
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-tag-regexp
176 (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank
177 "</>\n]*\\)\\(\\s-+[^<>\n]+[^</>\n]\\)?\\(/\\)?>")
178 "A regexp used to find XML-style tags within a buffer when publishing.
179 Group 1 should be the tag name, group 2 the properties, and group
180 3 the optional immediate ending slash."
181 :type 'regexp
182 :group 'muse-regexp)
184 (defcustom muse-explicit-link-regexp
185 "\\[\\[\\([^][\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
186 "Regexp used to match [[target][description]] links.
187 Paren group 1 must match the URL, and paren group 2 the description."
188 :type 'regexp
189 :group 'muse-regexp)
191 (defcustom muse-implicit-link-regexp
192 (concat "\\([^" muse-regexp-blank "\n]+\\)")
193 "Regexp used to match an implicit link.
194 An implicit link is the largest block of text to be checked for
195 URLs and bare WikiNames by the `muse-link-at-point' function.
196 Paren group 1 is the text to be checked.
198 URLs are checked by default. To get WikiNames, load
199 muse-wiki.el.
201 This is only used when you are using muse-mode.el, but not
202 muse-colors.el.
204 If the above applies, and you want to match things with spaces in
205 them, you will have to modify this."
206 :type 'regexp
207 :group 'muse-regexp)
209 ;;; Regexps used to determine file types
211 (defcustom muse-file-regexp
212 (concat "\\`[~/]\\|\\?\\|\\."
213 "\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)"
214 "\\(\\.\\(gz\\|bz2\\)\\)?\\'")
215 "A link matching this regexp will be regarded as a link to a file."
216 :type 'regexp
217 :group 'muse-regexp)
219 (defcustom muse-image-regexp
220 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
221 "A link matching this regexp will be published inline as an image.
222 For example:
224 [[./wife.jpg][A picture of my wife]]
226 If you omit the description, the alt tag of the resulting HTML
227 buffer will be the name of the file."
228 :type 'regexp
229 :group 'muse-regexp)
231 (provide 'muse-regexps)
233 ;;; muse-regexps.el ends here