1 ;;; muse-regexps.el --- define regexps used by Muse
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
8 ;; Emacs Muse is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 3, or (at your
11 ;; option) any later version.
13 ;; Emacs Muse is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with Emacs Muse; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
25 ;; This file is the part of the Muse project that describes regexps
26 ;; that are used throughout the project.
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 ;; Muse Regular Expressions
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 (defgroup muse-regexp nil
39 "Regular expressions used in publishing and syntax highlighting."
42 ;;; Deal with the lack of character classes for regexps in Emacs21 and
45 (defcustom muse-regexp-use-character-classes 'undecided
46 "Indicate whether to use extended character classes like [:space:].
47 If 'undecided, Muse will use them if your emacs is known to support them.
49 Emacs 22 and Emacs 21.3.50 are known to support them. XEmacs
50 does not support them.
52 Emacs 21.2 or higher support them, but with enough annoying edge
53 cases that the sanest default is to leave them disabled."
54 :type '(choice (const :tag "Yes" t)
56 (const :tag "Let Muse decide" undecided))
59 (defvar muse-regexp-emacs-revision
61 (and (string-match "^[0-9]+\\.[0-9]+\\.\\([0-9]+\\)"
63 (match-string 1 emacs-version)
64 (string-to-number (match-string 1 emacs-version))))
65 "The revision number of this version of Emacs.")
67 (defun muse-extreg-usable-p ()
68 "Return non-nil if extended character classes can be used,
71 This is used when deciding the initial values of the muse-regexp
74 ((eq muse-regexp-use-character-classes t)
76 ((eq muse-regexp-use-character-classes nil)
78 ((featurep 'xemacs) nil) ; unusable on XEmacs
79 ((> emacs-major-version 21) t) ; usable if > 21
80 ((< emacs-major-version 21) nil)
81 ((< emacs-minor-version 3) nil)
82 ;; don't use if version is of format 21.x
83 ((null muse-regexp-emacs-revision) nil)
84 ;; only trust 21.3.50 or higher
85 ((>= muse-regexp-emacs-revision 50) t)
88 (defcustom muse-regexp-blank
89 (if (muse-extreg-usable-p)
92 "Regexp to use in place of \"[:blank:]\".
93 This should be something that matches spaces and tabs.
95 It is like a regexp, but should be embeddable inside brackets.
96 Muse will detect the appropriate value correctly most of
99 :options '("[:blank:]" " \t")
102 (defcustom muse-regexp-alnum
103 (if (muse-extreg-usable-p)
106 "Regexp to use in place of \"[:alnum:]\".
107 This should be something that matches all letters and numbers.
109 It is like a regexp, but should be embeddable inside brackets.
110 muse will detect the appropriate value correctly most of
113 :options '("[:alnum:]" "A-Za-z0-9")
116 (defcustom muse-regexp-lower
117 (if (muse-extreg-usable-p)
120 "Regexp to use in place of \"[:lower:]\".
121 This should match all lowercase characters.
123 It is like a regexp, but should be embeddable inside brackets.
124 muse will detect the appropriate value correctly most of
127 :options '("[:lower:]" "a-z")
130 (defcustom muse-regexp-upper
131 (if (muse-extreg-usable-p)
134 "Regexp to use in place of \"[:upper:]\".
135 This should match all uppercase characters.
137 It is like a regexp, but should be embeddable inside brackets.
138 muse will detect the appropriate value correctly most of
141 :options '("[:upper:]" "A-Z")
144 ;;; Regexps used to define Muse publishing syntax
146 (defcustom muse-list-item-regexp
147 (concat "^%s\\(\\([^\n" muse-regexp-blank "].*?\\)?::"
148 "\\(?:[" muse-regexp-blank "]+\\|$\\)"
149 "\\|[" muse-regexp-blank "]-[" muse-regexp-blank "]*"
150 "\\|[" muse-regexp-blank "][0-9]+\\.[" muse-regexp-blank "]*\\)")
151 "Regexp used to match the beginning of a list item.
152 The '%s' will be replaced with a whitespace regexp when publishing."
156 (defcustom muse-ol-item-regexp (concat "\\`[" muse-regexp-blank "]+[0-9]+\\.")
157 "Regexp used to match an ordered list item."
161 (defcustom muse-ul-item-regexp (concat "\\`[" muse-regexp-blank "]+-")
162 "Regexp used to match an unordered list item."
166 (defcustom muse-dl-term-regexp
167 (concat "[" muse-regexp-blank "]*\\(.+?\\)["
168 muse-regexp-blank "]+::\\(?:[" muse-regexp-blank "]+\\|$\\)")
169 "Regexp used to match a definition list term.
170 The first match string must contain the term."
174 (defcustom muse-dl-entry-regexp (concat "\\`[" muse-regexp-blank "]*::")
175 "Regexp used to match a definition list entry."
179 (defcustom muse-table-field-regexp
180 (concat "[" muse-regexp-blank "]+\\(|+\\)\\(?:["
181 muse-regexp-blank "]\\|$\\)")
182 "Regexp used to match table separators when publishing."
186 (defcustom muse-table-line-regexp (concat ".*" muse-table-field-regexp ".*")
187 "Regexp used to match a table line when publishing."
191 (defcustom muse-table-hline-regexp (concat "[" muse-regexp-blank
192 "]*|[-+]+|[" muse-regexp-blank
194 "Regexp used to match a horizontal separator line in a table."
198 (defcustom muse-table-el-border-regexp (concat "[" muse-regexp-blank "]*"
200 "[" muse-regexp-blank "]*")
201 "Regexp used to match the beginning and end of a table.el-style table."
205 (defcustom muse-table-el-line-regexp (concat "[" muse-regexp-blank "]*"
207 "[" muse-regexp-blank "]*")
208 "Regexp used to match a table line of a table.el-style table."
212 (defcustom muse-tag-regexp
213 (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank
214 "</>\n]*\\)\\(\\s-+[^<>]+[^</>\n]\\)?\\(/\\)?>")
215 "A regexp used to find XML-style tags within a buffer when publishing.
216 Group 1 should be the tag name, group 2 the properties, and group
217 3 the optional immediate ending slash."
221 (defcustom muse-explicit-link-regexp
222 "\\[\\[\\([^][\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
223 "Regexp used to match [[target][description]] links.
224 Paren group 1 must match the URL, and paren group 2 the description."
228 (defcustom muse-implicit-link-regexp
229 (concat "\\([^" muse-regexp-blank "\n]+\\)")
230 "Regexp used to match an implicit link.
231 An implicit link is the largest block of text to be checked for
232 URLs and bare WikiNames by the `muse-link-at-point' function.
233 Paren group 1 is the text to be checked.
235 URLs are checked by default. To get WikiNames, load
238 This is only used when you are using muse-mode.el, but not
241 If the above applies, and you want to match things with spaces in
242 them, you will have to modify this."
246 ;;; Regexps used to determine file types
248 (defcustom muse-file-regexp
249 (concat "\\`[~/]\\|\\?\\|/\\'\\|\\."
250 "\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)"
251 "\\(\\.\\(gz\\|bz2\\)\\)?\\'")
252 "A link matching this regexp will be regarded as a link to a file."
256 (defcustom muse-image-regexp
257 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
258 "A link matching this regexp will be published inline as an image.
261 [[./wife.jpg][A picture of my wife]]
263 If you omit the description, the alt tag of the resulting HTML
264 buffer will be the name of the file."
268 (provide 'muse-regexps)
270 ;;; muse-regexps.el ends here