Path: blob/master/elisp/slime/contrib/slime-highlight-edits.el
990 views
1(define-slime-contrib slime-highlight-edits2"Highlight edited, i.e. not yet compiled, code."3(:authors "William Bland <[email protected]>")4(:license "GPL")5(:on-load (add-hook 'slime-mode-hook 'slime-activate-highlight-edits))6(:on-unload (remove-hook 'slime-mode-hook 'slime-activate-highlight-edits)))78(defun slime-activate-highlight-edits ()9(slime-highlight-edits-mode 1))1011(defface slime-highlight-edits-face12`((((class color) (background light))13(:background "lightgray"))14(((class color) (background dark))15(:background "dimgray"))16(t (:background "yellow")))17"Face for displaying edit but not compiled code."18:group 'slime-mode-faces)1920(define-minor-mode slime-highlight-edits-mode21"Minor mode to highlight not-yet-compiled code." nil)2223(add-hook 'slime-highlight-edits-mode-on-hook24'slime-highlight-edits-init-buffer)2526(add-hook 'slime-highlight-edits-mode-off-hook27'slime-highlight-edits-reset-buffer)2829(defun slime-highlight-edits-init-buffer ()30(make-local-variable 'after-change-functions)31(add-to-list 'after-change-functions32'slime-highlight-edits)33(add-to-list 'slime-before-compile-functions34'slime-highlight-edits-compile-hook))3536(defun slime-highlight-edits-reset-buffer ()37(setq after-change-functions38(remove 'slime-highlight-edits after-change-functions))39(slime-remove-edits (point-min) (point-max)))4041;; FIXME: what's the LEN arg for?42(defun slime-highlight-edits (beg end &optional len)43(save-match-data44(when (and (slime-connected-p)45(not (slime-inside-comment-p))46(not (slime-only-whitespace-p beg end)))47(let ((overlay (make-overlay beg end)))48(overlay-put overlay 'face 'slime-highlight-edits-face)49(overlay-put overlay 'slime-edit t)))))5051(defun slime-remove-edits (start end)52"Delete the existing Slime edit hilights in the current buffer."53(save-excursion54(goto-char start)55(while (< (point) end)56(dolist (o (overlays-at (point)))57(when (overlay-get o 'slime-edit)58(delete-overlay o)))59(goto-char (next-overlay-change (point))))))6061(defun slime-highlight-edits-compile-hook (start end)62(when slime-highlight-edits-mode63(let ((start (save-excursion (goto-char start)64(skip-chars-backward " \t\n\r")65(point)))66(end (save-excursion (goto-char end)67(skip-chars-forward " \t\n\r")68(point))))69(slime-remove-edits start end))))7071(defun slime-only-whitespace-p (beg end)72"Contains the region from BEG to END only whitespace?"73(save-excursion74(goto-char beg)75(skip-chars-forward " \n\t\r" end)76(<= end (point))))7778(provide 'slime-highlight-edits)798081