;;; shm-overlays.el --- Overlays ;; Copyright (c) 2014 Chris Done. All rights reserved. ;; This file 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 3, or (at your option) ;; any later version. ;; This file 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, see . ;;; Code: (require 'cl) (require 'shm-node) (defvar shm-current-node-overlay nil "Overlay to highlight the current node.") (defvar shm-last-point 0 "When moving around, the current node overlay will update according to where you are. But often you can shrink/expand the scope of the current node. This variable lets us avoid the node being reset by realising we haven't actually moved the point.") (defun shm-delete-overlays (start end type) "Delete overlays of the given type. This is used for both current overlay and quarantines." (mapc (lambda (o) (when (overlay-get o type) (delete-overlay o))) (overlays-in start end))) (defun shm-current-overlay (start end node-pair) "Make the overlay for current node at START to END, setting the NODE-PAIR in the overlay." (let ((o (make-overlay start end nil nil t))) (overlay-put o 'shm-current-overlay t) (overlay-put o 'face 'shm-current-face) (overlay-put o 'node-pair node-pair) (overlay-put o 'priority 1) o)) (defun shm-quarantine-overlay (start end) "Make a quarantine from START to END." (let ((o (make-overlay start end nil nil t))) (overlay-put o 'shm-quarantine t) (overlay-put o 'face 'shm-quarantine-face) (overlay-put o 'priority 0) o)) (defun shm-find-overlay (type) "Find overlays at point." (remove-if-not (lambda (o) (overlay-get o type)) (overlays-in (point-min) (point-max)))) (provide 'shm-overlays)