muse-protocols: Add DOI handling.
[muse-el.git] / lisp / muse-regexps.el
blob354e4d64bd8da9b53529dec9fef8fed8454311ac
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 "]-[" muse-regexp-blank
142 "]*\\|[" muse-regexp-blank "][0-9]+\\.["
143 muse-regexp-blank "]*\\|\\(.*?\\)["
144 muse-regexp-blank "]+::[" 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
166 (concat "^[" muse-regexp-blank "]*\\(?:[^|\n]+\\||\\)"
167 muse-table-field-regexp "[^|\n].*")
168 "Regexp used to match a table line when publishing."
169 :type 'regexp
170 :group 'muse-regexp)
172 (defcustom muse-tag-regexp
173 (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank
174 "</>\n]*\\)\\(\\s-+[^<>\n]+[^</>\n]\\)?\\(/\\)?>")
175 "A regexp used to find XML-style tags within a buffer when publishing.
176 Group 1 should be the tag name, group 2 the properties, and group
177 3 the optional immediate ending slash."
178 :type 'regexp
179 :group 'muse-regexp)
181 (defcustom muse-explicit-link-regexp
182 "\\[\\[\\([^][\t\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
183 "Regexp used to match [[target][description]] links.
184 Paren group 1 must match the URL, and paren group 2 the description."
185 :type 'regexp
186 :group 'muse-regexp)
188 (defcustom muse-implicit-link-regexp
189 (concat "\\([^" muse-regexp-blank "\n]+\\)")
190 "Regexp used to match an implicit link.
191 An implicit link is the largest block of text to be checked for
192 URLs and bare WikiNames by the `muse-link-at-point' function.
193 Paren group 1 is the text to be checked.
195 URLs are checked by default. To get WikiNames, load
196 muse-wiki.el.
198 This is only used when you are using muse-mode.el, but not
199 muse-colors.el.
201 If the above applies, and you want to match things with spaces in
202 them, you will have to modify this."
203 :type 'regexp
204 :group 'muse-regexp)
206 (defcustom muse-file-regexp
207 "[/?]\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)\\)?\\'"
208 "A link matching this regexp will be regarded as a link to a file."
209 :type 'regexp
210 :group 'muse-regexp)
212 (defcustom muse-image-regexp
213 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
214 "A link matching this regexp will be published inline as an image.
215 For example:
217 [[./wife.jpg][A picture of my wife]]
219 If you omit the description, the alt tag of the resulting HTML
220 buffer will be the name of the file."
221 :type 'regexp
222 :group 'muse-regexp)
224 (provide 'muse-regexps)
226 ;;; muse-regexps.el ends here