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
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
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.
24 ;; This file is the part of the Muse project that describes regexps
25 ;; that are used throughout the project.
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; Muse Regular Expressions
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 (defgroup muse-regexp nil
38 "Regular expressions used in publishing and syntax highlighting."
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 does
48 Emacs 21.2 or higher might support them, but the maintainer is
49 uncertain, so by default extended regexps are not used with these
51 :type
'(choice (const :tag
"Yes" t
)
53 (const :tag
"Let Muse decide" undecided
))
56 (defun muse-extreg-usable-p ()
57 "Return non-nil if extended character classes can be used,
60 This is used when deciding the initial values of the muse-regexp
63 ((eq muse-regexp-use-character-classes t
)
65 ((eq muse-regexp-use-character-classes nil
)
69 (string-match "^[0-9]+\\.[0-9]+\\.\\([0-9]+\\)"
71 (cond ((featurep 'xemacs
) nil
) ; unusable on XEmacs
72 ((> emacs-major-version
21) t
) ; usable if > 21
73 ((< emacs-major-version
21) nil
)
74 ((< emacs-minor-version
3) nil
)
75 ;; don't use if version is of format 21.x
76 ((null (match-string 1 emacs-version
)) nil
)
77 ;; don't trust the 21.3.1 release or its predecessors
78 ((> (string-to-number (match-string 1 emacs-version
)) 1) t
)
81 (defcustom muse-regexp-blank
82 (if (muse-extreg-usable-p)
85 "Regexp to use in place of \"[:blank:]\".
86 This should be something that matches spaces and tabs.
88 It is like a regexp, but should be embeddable inside brackets.
89 Muse will detect the appropriate value correctly most of
92 :options
'("[:blank:]" " \t")
95 (defcustom muse-regexp-space
96 (if (muse-extreg-usable-p)
99 "Regexp to use in place of \"[:space:]\".
100 This should be something that matches spaces, tabs, and newlines.
102 It is like a regexp, but should be embeddable inside brackets.
103 muse will detect the appropriate value correctly most of
106 :options
'("[:space:]" " \t\n")
109 (defcustom muse-regexp-alnum
110 (if (muse-extreg-usable-p)
113 "Regexp to use in place of \"[:alnum:]\".
114 This should be something that matches all letters and numbers.
116 It is like a regexp, but should be embeddable inside brackets.
117 muse will detect the appropriate value correctly most of
120 :options
'("[:alnum:]" "A-Za-z0-9")
123 (defcustom muse-regexp-lower
124 (if (muse-extreg-usable-p)
127 "Regexp to use in place of \"[:lower:]\".
128 This should match all lowercase characters.
130 It is like a regexp, but should be embeddable inside brackets.
131 muse will detect the appropriate value correctly most of
134 :options
'("[:lower:]" "a-z")
137 (defcustom muse-regexp-upper
138 (if (muse-extreg-usable-p)
141 "Regexp to use in place of \"[:upper:]\".
142 This should match all uppercase characters.
144 It is like a regexp, but should be embeddable inside brackets.
145 muse will detect the appropriate value correctly most of
148 :options
'("[:upper:]" "A-Z")
151 (defcustom muse-tag-regexp
152 (concat "<\\([^/" muse-regexp-space
"][^" muse-regexp-space
153 "</>]*\\)\\(\\s-+[^<>]+[^</>]\\)?\\(/\\)?>")
154 "A regexp used to find XML-style tags within a buffer when publishing.
155 Group 1 should be the tag name, group 2 the properties, and group
156 3 the optional immediate ending slash."
160 (defcustom muse-explicit-link-regexp
161 "\\[\\[\\([^][\t\n]+\\)\\]\\(?:\\[\\([^][\n]+\\)\\]\\)?\\]"
162 "Regexp used to match [[target][description]] links.
163 Paren group 1 must match the URL, and paren group 2 the description."
167 (defcustom muse-implicit-link-regexp
168 (concat "\\([^" muse-regexp-space
"]+\\)")
169 "Regexp used to match an implicit link.
170 An implicit link is the largest block of text to be checked for
171 URLs and bare WikiNames by the `muse-link-at-point' function.
172 Paren group 1 is the text to be checked.
174 URLs are checked by default. To get WikiNames, load
177 If you want to match things with spaces in them, you will have to
182 (defcustom muse-url-regexp
183 (concat "\\<\\(?:https?:/?/?\\|ftp:/?/?\\|gopher://\\|"
184 "telnet://\\|wais://\\|file:/\\|s?news:\\|"
186 "[^]" muse-regexp-space
"\"'()<>[^`{}]*[^]"
187 muse-regexp-space
"\"'()<>[^`{}.,;]+")
188 "A regexp used to match URLs within a Muse page."
192 (defcustom muse-file-regexp
193 "[/?]\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)\\)?\\'"
194 "A link matching this regexp will be regarded as a link to a file."
198 (defcustom muse-image-regexp
199 "\\.\\(eps\\|gif\\|jp\\(e?g\\)\\|p\\(bm\\|ng\\)\\|tiff\\|x\\([bp]m\\)\\)\\'"
200 "A link matching this regexp will be published inline as an image.
203 [[./wife.jpg][A picture of my wife]]
205 If you omit the description, the alt tag of the resulting HTML
206 buffer will be the name of the file."
210 (defvar muse-ignored-extensions-regexp nil
211 "A regexp of extensions to omit from the ending of a Muse page name.
212 This is autogenerated from `muse-ignored-extensions'.")
214 (defun muse-update-ignored-extensions-regexp (sym val
)
215 "Update the value of `muse-ignored-extensions-regexp'."
218 (setq muse-wiki-ignored-extensions-regexp
220 (regexp-quote muse-file-extension
) "\\|"
221 (mapconcat 'identity muse-ignored-extensions
"\\|")
223 (setq muse-wiki-ignored-extensions-regexp
224 (if muse-file-extension
225 (concat "\\.\\(" muse-file-extension
"\\)\\'")
228 (defcustom muse-ignored-extensions
'("bz2" "gz" "[Zz]")
229 "A regexp of extensions to omit from the ending of a Muse page name.
232 Don't put a period at the beginning of each extension unless you
233 understand that it is part of a regexp."
234 :type
'(repeat (regexp :tag
"Extension"))
235 :set
'muse-update-ignored-extensions-regexp
238 (provide 'muse-regexps
)
240 ;;; muse-regexps.el ends here