1 ;;; minimap.el --- Sidebar showing a "mini-map" of a buffer
3 ;; Copyright (C) 2009-2014 Free Software Foundation, Inc.
5 ;; Author: David Engster <deng@randomsample.de>
9 ;; This file is part of GNU Emacs.
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License
13 ;; as published by the Free Software Foundation; either version 2
14 ;; of the License, or (at your option) any later version.
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
26 ;; This file is an implementation of a minimap sidebar, i.e., a
27 ;; smaller display of the current buffer on the left side. It
28 ;; highlights the currently shown region and updates its position
29 ;; automatically. You can navigate in the minibar by dragging the
30 ;; active region with the mouse, which will scroll the corresponding
31 ;; edit buffer. Additionally, you can overlay information from the
32 ;; tags gathered by CEDET's semantic analyzer.
34 ;; Simply use M-x minimap-mode to toggle activation of the minimap.
35 ;; Use 'M-x customize-group RET minimap RET' to adapt minimap to your
40 ;; * Currently cannot deal with images.
41 ;; * Display/movement can be a bit erratic at times.
46 ;; * Make sidebar permanently visible. This requires something like a
47 ;; 'window group' feature in Emacs, which is currently being worked on.
48 ;; * Moving the active region with the keyboard / mouse-wheel ?
53 ;;;; Changes since v1.0:
55 ;; - Largely rewritten as a minor mode; use M-x minimap-mode to
57 ;; - Minimap will now remain active for all buffers which derive from
58 ;; `prog-mode' (can be changed through `minimap-major-modes'). The
59 ;; minimap window will be automatically created or deleted (see new
60 ;; variables `minimap-recreate-window' and
61 ;; `minimap-automatically-delete-window').
62 ;; - Possibility to set a minimum width of the minimap window
63 ;; (`minimap-minimum-width').
64 ;; - Minimap window will be marked so that you should not be able to
66 ;; - Semantic overlays will be automatically updated during editing.
67 ;; - Lots of bug fixes.
69 ;;; Customizable variables:
72 "A minimap sidebar for Emacs."
75 (defface minimap-font-face
76 '((default :family "DejaVu Sans Mono" :height 30))
77 "Face used for text in minimap buffer, notably the font family and height.
78 This height should be really small. You probably want to use a
79 TrueType font for this. After changing this, you should
80 recreate the minimap to avoid problems with recentering."
83 (defface minimap-active-region-background
84 '((((background dark)) (:background "#4517305D0000"))
85 (t (:background "#C847D8FEFFFF")))
86 "Face for the active region in the minimap.
87 By default, this is only a different background color."
90 (defface minimap-semantic-function-face
91 '((((background dark))
92 (:box (:line-width 1 :color "white")
93 :inherit (font-lock-function-name-face minimap-font-face)
94 :height 2.75 :background "gray10"))
95 (t (:box (:line-width 1 :color "black")
96 :inherit (font-lock-function-name-face minimap-font-face)
97 :height 2.75 :background "gray90")))
98 "Face used for functions in the semantic overlay.")
100 (defface minimap-semantic-variable-face
101 '((((background dark))
102 (:box (:line-width 1 :color "white")
103 :inherit (font-lock-variable-name-face minimap-font-face)
104 :height 2.75 :background "gray10"))
105 (t (:box (:line-width 1 :color "black")
106 :inherit (font-lock-function-name-face minimap-font-face)
107 :height 2.75 :background "gray90")))
108 "Face used for variables in the semantic overlay.")
110 (defface minimap-semantic-type-face
111 '((((background dark))
112 (:box (:line-width 1 :color "white")
113 :inherit (font-lock-type-face minimap-font-face)
114 :height 2.75 :background "gray10"))
115 (t (:box (:line-width 1 :color "black")
116 :inherit (font-lock-function-name-face minimap-font-face)
117 :height 2.75 :background "gray90")))
118 "Face used for types in the semantic overlay.")
120 (defcustom minimap-width-fraction 0.15
121 "Fraction of width which should be used for minimap sidebar."
125 (defcustom minimap-minimum-width 30
126 "Minimum width of minimap in characters (default size).
131 (defcustom minimap-window-location 'left
132 "Location of the minimap window.
133 Can be either the symbol `left' or `right'."
134 :type '(choice (const :tag "Left" left)
135 (const :tag "Right" right))
138 (defcustom minimap-buffer-name " *MINIMAP*"
139 "Buffer name of minimap sidebar."
143 (defcustom minimap-update-delay 0.2
144 "Delay in seconds after which sidebar gets updated.
145 Setting this to 0 will let the minimap react immediately, but
146 this will slow down scrolling."
148 :set (lambda (sym value)
150 (when (and (boundp 'minimap-timer-object)
151 minimap-timer-object)
152 (cancel-timer minimap-timer-object)
153 (setq minimap-timer-object
155 minimap-update-delay t 'minimap-update))))
158 (defcustom minimap-always-recenter nil
159 "Whether minimap sidebar should be recentered after every point movement."
163 (defcustom minimap-recenter-type 'relative
164 "Specifies the type of recentering the minimap should use.
165 The minimap can use different types of recentering, i.e., how the
166 minimap should behave when you scroll in the main window or when
167 you drag the active region with the mouse. The following
168 explanations will probably not help much, so simply try them and
169 choose the one which suits you best.
171 `relative' -- The position of the active region in the minimap
172 corresponds with the relative position of this region in the
173 buffer. This the default.
175 `middle' -- The active region will stay fixed in the middle of
178 `free' -- The position will be more or less free. When dragging
179 the active region, the minimap will scroll when you reach the
181 :type '(choice (const :tag "Relative" relative)
182 (const :tag "Middle" middle)
183 (const :tag "Free" free))
186 (defcustom minimap-hide-scroll-bar t
187 "Whether the minimap should hide the vertical scrollbar."
191 (defcustom minimap-hide-fringes nil
192 "Whether the minimap should hide the fringes."
196 (defcustom minimap-dedicated-window t
197 "Whether the minimap should create a dedicated window."
201 (defcustom minimap-display-semantic-overlays t
202 "Display overlays from CEDET's semantic analyzer.
203 If you use CEDET and the buffer's major-mode is supported, the
204 minimap can display overlays generated by the semantic analyzer.
205 By default, it will apply the faces `minimap-semantic-<X>-face',
206 with <X> being \"function\", \"variable\" and \"type\". Also, it
207 will display the name of the tag in the middle of the overlay in
208 the corresponding font-lock face.
210 See also `minimap-enlarge-certain-faces', which can be used as
215 (defcustom minimap-enlarge-certain-faces 'as-fallback
216 "Whether certain faces should be enlarged in the minimap.
217 All faces listed in `minimap-normal-height-faces' will be
218 displayed using the default font height, allowing you to still
219 read text using those faces. By default, this should enlarge all
220 function names in the minimap, given you have font locking
221 enabled. This variable can have the following values:
223 'as-fallback (the default) -- The feature will only be activated
224 if information from CEDET's semantic analyzer isn't available
225 (see: `minimap-display-semantic-overlays').
226 'always -- Always active.
228 :type '(choice (const :tag "Fallback if CEDET unavailable." 'as-fallback)
229 (const :tag "Always active." 'always)
230 (const :tag "Inactive." nil))
233 (defcustom minimap-normal-height-faces '(font-lock-function-name-face)
234 "List of faces which should be displayed with normal height.
235 When `minimap-enlarge-certain-faces' is non-nil, all faces in
236 this list will be displayed using the default font height. By
237 default, this list contains `font-lock-function-name-face', so
238 you can still read function names in the minimap."
242 (defcustom minimap-sync-overlay-properties '(face invisible)
243 "Specifies which overlay properties should be synced.
244 Unlike text properties, overlays are not applied automatically to
245 the minimap and must be explicitly synced. This variable
246 specifies which overlay properties should be synced by
247 `minimap-sync-overlays'. Most importantly, this variable should
248 include 'invisible', so that hidden text does not appear in the
250 :type '(repeat symbol)
253 (defcustom minimap-major-modes '(prog-mode)
254 "Major modes for which a minimap should be created.
255 This can also be a parent mode like 'prog-mode.
256 If nil, a minimap must be explicitly created for each buffer."
257 :type '(repeat symbol)
260 (defcustom minimap-recreate-window t
261 "Whether the minimap window should be automatically re-created.
262 If this is non-nil, the side window for the minimap will be
263 automatically re-created as soon as you kill it."
267 (defcustom minimap-automatically-delete-window t
268 "Whether the minimap window should be automatically deleted.
269 Setting this to non-nil will delete the minibuffer side window
270 when you enter a buffer which is not derived from
271 `minimap-major-modes' (excluding the minibuffer)."
275 ;;; Internal variables
277 ;; The buffer currently displayed in the minimap
278 (defvar minimap-active-buffer nil)
279 ;; Window start/end from the base buffer
280 (defvar minimap-start nil)
281 (defvar minimap-end nil)
282 ;; General overlay for the minimap
283 (defvar minimap-base-overlay nil)
284 ;; Overlay for the active region
285 (defvar minimap-active-overlay nil)
287 (defvar minimap-timer-object nil)
288 ;; Lines the minimap can display
289 (defvar minimap-numlines nil)
290 (defvar minimap-pointmin-overlay nil)
294 (defun minimap-active-current-buffer-p ()
295 "Whether the current buffer is displayed in the minimap."
296 (and (eq (current-buffer) minimap-active-buffer)
297 (get-buffer minimap-buffer-name)
298 (with-current-buffer minimap-buffer-name
299 (eq minimap-active-buffer (buffer-base-buffer)))))
301 (defsubst minimap-get-window ()
302 "Get current minimap window."
303 (when (get-buffer minimap-buffer-name)
304 (get-buffer-window minimap-buffer-name)))
306 (defsubst minimap-kill-buffer ()
307 "Kill the minimap buffer."
308 (when (get-buffer minimap-buffer-name)
309 (kill-buffer minimap-buffer-name)))
311 (defun minimap-create-window ()
312 (let ((width (round (* (window-width)
313 minimap-width-fraction))))
314 (when (< width minimap-minimum-width)
315 (setq width minimap-minimum-width))
316 (if (eq minimap-window-location 'left)
317 (split-window-horizontally width)
318 (split-window-horizontally
321 ;; Set up the minimap window:
322 ;; You should not be able to enter the minimap window.
323 (set-window-parameter nil 'no-other-window t)
325 (when minimap-hide-scroll-bar
326 (setq vertical-scroll-bar nil))
327 (when minimap-hide-fringes
328 (set-window-fringes nil 0 0))
331 (get-buffer-create minimap-buffer-name) t t)
332 ;; Do not fold lines in the minimap.
333 (setq truncate-lines t)
334 ;; Make it dedicated.
335 (when minimap-dedicated-window
336 (set-window-dedicated-p nil t))
341 (defun minimap-setup-hooks (&optional remove)
342 "Hook minimap into other modes.
343 If REMOVE is non-nil, remove minimap from other modes."
346 (remove-hook 'outline-view-change-hook 'minimap-sync-overlays)
347 (remove-hook 'hs-hide-hook 'minimap-sync-overlays)
348 (remove-hook 'hs-show-hook 'minimap-sync-overlays))
349 ;; outline-(minor-)mode
350 (add-hook 'outline-view-change-hook 'minimap-sync-overlays)
352 (add-hook 'hs-hide-hook 'minimap-sync-overlays)
353 (add-hook 'hs-show-hook 'minimap-sync-overlays)))
355 ;;; Minimap creation / killing
357 (define-minor-mode minimap-mode
358 "Toggle minimap mode."
364 (when (and minimap-major-modes
365 (apply 'derived-mode-p minimap-major-modes))
366 (unless (minimap-get-window)
367 (minimap-create-window))
369 (minimap-new-minimap))
371 (setq minimap-timer-object
372 (run-with-idle-timer minimap-update-delay t 'minimap-update))
373 ;; Hook into other modes.
374 (minimap-setup-hooks))
377 (minimap-setup-hooks t)))
380 (defun minimap-create ()
381 "Create a minimap sidebar."
385 (defun minimap-new-minimap ()
386 "Create new minimap BUFNAME for current buffer and window.
387 Re-use already existing minimap window if possible."
389 (let ((currentbuffer (current-buffer))
390 (win (minimap-get-window))
391 (indbuf (make-indirect-buffer (current-buffer)
392 (concat minimap-buffer-name "_temp")))
393 (edges (window-pixel-edges)))
394 ;; Remember the active buffer currently displayed in the minimap.
395 (setq minimap-active-buffer (current-buffer))
396 ;; Hook into CEDET if necessary.
397 (when (and minimap-display-semantic-overlays
398 (boundp 'semantic-after-toplevel-cache-change-hook))
399 (add-hook 'semantic-after-partial-cache-change-hook
400 'minimap-apply-semantic-overlays nil t)
401 (add-hook 'semantic-after-toplevel-cache-change-hook
402 'minimap-apply-semantic-overlays nil t))
403 (with-selected-window win
404 ;; Now set up the minimap:
405 (when (window-dedicated-p)
406 (set-window-dedicated-p nil nil))
407 (switch-to-buffer indbuf t t)
408 (minimap-kill-buffer)
409 (rename-buffer minimap-buffer-name)
410 ;; Do not fold lines in the minimap.
411 (setq truncate-lines t)
412 (when minimap-dedicated-window
413 (set-window-dedicated-p nil t))
414 (setq minimap-base-overlay (make-overlay (point-min) (point-max) nil t t))
415 (overlay-put minimap-base-overlay 'face 'minimap-font-face)
416 (overlay-put minimap-base-overlay 'priority 1)
417 (setq minimap-pointmin-overlay (make-overlay (point-min) (1+ (point-min))))
418 (setq minimap-start (window-start)
419 minimap-end (window-end)
420 minimap-active-overlay (make-overlay minimap-start minimap-end)
422 (overlay-put minimap-active-overlay 'face
423 'minimap-active-region-background)
424 (overlay-put minimap-active-overlay 'priority 5)
426 (when (and (boundp 'linum-mode)
429 (setq buffer-read-only t)
430 ;; Calculate the actual number of lines displayable with the minimap face.
431 (setq minimap-numlines
434 (- (nth 3 edges) (nth 1 edges))
435 (car (progn (redisplay t) (window-line-height)))))))
436 (minimap-sync-overlays)))
439 (defun minimap-kill ()
442 (when (minimap-get-window)
443 (delete-window (minimap-get-window)))
444 (cancel-timer minimap-timer-object))
448 (defun minimap-update (&optional force)
449 "Update minimap sidebar if necessary.
450 This is meant to be called from the idle-timer or the post command hook.
451 When FORCE, enforce update of the active region."
453 ;; If we are in the minibuffer, do nothing.
454 (unless (active-minibuffer-window)
455 (if (minimap-active-current-buffer-p)
456 ;; We are still in the same buffer, so just update the minimap.
457 (let ((win (minimap-get-window))
458 (start (window-start))
461 (when (and (null win)
462 minimap-recreate-window)
463 ;; The minimap window is no longer visible, so create it again...
464 (setq win (minimap-create-window))
465 ;; ...and switch to existing minimap buffer.
466 (with-selected-window win
467 (when (window-dedicated-p)
468 (set-window-dedicated-p nil nil))
469 (switch-to-buffer minimap-buffer-name t t)
470 (when minimap-dedicated-window
471 (set-window-dedicated-p nil t))))
472 (with-selected-window win
473 ;; Make sure the base overlay spans the whole buffer.
474 (unless (and (= (overlay-start minimap-base-overlay) (point-min))
475 (= (overlay-end minimap-base-overlay) (point-max)))
476 (move-overlay minimap-base-overlay (point-min) (point-max)))
477 (unless (and (not force)
478 (= minimap-start start)
480 ;; Update the overlay.
481 (move-overlay minimap-active-overlay start end)
482 (setq minimap-start start
484 (minimap-recenter (line-number-at-pos (/ (+ end start) 2))
485 (/ (- (line-number-at-pos end)
486 (line-number-at-pos start))
489 (when minimap-always-recenter
490 (recenter (round (/ (window-height) 2)))))
493 ;; The buffer was switched, check if the minimap should switch, too.
494 (if (and minimap-major-modes
495 (apply 'derived-mode-p minimap-major-modes))
497 ;; Create window if necessary...
498 (unless (minimap-get-window)
499 (minimap-create-window))
500 ;; ...and re-create minimap with new buffer...
501 (minimap-new-minimap)
504 ;; ...and call update again.
506 ;; Otherwise, delete window if the user so wishes.
507 (when (and (minimap-get-window)
508 minimap-automatically-delete-window)
509 ;; We wait a tiny bit before deleting the window, since we
510 ;; might only be temporarily in another buffer.
511 (run-with-timer 0.3 nil
513 (when (and (null (minimap-active-current-buffer-p))
514 (minimap-get-window))
515 (delete-window (minimap-get-window))))))))))
519 (defun minimap-move-overlay-mouse (start-event)
520 "Move overlay by tracking mouse movement."
522 (mouse-set-point start-event)
523 (when (get-buffer-window (buffer-base-buffer (current-buffer)))
524 (let* ((echo-keystrokes 0)
525 (end-posn (event-end start-event))
526 (start-point (posn-point end-posn))
527 (make-cursor-line-fully-visible nil)
529 (minimap-automatically-delete-window nil)
530 (pcselmode (when (boundp 'pc-selection-mode)
533 (when (and pcselmode (fboundp 'pc-selection-mode))
534 (pc-selection-mode -1))
535 (move-overlay minimap-active-overlay start-point minimap-end)
537 (minimap-set-overlay start-point)
539 (consp (setq ev (read-event)))
540 (eq (car ev) 'mouse-movement))
541 (setq pt (posn-point (event-start ev)))
543 (minimap-set-overlay pt))))
544 (select-window (get-buffer-window (buffer-base-buffer)))
546 (when (and pcselmode (fboundp 'pc-selection-mode))
547 (pc-selection-mode 1)))))
549 (defun minimap-set-overlay (pt)
550 "Set overlay position, with PT being the middle."
552 (let* ((ovstartline (line-number-at-pos minimap-start))
553 (ovendline (line-number-at-pos minimap-end))
554 (ovheight (round (/ (- ovendline ovstartline) 2)))
555 (line (line-number-at-pos))
556 (winstart (window-start))
557 (winend (window-end))
559 (setq pt (point-at-bol))
560 (setq newstart (minimap-line-to-pos (- line ovheight)))
561 ;; Perform recentering
562 (minimap-recenter line ovheight)
563 ;; Set new position in main buffer and redisplay
564 (with-selected-window (get-buffer-window (buffer-base-buffer))
566 (set-window-start nil newstart)
568 (setq newend (window-end)))
569 (when (eq minimap-recenter-type 'free)
570 (while (> newend winend)
573 (setq winend (window-end))))
574 (move-overlay minimap-active-overlay newstart newend)))
576 (defun minimap-line-to-pos (line)
577 "Return point position of line number LINE."
580 (if (eq selective-display t)
581 (re-search-forward "[\n\C-m]" nil 'end (1- line))
582 (forward-line (1- line)))
585 (defun minimap-recenter (middle height)
586 "Recenter the minimap according to `minimap-recenter-type'.
587 MIDDLE is the line number in the middle of the active region.
588 HEIGHT is the number of lines from MIDDLE to begin/end of the
591 ;; Relative recentering
592 ((eq minimap-recenter-type 'relative)
593 (let* ((maxlines (line-number-at-pos (point-max)))
594 percentage relpos newline start numlines)
595 (setq numlines (count-lines (window-start) (window-end)))
596 (setq percentage (/ (float middle) (float maxlines)))
597 (setq newline (ceiling (* percentage numlines)))
598 (setq start (minimap-line-to-pos
601 (- numlines height height))))))
602 (or (> start (point-min))
603 (setq start (point-min)))
604 ;; If (point-max) already visible, don't go further
605 (if (and (> start (window-start))
606 (with-selected-window (get-buffer-window (buffer-base-buffer))
607 (= (point-max) (window-end))))
609 (goto-char (point-max))
611 (unless (and (> start (window-start))
612 (= (point-max) (window-end)))
613 (set-window-start nil start)))))
614 ;; Middle recentering
615 ((eq minimap-recenter-type 'middle)
616 (let ((start (- middle height
618 (- minimap-numlines height height))))))
621 ;; Hack: Emacs cannot scroll down any further, so we fake
622 ;; it using an overlay. Otherwise, the active region
623 ;; would move to the top.
624 (overlay-put minimap-pointmin-overlay
626 (make-string (abs start) 10)
627 (buffer-substring (point-min) (1+ (point-min)))))
628 (overlay-put minimap-pointmin-overlay
629 'face `(:background ,(face-background 'default)))
630 (overlay-put minimap-pointmin-overlay
633 (overlay-put minimap-pointmin-overlay 'display "")
634 (overlay-put minimap-pointmin-overlay 'face nil))
635 (set-window-start nil (minimap-line-to-pos start))))
637 ((eq minimap-recenter-type 'free)
638 (let ((newstart (minimap-line-to-pos (- middle height)))
639 (winstart (window-start)))
640 (while (< newstart winstart)
643 (setq winstart (window-start)))))))
645 ;;; Minimap minor mode
647 (defvar minimap-sb-mode-map (make-sparse-keymap)
648 "Keymap used by `minimap-sb-mode'.")
650 (define-key minimap-sb-mode-map [down-mouse-1] 'minimap-move-overlay-mouse)
651 (define-key minimap-sb-mode-map [down-mouse-2] 'minimap-move-overlay-mouse)
652 (define-key minimap-sb-mode-map [down-mouse-3] 'minimap-move-overlay-mouse)
654 (define-minor-mode minimap-sb-mode
655 "Minor mode for minimap sidebar."
656 nil "minimap" minimap-sb-mode-map)
658 ;;; Sync minimap with modes which create/delete overlays.
660 (defun minimap-sync-overlays ()
661 "Synchronize overlays between base and minimap buffer.
662 Apply semantic overlays or face enlargement if necessary."
664 ;; Get overlays and Semantic status from base buffer.
665 (when (and minimap-mode
666 (minimap-active-current-buffer-p))
667 (with-current-buffer minimap-active-buffer
668 (let ((baseov (overlays-in (point-min) (point-max)))
669 (semantic (and (boundp 'semantic-version)
670 (semantic-active-p)))
672 ;; Apply overlays to minimap.
673 (with-current-buffer minimap-buffer-name
674 ;; Delete overlays (but keep our own).
675 (let ((ovs (overlays-in (point-min) (point-max))))
677 (unless (member ov (list minimap-pointmin-overlay
679 minimap-active-overlay))
680 (delete-overlay ov))))
682 (when (and (eq (overlay-buffer (car baseov)) minimap-active-buffer)
683 (setq props (minimap-get-sync-properties (car baseov))))
684 (setq ov (make-overlay (overlay-start (car baseov))
685 (overlay-end (car baseov))))
686 (while (setq p (car props))
687 (overlay-put ov (car p) (cadr p))
688 (setq props (cdr props))))
689 (setq baseov (cdr baseov)))
690 (move-overlay minimap-pointmin-overlay (point-min) (1+ (point-min)))
691 ;; Re-apply font overlay
692 (move-overlay minimap-base-overlay (point-min) (point-max)))
694 (when (and font-lock-mode
695 (or (eq minimap-enlarge-certain-faces 'always)
696 (and (eq minimap-enlarge-certain-faces 'as-fallback)
697 (or (not minimap-display-semantic-overlays)
699 (when (eq font-lock-support-mode 'jit-lock-mode)
700 (jit-lock-fontify-now))
701 (minimap-enlarge-faces))
704 minimap-display-semantic-overlays)
705 (minimap-apply-semantic-overlays t))))))
707 (defun minimap-get-sync-properties (ov)
708 "Get properties from overlay OV which should be synced.
709 You can specify those properties with
710 `minimap-sync-overlay-properties'."
714 (let ((val (overlay-get ov p)))
718 minimap-sync-overlay-properties)))
720 (defun minimap-enlarge-faces ()
721 "Apply default font to all faces in `minimap-normal-height-faces'."
722 (let ((pos (next-single-property-change (point-min) 'face))
725 (setq face (get-text-property pos 'face))
727 (member face minimap-normal-height-faces))
728 (with-current-buffer minimap-buffer-name
731 (setq pos (next-single-property-change pos 'face))))
732 (overlay-put ov 'face `(:family ,(face-font 'default)))
733 (overlay-put ov 'priority 5)))
734 (setq pos (next-single-property-change pos 'face)))))
736 (defun minimap-apply-semantic-overlays (tags)
737 "Apply semantic overlays to the minimap.
738 TAGS is the list of tags. If it is t, fetch tags from buffer."
741 (with-current-buffer minimap-active-buffer
742 (let (tag class ov ovnew)
744 (setq tags (semantic-fetch-tags)))
746 (setq tag (car tags))
747 (setq class (semantic-tag-class tag))
748 (setq ov (semantic-tag-overlay tag))
749 (when (and (overlayp ov)
750 (or (eq class 'function)
752 (eq class 'variable)))
753 (with-current-buffer minimap-buffer-name
754 (let ((start (overlay-start ov))
755 (end (overlay-end ov))
756 (name (semantic-tag-name tag)))
757 ;; First, remove old Semantic overlays.
758 (remove-overlays start end 'minimap-semantic t)
759 ;; Now put the new ones.
761 (setq ovnew (make-overlay start end))
762 'face `(:background ,(face-background
763 (intern (format "minimap-semantic-%s-face"
764 (symbol-name class))))))
765 (overlay-put ovnew 'priority 1)
766 (overlay-put ovnew 'minimap-semantic t)
768 (minimap-line-to-pos (/ (+ (line-number-at-pos start)
769 (line-number-at-pos end)) 2)))
771 (while (looking-at "^$")
774 (setq end (progn (goto-char start) (point-at-eol)))
775 (setq ovnew (make-overlay start end))
776 (overlay-put ovnew 'face (format "minimap-semantic-%s-face"
777 (symbol-name class)))
778 (overlay-put ovnew 'display (concat " " name " "))
779 (overlay-put ovnew 'priority 6)
780 (overlay-put ovnew 'minimap-semantic t))))
781 (setq tags (cdr tags)))))))
785 ;;; minimap.el ends here