Mercurial > emacs
comparison lisp/whitespace.el @ 90650:02cf29720f31
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 490-504)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 161-163)
- Update from CVS
- Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-130
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 07 Nov 2006 23:22:48 +0000 |
parents | 6823a91487f2 75af8d959739 |
children | f1d13e615070 |
comparison
equal
deleted
inserted
replaced
90649:d53934e7ddef | 90650:02cf29720f31 |
---|---|
192 `whitespace-check-buffer-spacetab'." | 192 `whitespace-check-buffer-spacetab'." |
193 :type 'boolean | 193 :type 'boolean |
194 :group 'whitespace) | 194 :group 'whitespace) |
195 | 195 |
196 (defcustom whitespace-spacetab-regexp "[ ]+\t" | 196 (defcustom whitespace-spacetab-regexp "[ ]+\t" |
197 "Regexp to match a space followed by a TAB." | 197 "Regexp to match one or more spaces followed by a TAB." |
198 :type 'regexp | 198 :type 'regexp |
199 :group 'whitespace) | 199 :group 'whitespace) |
200 | 200 |
201 (defcustom whitespace-check-indent-whitespace indent-tabs-mode | 201 (defcustom whitespace-check-indent-whitespace indent-tabs-mode |
202 "Flag to check indentation whitespace. This is the global for the system. | 202 "Flag to check indentation whitespace. This is the global for the system. |
203 It can be overriden by setting a buffer local variable | 203 It can be overriden by setting a buffer local variable |
204 `whitespace-check-buffer-indent'." | 204 `whitespace-check-buffer-indent'." |
205 :type 'boolean | 205 :type 'boolean |
206 :group 'whitespace) | 206 :group 'whitespace) |
207 | 207 |
208 (defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ") | 208 (defcustom whitespace-indent-regexp "^\t*\\( \\)+" |
209 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line." | 209 "Regexp to match multiples of eight spaces near line beginnings. |
210 The default value ignores leading TABs." | |
210 :type 'regexp | 211 :type 'regexp |
211 :group 'whitespace) | 212 :group 'whitespace) |
212 | 213 |
213 (defcustom whitespace-check-ateol-whitespace t | 214 (defcustom whitespace-check-ateol-whitespace t |
214 "Flag to check end-of-line whitespace. This is the global for the system. | 215 "Flag to check end-of-line whitespace. This is the global for the system. |
215 It can be overriden by setting a buffer local variable | 216 It can be overriden by setting a buffer local variable |
216 `whitespace-check-buffer-ateol'." | 217 `whitespace-check-buffer-ateol'." |
217 :type 'boolean | 218 :type 'boolean |
218 :group 'whitespace) | 219 :group 'whitespace) |
219 | 220 |
220 ;; (defcustom whitespace-ateol-regexp "[ \t]$" | |
221 (defcustom whitespace-ateol-regexp "[ \t]+$" | 221 (defcustom whitespace-ateol-regexp "[ \t]+$" |
222 "Regexp to match a TAB or a space at the EOL." | 222 "Regexp to match one or more TABs or spaces at line ends." |
223 :type 'regexp | 223 :type 'regexp |
224 :group 'whitespace) | 224 :group 'whitespace) |
225 | 225 |
226 (defcustom whitespace-errbuf "*Whitespace Errors*" | 226 (defcustom whitespace-errbuf "*Whitespace Errors*" |
227 "The name of the buffer where whitespace related messages will be logged." | 227 "The name of the buffer where whitespace related messages will be logged." |
423 (whitespace-check-whitespace-mode current-prefix-arg) | 423 (whitespace-check-whitespace-mode current-prefix-arg) |
424 (if (and buffer-file-name (> (buffer-size) 0) whitespace-mode) | 424 (if (and buffer-file-name (> (buffer-size) 0) whitespace-mode) |
425 (progn | 425 (progn |
426 (whitespace-check-buffer-list (buffer-name) buffer-file-name) | 426 (whitespace-check-buffer-list (buffer-name) buffer-file-name) |
427 (whitespace-tickle-timer) | 427 (whitespace-tickle-timer) |
428 (whitespace-unhighlight-the-space) | 428 (overlay-recenter (point-max)) |
429 (remove-overlays nil nil 'face 'whitespace-highlight) | |
429 (if whitespace-auto-cleanup | 430 (if whitespace-auto-cleanup |
430 (if buffer-read-only | 431 (if buffer-read-only |
431 (if (not quiet) | 432 (if (not quiet) |
432 (message "Can't cleanup: %s is read-only" (buffer-name))) | 433 (message "Can't cleanup: %s is read-only" (buffer-name))) |
433 (whitespace-cleanup-internal)) | 434 (whitespace-cleanup-internal)) |
589 (narrow-to-region s e) | 590 (narrow-to-region s e) |
590 (whitespace-cleanup-internal t)) | 591 (whitespace-cleanup-internal t)) |
591 (whitespace-buffer t))) | 592 (whitespace-buffer t))) |
592 | 593 |
593 (defun whitespace-buffer-leading () | 594 (defun whitespace-buffer-leading () |
594 "Check to see if there are any empty lines at the top of the file." | 595 "Return t if the current buffer has leading newline characters. |
596 If highlighting is enabled, highlight these characters." | |
595 (save-excursion | 597 (save-excursion |
596 (let ((pmin nil) | 598 (goto-char (point-min)) |
597 (pmax nil)) | 599 (skip-chars-forward "\n") |
598 (goto-char (point-min)) | 600 (unless (bobp) |
599 (beginning-of-line) | 601 (whitespace-highlight-the-space (point-min) (point)) |
600 (setq pmin (point)) | 602 t))) |
601 (end-of-line) | |
602 (setq pmax (point)) | |
603 (if (equal pmin pmax) | |
604 (progn | |
605 (whitespace-highlight-the-space pmin (1+ pmax)) | |
606 t) | |
607 nil)))) | |
608 | 603 |
609 (defun whitespace-buffer-leading-cleanup () | 604 (defun whitespace-buffer-leading-cleanup () |
610 "Remove any empty lines at the top of the file." | 605 "Remove any leading newline characters from current buffer." |
611 (save-excursion | 606 (save-excursion |
612 (goto-char (point-min)) | 607 (goto-char (point-min)) |
613 (skip-chars-forward "\n") | 608 (skip-chars-forward "\n") |
614 (delete-region (point-min) (point)))) | 609 (delete-region (point-min) (point)))) |
615 | 610 |
616 (defun whitespace-buffer-trailing () | 611 (defun whitespace-buffer-trailing () |
617 "Check to see if are is more than one empty line at the bottom." | 612 "Return t if the current buffer has extra trailing newline characters. |
618 (save-excursion | 613 If highlighting is enabled, highlight these characters." |
619 (let ((pmin nil) | |
620 (pmax nil)) | |
621 (goto-char (point-max)) | |
622 (beginning-of-line) | |
623 (setq pmin (point)) | |
624 (end-of-line) | |
625 (setq pmax (point)) | |
626 (if (equal pmin pmax) | |
627 (progn | |
628 (goto-char (- (point) 1)) | |
629 (beginning-of-line) | |
630 (setq pmin (point)) | |
631 (end-of-line) | |
632 (setq pmax (point)) | |
633 (if (equal pmin pmax) | |
634 (progn | |
635 (whitespace-highlight-the-space (- pmin 1) pmax) | |
636 t) | |
637 nil)) | |
638 nil)))) | |
639 | |
640 (defun whitespace-buffer-trailing-cleanup () | |
641 "Delete all the empty lines at the bottom." | |
642 (save-excursion | 614 (save-excursion |
643 (goto-char (point-max)) | 615 (goto-char (point-max)) |
644 (skip-chars-backward "\n") | 616 (skip-chars-backward "\n") |
645 (if (not (bolp)) | 617 (forward-line) |
646 (forward-char 1)) | 618 (unless (eobp) |
647 (delete-region (point) (point-max)))) | 619 (whitespace-highlight-the-space (point) (point-max)) |
620 t))) | |
621 | |
622 (defun whitespace-buffer-trailing-cleanup () | |
623 "Remove extra trailing newline characters from current buffer." | |
624 (save-excursion | |
625 (goto-char (point-max)) | |
626 (skip-chars-backward "\n") | |
627 (unless (eobp) | |
628 (forward-line) | |
629 (delete-region (point) (point-max))))) | |
648 | 630 |
649 (defun whitespace-buffer-search (regexp) | 631 (defun whitespace-buffer-search (regexp) |
650 "Search for any given whitespace REGEXP." | 632 "Search for any given whitespace REGEXP." |
651 (let ((whitespace-retval "")) | 633 (with-local-quit |
652 (save-excursion | 634 (let (whitespace-retval) |
653 (goto-char (point-min)) | 635 (save-excursion |
654 (while (re-search-forward regexp nil t) | 636 (goto-char (point-min)) |
655 (progn | 637 (while (re-search-forward regexp nil t) |
656 (setq whitespace-retval (format "%s %s" whitespace-retval | 638 (whitespace-highlight-the-space (match-beginning 0) (match-end 0)) |
657 (match-beginning 0))) | 639 (push (match-beginning 0) whitespace-retval))) |
658 (whitespace-highlight-the-space (match-beginning 0) (match-end 0)))) | 640 (when whitespace-retval |
659 (if (equal "" whitespace-retval) | 641 (format " %s" (nreverse whitespace-retval)))))) |
660 nil | |
661 whitespace-retval)))) | |
662 | 642 |
663 (defun whitespace-buffer-cleanup (regexp newregexp) | 643 (defun whitespace-buffer-cleanup (regexp newregexp) |
664 "Search for any given whitespace REGEXP and replace it with the NEWREGEXP." | 644 "Search for any given whitespace REGEXP and replace it with the NEWREGEXP." |
665 (save-excursion | 645 (save-excursion |
666 (goto-char (point-min)) | 646 (goto-char (point-min)) |
711 | 691 |
712 (defun whitespace-highlight-the-space (b e) | 692 (defun whitespace-highlight-the-space (b e) |
713 "Highlight the current line, unhighlighting a previously jumped to line." | 693 "Highlight the current line, unhighlighting a previously jumped to line." |
714 (if whitespace-display-spaces-in-color | 694 (if whitespace-display-spaces-in-color |
715 (let ((ol (whitespace-make-overlay b e))) | 695 (let ((ol (whitespace-make-overlay b e))) |
716 (push ol whitespace-highlighted-space) | |
717 (whitespace-overlay-put ol 'face 'whitespace-highlight)))) | 696 (whitespace-overlay-put ol 'face 'whitespace-highlight)))) |
718 ;; (add-hook 'pre-command-hook 'whitespace-unhighlight-the-space)) | |
719 | 697 |
720 (defun whitespace-unhighlight-the-space() | 698 (defun whitespace-unhighlight-the-space() |
721 "Unhighlight the currently highlight line." | 699 "Unhighlight the currently highlight line." |
722 (if (and whitespace-display-spaces-in-color whitespace-highlighted-space) | 700 (if (and whitespace-display-spaces-in-color whitespace-highlighted-space) |
723 (progn | 701 (progn |
724 (mapc 'whitespace-delete-overlay whitespace-highlighted-space) | 702 (mapc 'whitespace-delete-overlay whitespace-highlighted-space) |
725 (setq whitespace-highlighted-space nil)) | 703 (setq whitespace-highlighted-space nil)))) |
726 (remove-hook 'pre-command-hook 'whitespace-unhighlight-the-space))) | |
727 | 704 |
728 (defun whitespace-check-buffer-list (buf-name buf-file) | 705 (defun whitespace-check-buffer-list (buf-name buf-file) |
729 "Add a buffer and its file to the whitespace monitor list. | 706 "Add a buffer and its file to the whitespace monitor list. |
730 | 707 |
731 The buffer named BUF-NAME and its associated file BUF-FILE are now monitored | 708 The buffer named BUF-NAME and its associated file BUF-FILE are now monitored |
778 (whitespace-refresh-rescan-list buffile bufname))) | 755 (whitespace-refresh-rescan-list buffile bufname))) |
779 ;;(message "Removing %s from refresh list" bufname) | 756 ;;(message "Removing %s from refresh list" bufname) |
780 (whitespace-refresh-rescan-list buffile bufname)))))) | 757 (whitespace-refresh-rescan-list buffile bufname)))))) |
781 | 758 |
782 (defun whitespace-refresh-rescan-list (buffile bufname) | 759 (defun whitespace-refresh-rescan-list (buffile bufname) |
783 "Refresh the list of files to be rescaned for whitespace creep." | 760 "Refresh the list of files to be rescanned for whitespace creep." |
784 (if whitespace-all-buffer-files | 761 (if whitespace-all-buffer-files |
785 (setq whitespace-all-buffer-files | 762 (setq whitespace-all-buffer-files |
786 (delete (list buffile bufname) whitespace-all-buffer-files)) | 763 (delete (list buffile bufname) whitespace-all-buffer-files)) |
787 (when whitespace-rescan-timer | 764 (when whitespace-rescan-timer |
788 (disable-timeout whitespace-rescan-timer) | 765 (disable-timeout whitespace-rescan-timer) |