;; show-controlchar-mode.el ;; ;; Copyleft 2001 Yoichiro Okabe ;; mailto:rakkyo@pc.highway.ne.jp ;; http://hp.vector.co.jp/authors/VA021626/ ;; ;; version 0.1 2001/03/09 first release ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of ;; the License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be ;; useful, but WITHOUT ANY WARRANTY; without even the implied ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. See the GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, ;; MA 02111-1307 USA ;; ;; (require 'poe) ; using apel::poe pop,push ;(defvar global-show-controlchar-mode nil "Non-nil means show-controlchar-mode is enabled globaly.") (defvar show-controlchar-mode nil "Non-nil means show-controlchar-mode is enabled.") (make-variable-buffer-local 'show-controlchar-mode) (if (not (assq 'show-controlchar-mode minor-mode-alist)) (setq minor-mode-alist (cons '(show-controlchar-mode " ^c") minor-mode-alist))) (defvar show-controlchar-ov nil "Internal use only.") (make-variable-buffer-local 'show-controlchar-ov) (defvar show-controlchar-last-window-start nil "Internal use only.") (make-variable-buffer-local 'show-controlchar-last-window-start) (defvar show-controlchar-last-window-end nil "Internal use only.") (make-variable-buffer-local 'show-controlchar-last-window-end) (defvar show-controlchar-highlight-chars (list 'eol 'widespace) "") (defface show-controlchar-eol-face '((t (:background "linen"))) "") (defface show-controlchar-tab-face '((t (:background "pink"))) "") (defface show-controlchar-widespace-face '((t (:background "yellow"))) "") (defconst show-controlchar-eol-char 10 "LF") (defconst show-controlchar-tab-char 9 "TAB") (defconst show-controlchar-widespace-char 53409 "wide space") (defun show-controlchar-mode (&optional arg) "Toggle show-controlchar mode. With arg, turn Visible Mark mode on iff arg is positive. When Visible Mark mode is enabled, the mark of EOL and marks of enter are visible." (interactive "P") (setq show-controlchar-mode (if (null arg) (not show-controlchar-mode) (> (prefix-numeric-value arg) 0))) ;;;(run-hooks 'show-controlchar-mode-hook) (if show-controlchar-mode (show-controlchar-mode-initialize) (show-controlchar-mode-uninitialize)) ) (defun show-controlchar-mode-initialize() "Initialize show-controlchar-mode." (make-local-hook 'post-command-hook) (add-hook 'post-command-hook 'show-controlchar-on-post-command t) ;(make-local-hook 'after-change-functions) ;(add-hook 'after-change-functions 'show-controlchar-on-buffer-change t) ;(make-local-hook 'window-scroll-functions) ;(add-hook 'window-scroll-functions 'show-controlchar-on-window-scroll t) (show-controlchar-mark-show) ) (defun show-controlchar-mode-uninitialize() "Initialize show-controlchar-mode." (show-controlchar-mark-hide) (remove-hook 'post-command-hook 'show-controlchar-on-post-command t) ;(remove-hook 'after-change-functions 'show-controlchar-on-buffer-change t) ;(remove-hook 'window-scroll-functions 'show-controlchar-on-window-scroll t) ) (defun show-controlchar-on-buffer-change (beg end old-len) "for after-change-functions hook" (and show-controlchar-mode (show-controlchar-mark-show)) ) (defun show-controlchar-on-window-scroll (win pos-start) "for window-scrolle-functions hook" (and show-controlchar-mode (show-controlchar-mark-show)) ) (defun show-controlchar-on-post-command () "Callback attached working." (and show-controlchar-mode (show-controlchar-mark-show))) (defun show-controlchar-mark-hide () "Hide marks." (let (ov) (while (setq ov (pop show-controlchar-ov)) (delete-overlay ov)) (setq show-controlchar-ov nil)) ) (defun show-controlchar-mark-show() "Show marks target window." (interactive) (let ((ws) (we) (buf (current-buffer)) (ov) (cur-char) (pos) (win) (windows (get-buffer-window-list (current-buffer) t 'visible) )) (show-controlchar-mark-hide) (while (setq win (car windows)) (setq ws (window-start win)) (setq we (window-end win t)) (save-excursion (setq pos ws) (while (> we pos) (setq cur-char (char-after pos)) (setq ov nil) (if (and (memq 'eol show-controlchar-highlight-chars) (eq show-controlchar-eol-char cur-char)) (progn (setq ov (make-overlay pos (1+ pos) buf nil nil)) (overlay-put ov 'face 'show-controlchar-eol-face) (overlay-put ov 'evaporate t) )) (if (and (memq 'tab show-controlchar-highlight-chars) (eq show-controlchar-tab-char cur-char)) (progn (setq ov (make-overlay pos (1+ pos) buf nil nil)) (overlay-put ov 'face 'show-controlchar-tab-face) (overlay-put ov 'evaporate t) )) (if (and (memq 'widespace show-controlchar-highlight-chars) (eq show-controlchar-widespace-char cur-char)) (progn (setq ov (make-overlay pos (1+ pos) buf nil nil)) (overlay-put ov 'face 'show-controlchar-widespace-face) (overlay-put ov 'evaporate t) )) (if (overlayp ov) (push ov show-controlchar-ov)) (setq pos (1+ pos)))) (setq windows (cdr windows)) ) ) ) (provide 'show-controlchar-mode)