Merged from mwolson@gnu.org--2006 (patch 61)
[muse-el.git] / lisp / muse-regexps.el
blob8c8495a45806169c1681f9f4b67c0ca9143ca323
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 (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-tag-regexp
141 (concat "<\\([^/\n" muse-regexp-blank "][^\n" muse-regexp-blank
142 "</>]*\\)\\(\\s-+[^<>]+[^</>]\\)?\\(/\\)?>")
143 "A regexp used to find XML-style tags within a buffer when publishing.
144 Group 1 should be the tag name, group 2 the properties, and group
145 3 the optional immediate ending slash."
146 :type 'regexp
147 :group 'muse-regexp)
149 (defcustom muse-explicit-link-regexp
150 "\\[\\[\\([^][\t\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
151 "Regexp used to match [[target][description]] links.
152 Paren group 1 must match the URL, and paren group 2 the description."
153 :type 'regexp
154 :group 'muse-regexp)
156 (defcustom muse-implicit-link-regexp
157 (concat "\\([^" muse-regexp-blank "\n]+\\)")
158 "Regexp used to match an implicit link.
159 An implicit link is the largest block of text to be checked for
160 URLs and bare WikiNames by the `muse-link-at-point' function.
161 Paren group 1 is the text to be checked.
163 URLs are checked by default. To get WikiNames, load
164 muse-wiki.el.
166 If you want to match things with spaces in them, you will have to
167 modify this."
168 :type 'regexp
169 :group 'muse-regexp)
171 (defcustom muse-file-regexp
172 "[/?]\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)\\)?\\'"
173 "A link matching this regexp will be regarded as a link to a file."
174 :type 'regexp
175 :group 'muse-regexp)
177 (defcustom muse-image-regexp
178 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
179 "A link matching this regexp will be published inline as an image.
180 For example:
182 [[./wife.jpg][A picture of my wife]]
184 If you omit the description, the alt tag of the resulting HTML
185 buffer will be the name of the file."
186 :type 'regexp
187 :group 'muse-regexp)
189 (provide 'muse-regexps)
191 ;;; muse-regexps.el ends here