1 ;;; visible-mark.el --- Make marks visible.
5 ;; This was hacked together by Jorgen Schäfer
6 ;; And hacked again by Yann Hodique
7 ;; Donated to the public domain. Use at your own risk.
10 ;; 2008-02-21 MATSUYAMA Tomohiro <t.matsuyama.pub@gmail.com>
12 ;; * visible-mark.el: Added function to inhibit trailing overlay.
14 ;; 2008-01-31 MATSUYAMA Tomohiro <t.matsuyama.pub@gmail.com>
16 ;; * visible-mark.el: Create formal emacs lisp file from
17 ;; http://www.emacswiki.org/cgi-bin/wiki/VisibleMark.
18 ;; Yann Hodique and Jorgen Schäfer are original authors.
19 ;; Added function to make multiple marks visible.
27 (defgroup visible-mark nil
28 "Show the position of your mark."
30 :prefix "visible-mark-")
32 (defface visible-mark-face
33 `((((type tty) (class color))
34 (:background "gray" :foreground "black"))
35 (((type tty) (class mono))
37 (((class color) (background dark))
38 (:background "gray" :foreground "black"))
39 (((class color) (background light))
40 (:background "grey80"))
41 (t (:background "gray")))
45 (defvar visible-mark-overlays nil
46 "The overlays used in this buffer.")
47 (make-variable-buffer-local 'visible-mark-overlays)
49 (defcustom visible-mark-inhibit-trailing-overlay t
50 "If non-nil, inhibit trailing overlay with underline face."
54 (defcustom visible-mark-max 1
55 "A number of mark to be visible."
59 (defcustom visible-mark-faces nil
60 "A list of mark faces."
64 (defcustom global-visible-mark-mode-exclude-alist nil
65 "A list of buffer names to be excluded"
67 :type '(repeat regexp))
69 (defun visible-mark-initialize-overlays ()
72 (when (eq 'visible-mark (overlay-get x 'category))
74 (overlays-in (point-min) (point-max)))
76 (dotimes (i visible-mark-max)
77 (let ((overlay (make-overlay (point-min) (point-min))))
78 (overlay-put overlay 'category 'visible-mark)
79 (push overlay overlays)))
80 (setq visible-mark-overlays (nreverse overlays))))
82 (defun visible-mark-find-overlay-at (pos)
83 (let ((overlays (overlays-at pos))
85 (while (and overlays (not found))
86 (let ((overlay (car overlays)))
87 (if (eq 'visible-mark (overlay-get overlay 'category))
88 (setq found overlay)))
89 (setq overlays (cdr overlays)))
92 (defun visible-mark-move-overlays ()
93 "Move the overlay in `visible-mark-overlay' to a new position."
94 (mapc (lambda (x) (move-overlay x 0 0))
95 visible-mark-overlays)
96 (let ((marks (cons (mark-marker) mark-ring))
97 (overlays visible-mark-overlays))
98 (dotimes (i visible-mark-max)
99 (let* ((mark (car-safe marks))
100 (overlay (car overlays))
101 (pos (and mark (marker-position mark))))
104 ((and visible-mark-inhibit-trailing-overlay
105 (save-excursion (goto-char pos) (eolp)))
106 (overlay-put overlay 'face nil)
107 (if (visible-mark-find-overlay-at pos)
108 (progn (overlay-put overlay 'before-string nil)
109 (move-overlay overlay 0 0))
110 (overlay-put overlay 'before-string
113 'face (or (nth i visible-mark-faces) 'visible-mark-face)
115 (move-overlay overlay pos (1+ pos))))
117 (overlay-put overlay 'before-string nil)
118 (overlay-put overlay 'face
119 (or (nth i visible-mark-faces) 'visible-mark-face))
120 (move-overlay overlay pos (1+ pos)))))
121 (setq marks (cdr marks)))
122 (setq overlays (cdr overlays)))))
124 (require 'easy-mmode)
126 (defun visible-mark-mode-maybe ()
128 ((minibufferp (current-buffer)) nil)
131 (or (string-match (car arg) (buffer-name))
133 (fun global-visible-mark-mode-exclude-alist)) nil)
135 (visible-mark-mode t)))
137 (define-minor-mode visible-mark-mode
138 "A mode to make the mark visible."
141 (if visible-mark-mode
143 (visible-mark-initialize-overlays)
144 (add-hook 'post-command-hook 'visible-mark-move-overlays nil t))
145 (mapc 'delete-overlay visible-mark-overlays)
146 (setq visible-mark-overlays nil)
147 (remove-hook 'post-command-hook 'visible-mark-move-overlays t)))
149 (define-global-minor-mode
150 global-visible-mark-mode visible-mark-mode visible-mark-mode-maybe
151 :group 'visible-mark)
153 (provide 'visible-mark)
154 ;;; visible-mark.el ends here