Function: ispell-region
ispell-region is an autoloaded, interactive and byte-compiled function
defined in ispell.el.gz.
Signature
(ispell-region REG-START REG-END &optional RECHECKP SHIFT)
Documentation
Interactively check a region for spelling errors.
Leave the mark at the last misspelled word that the user was queried about.
Return nil if spell session was terminated, otherwise returns shift offset amount for last line processed.
Probably introduced at or before Emacs version 19.20.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/ispell.el.gz
;; Spelling of comments are checked when ispell-check-comments is non-nil.
;;;###autoload
(defun ispell-region (reg-start reg-end &optional recheckp shift)
"Interactively check a region for spelling errors.
Leave the mark at the last misspelled word that the user was queried about.
Return nil if spell session was terminated, otherwise returns shift offset
amount for last line processed."
(interactive "r") ; Don't flag errors on read-only bufs.
(ispell-set-spellchecker-params) ; Initialize variables and dicts alists
(if (not recheckp)
(ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
(let ((skip-region-start (make-marker))
(rstart (make-marker))
(region-type (if (and (= reg-start (point-min)) (= reg-end (point-max)))
(buffer-name) "region"))
(program-basename (file-name-nondirectory ispell-program-name))
(dictionary (or ispell-current-dictionary "default"))
max-word)
(unwind-protect
(save-excursion
(message "Spell-checking %s using %s with %s dictionary..."
region-type program-basename dictionary)
;; Returns cursor to original location.
(save-window-excursion
(goto-char reg-start)
(let ((transient-mark-mode)
(case-fold-search case-fold-search)
(query-fcc t)
in-comment key)
(ispell-print-if-debug
"ispell-region: (ispell-skip-region-list):\n%s
ispell-region: (ispell-begin-skip-region-regexp):\n%s
ispell-region: Search for first region to skip after (ispell-begin-skip-region-regexp)\n"
(ispell-skip-region-list)
(ispell-begin-skip-region-regexp))
(if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t)
(progn
(setq key (match-string-no-properties 0))
(set-marker skip-region-start (- (point) (length key)))
(goto-char reg-start)
(ispell-print-if-debug
"ispell-region: First skip: %s at (pos,line,column): (%s,%s,%s).\n"
key
(save-excursion (goto-char skip-region-start) (point))
(line-number-at-pos skip-region-start)
(save-excursion (goto-char skip-region-start) (current-column)))))
(ispell-print-if-debug
"ispell-region: Continue spell-checking with %s and %s dictionary...\n"
program-basename dictionary)
(set-marker rstart reg-start)
(set-marker ispell-region-end reg-end)
(while (and (not ispell-quit)
(< (point) ispell-region-end))
;; spell-check region with skipping
(if (and (marker-position skip-region-start)
(<= skip-region-start (point)))
(progn
;; If region inside line comment, must keep comment start.
(setq in-comment (point)
in-comment
(and comment-start
(or (null comment-end) (string= "" comment-end))
(save-excursion
(beginning-of-line)
(re-search-forward comment-start in-comment t))
comment-start))
;; Can change skip-regexps (in ispell-message)
(ispell-skip-region key) ; moves pt past region.
(set-marker rstart (point))
;; check for saving large attachments...
(setq query-fcc (and query-fcc
(ispell-ignore-fcc skip-region-start
rstart)))
(if (and (< rstart ispell-region-end)
(re-search-forward
(ispell-begin-skip-region-regexp)
ispell-region-end t))
(progn
(setq key (match-string-no-properties 0))
(set-marker skip-region-start
(- (point) (length key)))
(goto-char rstart)
(ispell-print-if-debug
"ispell-region: Next skip: %s at (pos,line,column): (%s,%s,%s).\n"
key
(save-excursion (goto-char skip-region-start) (point))
(line-number-at-pos skip-region-start)
(save-excursion (goto-char skip-region-start) (current-column))))
(set-marker skip-region-start nil))))
(setq reg-end (max (point)
(if (marker-position skip-region-start)
(min skip-region-start ispell-region-end)
(marker-position ispell-region-end))))
(let* ((ispell-start (point))
(ispell-end (min (line-end-position) reg-end))
;; See if line must be prefixed by comment string to let ispell know this is
;; part of a comment string. This is only supported in some modes.
;; In particular, this is not supported in autoconf mode where adding the
;; comment string messes everything up because ispell tries to spellcheck the
;; `dnl' string header causing misalignments in some cases (debbugs.gnu.org: #12768).
(add-comment (and in-comment
(not (string= in-comment "dnl "))
in-comment))
(string (ispell-get-line
ispell-start ispell-end add-comment)))
(ispell-print-if-debug
"ispell-region: string pos (%s->%s), eol: %s, [in-comment]: [%s], [add-comment]: [%s], [string]: [%s]\n"
ispell-start ispell-end (line-end-position)
in-comment add-comment string)
(if add-comment ; account for comment chars added
(setq ispell-start (- ispell-start (length add-comment))
;; Reset `in-comment' (and indirectly `add-comment') for new line
in-comment nil))
(setq ispell-end (point)) ; "end" tracks region retrieved.
;; There is something to spell check!
(when string
;; (special start end)
(let ((res (ispell-process-line string
(and recheckp shift))))
(setq shift (car res))
(when (cdr res)
(setq max-word (cdr res)))))
(goto-char ispell-end)))))
(if ispell-quit
nil
(or shift 0)))
;; protected
(if (and (not (and recheckp ispell-keep-choices-win))
(get-buffer ispell-choices-buffer))
(kill-buffer ispell-choices-buffer))
(set-marker skip-region-start nil)
(set-marker rstart nil)
;; Allow the user to pop back to the last position.
(when max-word
(push-mark max-word t))
(if ispell-quit
(progn
;; preserve or clear the region for ispell-continue.
(if (not (numberp ispell-quit))
(set-marker ispell-region-end nil)
;; Ispell-continue enabled - ispell-region-end is set.
(goto-char ispell-quit))
;; Check for aborting
(if (and ispell-checking-message (numberp ispell-quit))
(progn
(setq ispell-quit nil)
(error "Message send aborted")))
(if (not recheckp) (setq ispell-quit nil)))
(if (not recheckp) (set-marker ispell-region-end nil))
;; Only save if successful exit.
(ispell-pdict-save ispell-silently-savep)
(message "Spell-checking %s using %s with %s dictionary...done"
region-type program-basename dictionary)))))