Function: whitespace-report-region

whitespace-report-region is an autoloaded, interactive and byte-compiled function defined in whitespace.el.gz.

Signature

(whitespace-report-region START END &optional FORCE REPORT-IF-BOGUS)

Documentation

Report some whitespace problems in a region.

Return nil if there is no whitespace problem; otherwise, return non-nil.

If FORCE is non-nil or C-u (universal-argument) was pressed just before calling whitespace-report-region interactively, it forces all classes of whitespace problem to be considered significant.

If REPORT-IF-BOGUS is t, it reports only when there are any whitespace problems in buffer; if it is never, it does not report problems.

Report if some of the following whitespace problems exist:

* If indent-tabs-mode(var)/indent-tabs-mode(fun) is non-nil:
   empty 1. empty lines at beginning of buffer.
   empty 2. empty lines at end of buffer.
   trailing 3. SPACEs or TABs at end of line.
   indentation 4. line starts with tab-width or more SPACEs.
   space-before-tab 5. SPACEs before TAB.
   space-after-tab 6. tab-width or more SPACEs after TAB.

* If indent-tabs-mode(var)/indent-tabs-mode(fun) is nil:
   empty 1. empty lines at beginning of buffer.
   empty 2. empty lines at end of buffer.
   trailing 3. SPACEs or TABs at end of line.
   indentation 4. TABS at beginning of line.
   space-before-tab 5. SPACEs before TAB.
   space-after-tab 6. tab-width or more SPACEs after TAB.

See whitespace-style for documentation. See also whitespace-cleanup and whitespace-cleanup-region for cleaning up these problems.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/whitespace.el.gz
;;;###autoload
(defun whitespace-report-region (start end &optional force report-if-bogus)
  "Report some whitespace problems in a region.

Return nil if there is no whitespace problem; otherwise, return
non-nil.

If FORCE is non-nil or \\[universal-argument] was pressed just
before calling `whitespace-report-region' interactively, it
forces all classes of whitespace problem to be considered
significant.

If REPORT-IF-BOGUS is t, it reports only when there are any
whitespace problems in buffer; if it is `never', it does not
report problems.

Report if some of the following whitespace problems exist:

* If `indent-tabs-mode' is non-nil:
   empty		1. empty lines at beginning of buffer.
   empty		2. empty lines at end of buffer.
   trailing		3. SPACEs or TABs at end of line.
   indentation		4. line starts with `tab-width' or more SPACEs.
   space-before-tab	5. SPACEs before TAB.
   space-after-tab	6. `tab-width' or more SPACEs after TAB.

* If `indent-tabs-mode' is nil:
   empty		1. empty lines at beginning of buffer.
   empty		2. empty lines at end of buffer.
   trailing		3. SPACEs or TABs at end of line.
   indentation		4. TABS at beginning of line.
   space-before-tab	5. SPACEs before TAB.
   space-after-tab	6. `tab-width' or more SPACEs after TAB.

See `whitespace-style' for documentation.
See also `whitespace-cleanup' and `whitespace-cleanup-region' for
cleaning up these problems."
  (interactive "r")
  (setq force (or current-prefix-arg force))
  (save-excursion
    (let* ((has-bogus nil)
           (rstart    (min start end))
           (rend      (max start end))
           ;; Fall back to whitespace-style so we can run before
           ;; before the mode is active.
           (style     (copy-sequence
                       (or whitespace-active-style whitespace-style)))
           (bogus-list
            (mapcar
             #'(lambda (option)
                 (when force
                   (push (car option) style))
                 (goto-char rstart)
                 (let ((regexp
                        (cond
                         ((eq (car option) 'indentation)
                          (whitespace-indentation-regexp))
                         ((eq (car option) 'indentation::tab)
                          (whitespace-indentation-regexp 'tab))
                         ((eq (car option) 'indentation::space)
                          (whitespace-indentation-regexp 'space))
                         ((eq (car option) 'space-after-tab)
                          (whitespace-space-after-tab-regexp))
                         ((eq (car option) 'space-after-tab::tab)
                          (whitespace-space-after-tab-regexp 'tab))
                         ((eq (car option) 'space-after-tab::space)
                          (whitespace-space-after-tab-regexp 'space))
                         ((eq (car option) 'missing-newline-at-eof)
                          "[^\n]\\'")
                         (t
                          (cdr option)))))
                   (when (re-search-forward regexp rend t)
                     (unless has-bogus
                       (setq has-bogus (memq (car option) style)))
                     t)))
             whitespace-report-list)))
      (when (pcase report-if-bogus ('nil t) ('never nil) (_ has-bogus))
        (whitespace-kill-buffer whitespace-report-buffer-name)
        ;; `indent-tabs-mode' may be local to current buffer
        ;; `tab-width' may be local to current buffer
        (let ((ws-indent-tabs-mode indent-tabs-mode)
              (ws-tab-width tab-width))
          (with-current-buffer (get-buffer-create
                                whitespace-report-buffer-name)
            (let ((inhibit-read-only t))
              (special-mode)
              (erase-buffer)
              (insert (if ws-indent-tabs-mode
                          (car whitespace-report-text)
                        (cdr whitespace-report-text)))
              (goto-char (point-min))
              (forward-line 3)
              (dolist (option whitespace-report-list)
                (forward-line 1)
                (whitespace-mark-x
                 27 (memq (car option) style))
                (whitespace-mark-x 7 (car bogus-list))
                (setq bogus-list (cdr bogus-list)))
              (forward-line 1)
              (whitespace-insert-value ws-indent-tabs-mode)
              (whitespace-insert-value ws-tab-width)
              (when has-bogus
                (goto-char (point-max))
                (insert (substitute-command-keys
                         " Type `\\[whitespace-cleanup]'")
                        " to cleanup the buffer.\n\n"
                        (substitute-command-keys
                         " Type `\\[whitespace-cleanup-region]'")
                        " to cleanup a region.\n\n"))
              (whitespace-display-window (current-buffer))))))
      has-bogus)))