Merged from mwolson@gnu.org--2005 (patch 298)
[muse-el.git] / lisp / muse-regexps.el
blob1623eb34c9a9f1e7b59bf118b1a2d9b058508580
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-space
99 (if (muse-extreg-usable-p)
100 "[:space:]"
101 " \t\n")
102 "Regexp to use in place of \"[:space:]\".
103 This should be something that matches spaces, tabs, and newlines.
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 '("[:space:]" " \t\n")
110 :group 'muse-regexp)
112 (defcustom muse-regexp-alnum
113 (if (muse-extreg-usable-p)
114 "[:alnum:]"
115 "A-Za-z0-9")
116 "Regexp to use in place of \"[:alnum:]\".
117 This should be something that matches all letters and numbers.
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 '("[:alnum:]" "A-Za-z0-9")
124 :group 'muse-regexp)
126 (defcustom muse-regexp-lower
127 (if (muse-extreg-usable-p)
128 "[:lower:]"
129 "a-z")
130 "Regexp to use in place of \"[:lower:]\".
131 This should match all lowercase 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 '("[:lower:]" "a-z")
138 :group 'muse-regexp)
140 (defcustom muse-regexp-upper
141 (if (muse-extreg-usable-p)
142 "[:upper:]"
143 "A-Z")
144 "Regexp to use in place of \"[:upper:]\".
145 This should match all uppercase characters.
147 It is like a regexp, but should be embeddable inside brackets.
148 muse will detect the appropriate value correctly most of
149 the time."
150 :type 'string
151 :options '("[:upper:]" "A-Z")
152 :group 'muse-regexp)
154 (defcustom muse-tag-regexp
155 (concat "<\\([^/" muse-regexp-space "][^" muse-regexp-space
156 "</>]*\\)\\(\\s-+[^<>]+[^</>]\\)?\\(/\\)?>")
157 "A regexp used to find XML-style tags within a buffer when publishing.
158 Group 1 should be the tag name, group 2 the properties, and group
159 3 the optional immediate ending slash."
160 :type 'regexp
161 :group 'muse-regexp)
163 (defcustom muse-explicit-link-regexp
164 "\\[\\[\\([^][\t\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
165 "Regexp used to match [[target][description]] links.
166 Paren group 1 must match the URL, and paren group 2 the description."
167 :type 'regexp
168 :group 'muse-regexp)
170 (defcustom muse-implicit-link-regexp
171 (concat "\\([^" muse-regexp-space "]+\\)")
172 "Regexp used to match an implicit link.
173 An implicit link is the largest block of text to be checked for
174 URLs and bare WikiNames by the `muse-link-at-point' function.
175 Paren group 1 is the text to be checked.
177 URLs are checked by default. To get WikiNames, load
178 muse-wiki.el.
180 If you want to match things with spaces in them, you will have to
181 modify this."
182 :type 'regexp
183 :group 'muse-regexp)
185 (defcustom muse-file-regexp
186 "[/?]\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)\\)?\\'"
187 "A link matching this regexp will be regarded as a link to a file."
188 :type 'regexp
189 :group 'muse-regexp)
191 (defcustom muse-image-regexp
192 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
193 "A link matching this regexp will be published inline as an image.
194 For example:
196 [[./wife.jpg][A picture of my wife]]
198 If you omit the description, the alt tag of the resulting HTML
199 buffer will be the name of the file."
200 :type 'regexp
201 :group 'muse-regexp)
203 (provide 'muse-regexps)
205 ;;; muse-regexps.el ends here