Commit 9ae19d2f authored by Alan Mackenzie's avatar Alan Mackenzie
Browse files

Enhance ispell-skip-region-alist by generating part of it at runtime.

* lisp/textmodes/ispell.el (ispell--\\w-filter, ispell--make-\\w-expression)
(ispell--make-filename-or-URL-re): New functions which generate a regexp.
(ispell-skip-region-alist): Remove the bit that matches a filename/URL, etc.
(ispell-begin-skip-region-regexp, ispell-skip-region-list, ispell-message):
Include the result of ispell--make-filename-or-URL-re in regexps.
parent e8937de5
......@@ -1782,6 +1782,51 @@ Extended character mode can be changed for this buffer by placing
a `~' followed by an extended-character mode -- such as `~.tex'.
The last occurring definition in the buffer will be used.")
(defun ispell--\\w-filter (char)
"Return CHAR in a string when CHAR doesn't have \"word\" syntax,
nil otherwise. CHAR must be a character."
(let ((str (string char)))
(not (string-match "\\w" str))
(defun ispell--make-\\w-expression (chars)
"Make a regular expression like \"\\(\\w\\|[-_]\\)\".
This (parenthesized) expression matches either a character of
\"word\" syntax or one in CHARS.
CHARS is a string of characters. A member of CHARS is omitted
from the expression if it already has word syntax. (Be careful
about special characters such as ?\\, ?^, ?], and ?- in CHARS.)
If after this filtering there are no chars left, or only one, a
special form of the expression is generated."
(let ((filtered
(mapconcat #'ispell--\\w-filter chars "")))
((equal filtered "")
((eq (length filtered) 1)
(concat "\\|" filtered "\\)"))
(concat "\\|[" filtered "]\\)"))))))
(defun ispell--make-filename-or-URL-re ()
"Construct a regexp to match some file names or URLs or email addresses.
The expression is crafted to match as great a variety of these
objects as practicable, without too many false matches happening."
(concat ;"\\(--+\\|_+\\|"
(ispell--make-\\w-expression "-_")
(ispell--make-\\w-expression "-_")
(ispell--make-\\w-expression "-_~=?&")
(defvar ispell-skip-region-alist
`((ispell-words-keyword forward-line)
......@@ -1798,7 +1843,7 @@ The last occurring definition in the buffer will be used.")
;; Matches e-mail addresses, file names, http addresses, etc. The
;; `-+' `_+' patterns are necessary for performance reasons when
;; `-' or `_' part of word syntax.
(,(purecopy "\\(--+\\|_+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)"))
; (,(purecopy "\\(--+\\|_+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)"))
;; above checks /.\w sequences
;; This is a pretty complex regexp. It can be simplified to the following:
......@@ -3387,7 +3432,8 @@ Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
(if (string= "" comment-end) "^" (regexp-quote comment-end)))
(if (and (null ispell-check-comments) comment-start)
(regexp-quote comment-start))
(ispell-begin-skip-region ispell-skip-region-alist)))
(ispell-begin-skip-region ispell-skip-region-alist)
......@@ -3426,6 +3472,8 @@ Manual checking must include comments and tib references.
The list is of the form described by variable `ispell-skip-region-alist'.
Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
(let ((skip-alist ispell-skip-region-alist))
(setq skip-alist (append (list (list (ispell--make-filename-or-URL-re)))
;; only additional explicit region definition is tex.
(if (eq ispell-parser 'tex)
(setq case-fold-search nil
......@@ -4119,9 +4167,10 @@ You can bind this to the key C-c i in GNUS or mail by adding to
(ispell-non-empty-string vm-included-text-prefix)))
(t default-prefix)))
(cons (list (concat "^\\(" cite-regexp "\\)")
(function forward-line))
(cons (list (ispell--make-filename-or-URL-re))
(cons (list (concat "^\\(" cite-regexp "\\)")
(function forward-line))
(old-case-fold-search case-fold-search)
(dictionary-alist ispell-message-dictionary-alist)
(ispell-checking-message t))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment