Fix nested list regression. Make some (untested) progress on dl.
[muse-el.git] / lisp / muse-regexps.el
blobe7e0f76e9e48ca7e8c2984bdbea3f8d12b8f2462
1 ;;; muse-regexps.el --- define regexps used by Muse
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
10 ;; version.
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ;; for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; 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 "]*\\|[0-9]+\\.["
142 muse-regexp-blank "]*\\|\\(?:.+?\\)["
143 muse-regexp-blank "]+::[" muse-regexp-blank "]*\\)")
144 "Regexp used to match the beginning of a list item.
145 The '%s' will be replaced with a whitespace regexp when publishing."
146 :type 'regexp
147 :group 'muse-regexp)
149 (defcustom muse-dl-entry-regexp
150 (concat "^[" muse-regexp-blank "]+::[" muse-regexp-blank "]*")
151 "Regexp used to match the beginning of a definition list entry.
152 Entries usually come after a term."
153 :type 'regexp
154 :group 'muse-regexp)
156 (defcustom muse-table-field-regexp
157 (concat "[" muse-regexp-blank "]+\\(|+\\)[" muse-regexp-blank "]+")
158 "Regexp used to match table separators when publishing."
159 :type 'regexp
160 :group 'muse-regexp)
162 (defcustom muse-table-line-regexp
163 (concat "^[" muse-regexp-blank "]*[^|\n]+" muse-table-field-regexp
164 "[^|\n].*")
165 "Regexp used to match a table line when publishing."
166 :type 'regexp
167 :group 'muse-regexp)
169 (defcustom muse-tag-regexp
170 (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank
171 "</>\n]*\\)\\(\\s-+[^<>\n]+[^</>\n]\\)?\\(/\\)?>")
172 "A regexp used to find XML-style tags within a buffer when publishing.
173 Group 1 should be the tag name, group 2 the properties, and group
174 3 the optional immediate ending slash."
175 :type 'regexp
176 :group 'muse-regexp)
178 (defcustom muse-explicit-link-regexp
179 "\\[\\[\\([^][\t\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
180 "Regexp used to match [[target][description]] links.
181 Paren group 1 must match the URL, and paren group 2 the description."
182 :type 'regexp
183 :group 'muse-regexp)
185 (defcustom muse-implicit-link-regexp
186 (concat "\\([^" muse-regexp-blank "\n]+\\)")
187 "Regexp used to match an implicit link.
188 An implicit link is the largest block of text to be checked for
189 URLs and bare WikiNames by the `muse-link-at-point' function.
190 Paren group 1 is the text to be checked.
192 URLs are checked by default. To get WikiNames, load
193 muse-wiki.el.
195 If you want to match things with spaces in them, you will have to
196 modify this."
197 :type 'regexp
198 :group 'muse-regexp)
200 (defcustom muse-file-regexp
201 "[/?]\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)\\)?\\'"
202 "A link matching this regexp will be regarded as a link to a file."
203 :type 'regexp
204 :group 'muse-regexp)
206 (defcustom muse-image-regexp
207 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
208 "A link matching this regexp will be published inline as an image.
209 For example:
211 [[./wife.jpg][A picture of my wife]]
213 If you omit the description, the alt tag of the resulting HTML
214 buffer will be the name of the file."
215 :type 'regexp
216 :group 'muse-regexp)
218 (provide 'muse-regexps)
220 ;;; muse-regexps.el ends here