~ubuntu-branches/ubuntu/intrepid/slime/intrepid

« back to all changes in this revision

Viewing changes to contrib/slime-highlight-edits.el

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-10-04 09:09:47 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071004090947-8oy7djtx8no3erxy
Tags: 1:20070927-2
Readded tree-widget to the sources. emacs21 on
debian does _not_ have that file. emacs22 and xemacs do.
(Closes: #445174)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;; slime-higlight-edits --- highlight edited, i.e. not yet compiled, code 
 
2
;;
 
3
;; Author: William Bland <doctorbill.news@gmail.com> and others
 
4
;; License: GNU GPL (same license as Emacs)
 
5
;;
 
6
;;; Installation: 
 
7
;; 
 
8
;; Add something like this your .emacs: 
 
9
;;
 
10
;;   (add-to-list 'load-path "<contrib-dir>")
 
11
;;   (autoload 'slime-highlight-edits-mode "slime-highlight-edits")
 
12
;;   (add-hook 'slime-mode-hook (lambda () (slime-highlight-edits-mode 1)))
 
13
 
 
14
(defface slime-highlight-edits-face
 
15
    `((((class color) (background light))
 
16
       (:background "lightgray"))
 
17
      (((class color) (background dark))
 
18
       (:background "dimgray"))
 
19
      (t (:background "yellow")))
 
20
  "Face for displaying edit but not compiled code."
 
21
  :group 'slime-mode-faces)
 
22
 
 
23
(define-minor-mode slime-highlight-edits-mode 
 
24
  "Minor mode to highlight not-yet-compiled code." nil)
 
25
 
 
26
(add-hook 'slime-highlight-edits-mode-on-hook
 
27
          'slime-highlight-edits-init-buffer)
 
28
 
 
29
(add-hook 'slime-highlight-edits-mode-off-hook
 
30
          'slime-highlight-edits-reset-buffer)
 
31
 
 
32
(defun slime-highlight-edits-init-buffer ()
 
33
  (make-local-variable 'after-change-functions)
 
34
  (add-to-list 'after-change-functions 
 
35
               'slime-highlight-edits)
 
36
  (add-to-list 'slime-before-compile-functions
 
37
               'slime-highlight-edits-compile-hook))
 
38
 
 
39
(defun slime-highlight-edits-reset-buffer ()
 
40
  (setq after-change-functions  
 
41
        (remove 'slime-highlight-edits after-change-functions))
 
42
  (slime-remove-edits (point-min) (point-max)))
 
43
 
 
44
;; FIXME: what's the LEN arg for?
 
45
(defun slime-highlight-edits (beg end &optional len) 
 
46
  (save-match-data
 
47
    (when (and (slime-connected-p)
 
48
               (not (slime-inside-comment-p beg end))
 
49
               (not (slime-only-whitespace-p beg end)))
 
50
      (let ((overlay (make-overlay beg end)))
 
51
        (overlay-put overlay 'face 'slime-highlight-edits-face)
 
52
        (overlay-put overlay 'slime-edit t)))))
 
53
 
 
54
(defun slime-remove-edits (start end)
 
55
  "Delete the existing Slime edit hilights in the current buffer."
 
56
  (save-excursion
 
57
    (goto-char start)
 
58
    (while (< (point) end)
 
59
      (dolist (o (overlays-at (point)))
 
60
        (when (overlay-get o 'slime-edit)
 
61
          (delete-overlay o)))
 
62
      (goto-char (next-overlay-change (point))))))
 
63
 
 
64
(defun slime-highlight-edits-compile-hook (start end)
 
65
  (when slime-highlight-edits-mode
 
66
    (let ((start (save-excursion (goto-char start) 
 
67
                                 (skip-chars-backward " \t\n\r")
 
68
                                 (point)))
 
69
          (end (save-excursion (goto-char end) 
 
70
                               (skip-chars-forward " \t\n\r")
 
71
                               (point))))
 
72
      (slime-remove-edits start end))))
 
73
 
 
74
(defun slime-inside-comment-p (beg end)
 
75
  "Is the region from BEG to END in a comment?"
 
76
  (save-excursion
 
77
    (goto-char beg)
 
78
    (let* ((hs-c-start-regexp ";\\|#|")
 
79
           (comment (hs-inside-comment-p)))
 
80
      (and comment
 
81
           (destructuring-bind (cbeg cend) comment
 
82
             (<= end cend))))))
 
83
 
 
84
(defun slime-only-whitespace-p (beg end)
 
85
  "Contains the region from BEG to END only whitespace?"
 
86
  (save-excursion
 
87
    (goto-char beg)
 
88
    (skip-chars-forward " \n\t\r" end)
 
89
    (<= end (point))))
 
90
 
 
91
(defun slime-highlight-edits-mode-on () (slime-highlight-edits-mode 1))
 
92
 
 
93
(defun slime-highlight-edits-init ()
 
94
  (add-hook 'slime-mode-hook 'slime-highlight-edits-mode-on))
 
95
 
 
96
(defun slime-highlight-edits-unload ()
 
97
  (remove-hook 'slime-mode-hook 'slime-highlight-edits-mode-on))
 
98
 
 
99
(provide 'slime-highlight-edits)
 
 
b'\\ No newline at end of file'