comparison lisp/whitespace.el @ 61395:21f8452c722e

(whitespace-highlight-the-space): Put the same overlay in the buffer and in whitespace-highlighted-space. (whitespace-unhighlight-the-space): Simplify. (whitespace-buffer): Simplify.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 08 Apr 2005 14:40:57 +0000
parents 31aa9a390538
children c85ac0c1b8e9 9deb6323655c 02f1dbc4a199
comparison
equal deleted inserted replaced
61394:31aa9a390538 61395:21f8452c722e
487 (if whitespace-indent "i") 487 (if whitespace-indent "i")
488 (if whitespace-leading "l") 488 (if whitespace-leading "l")
489 (if whitespace-spacetab "s") 489 (if whitespace-spacetab "s")
490 (if whitespace-trailing "t"))))) 490 (if whitespace-trailing "t")))))
491 (whitespace-update-modeline whitespace-this-modeline) 491 (whitespace-update-modeline whitespace-this-modeline)
492 (save-excursion 492 (if (get-buffer whitespace-errbuf)
493 (get-buffer-create whitespace-errbuf) 493 (kill-buffer whitespace-errbuf))
494 (kill-buffer whitespace-errbuf) 494 (with-current-buffer (get-buffer-create whitespace-errbuf)
495 (get-buffer-create whitespace-errbuf)
496 (set-buffer whitespace-errbuf)
497 (if whitespace-errmsg 495 (if whitespace-errmsg
498 (progn 496 (progn
499 (insert whitespace-errmsg) 497 (insert whitespace-errmsg)
500 (if (not (or quiet whitespace-silent)) 498 (if (not (or quiet whitespace-silent))
501 (display-buffer whitespace-errbuf t)) 499 (display-buffer (current-buffer) t))
502 (if (not quiet) 500 (if (not quiet)
503 (message "Whitespaces: [%s%s] in %s" 501 (message "Whitespaces: [%s%s] in %s"
504 whitespace-this-modeline 502 whitespace-this-modeline
505 (let ((whitespace-unchecked 503 (let ((whitespace-unchecked
506 (whitespace-unchecked-whitespaces))) 504 (whitespace-unchecked-whitespaces)))
509 "")) 507 ""))
510 whitespace-filename))) 508 whitespace-filename)))
511 (if (and (not quiet) (not (equal whitespace-clean-msg ""))) 509 (if (and (not quiet) (not (equal whitespace-clean-msg "")))
512 (message "%s %s" whitespace-filename 510 (message "%s %s" whitespace-filename
513 whitespace-clean-msg)))))))) 511 whitespace-clean-msg))))))))
514 (if whitespace-error 512 whitespace-error))
515 t
516 nil)))
517 513
518 ;;;###autoload 514 ;;;###autoload
519 (defun whitespace-region (s e) 515 (defun whitespace-region (s e)
520 "Check the region for whitespace errors." 516 "Check the region for whitespace errors."
521 (interactive "r") 517 (interactive "r")
734 (whitespace-mode-line-update)))) 730 (whitespace-mode-line-update))))
735 731
736 (defun whitespace-highlight-the-space (b e) 732 (defun whitespace-highlight-the-space (b e)
737 "Highlight the current line, unhighlighting a previously jumped to line." 733 "Highlight the current line, unhighlighting a previously jumped to line."
738 (if whitespace-display-spaces-in-color 734 (if whitespace-display-spaces-in-color
739 (progn 735 (let ((ol (whitespace-make-overlay b e)))
740 (whitespace-unhighlight-the-space) 736 (whitespace-unhighlight-the-space)
741 (add-to-list 'whitespace-highlighted-space 737 (push ol whitespace-highlighted-space)
742 (whitespace-make-overlay b e)) 738 (whitespace-overlay-put ol 'face 'whitespace-highlight-face))))
743 (whitespace-overlay-put (whitespace-make-overlay b e) 'face
744 'whitespace-highlight-face))))
745 ;; (add-hook 'pre-command-hook 'whitespace-unhighlight-the-space)) 739 ;; (add-hook 'pre-command-hook 'whitespace-unhighlight-the-space))
746 740
747 (defun whitespace-unhighlight-the-space () 741 (defun whitespace-unhighlight-the-space ()
748 "Unhighlight the currently highlight line." 742 "Unhighlight the currently highlight line."
749 (if (and whitespace-display-spaces-in-color whitespace-highlighted-space) 743 (if (and whitespace-display-spaces-in-color whitespace-highlighted-space)
750 (let ((whitespace-this-space nil)) 744 (progn
751 (while whitespace-highlighted-space 745 (mapc 'whitespace-delete-overlay whitespace-highlighted-space)
752 (setq whitespace-this-space (car whitespace-highlighted-space))
753 (setq whitespace-highlighted-space
754 (cdr whitespace-highlighted-space))
755 (whitespace-delete-overlay whitespace-this-space))
756 (setq whitespace-highlighted-space nil)) 746 (setq whitespace-highlighted-space nil))
757 (remove-hook 'pre-command-hook 'whitespace-unhighlight-the-space))) 747 (remove-hook 'pre-command-hook 'whitespace-unhighlight-the-space)))
758 748
759 (defun whitespace-check-buffer-list (buf-name buf-file) 749 (defun whitespace-check-buffer-list (buf-name buf-file)
760 "Add a buffer and its file to the whitespace monitor list. 750 "Add a buffer and its file to the whitespace monitor list.
861 851
862 (add-hook 'whitespace-unload-hook 'whitespace-unload-hook) 852 (add-hook 'whitespace-unload-hook 'whitespace-unload-hook)
863 853
864 (provide 'whitespace) 854 (provide 'whitespace)
865 855
866 ;;; arch-tag: 4ff44e87-b63c-402d-95a6-15e51e58bd0c 856 ;; arch-tag: 4ff44e87-b63c-402d-95a6-15e51e58bd0c
867 ;;; whitespace.el ends here 857 ;;; whitespace.el ends here