Klimi's new dotfiles with stow.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

81 rader
2.7 KiB

5 år sedan
  1. (require 'slime)
  2. (require 'slime-parse)
  3. (define-slime-contrib slime-highlight-edits
  4. "Highlight edited, i.e. not yet compiled, code."
  5. (:authors "William Bland <doctorbill.news@gmail.com>")
  6. (:license "GPL")
  7. (:on-load (add-hook 'slime-mode-hook 'slime-activate-highlight-edits))
  8. (:on-unload (remove-hook 'slime-mode-hook 'slime-activate-highlight-edits)))
  9. (defun slime-activate-highlight-edits ()
  10. (slime-highlight-edits-mode 1))
  11. (defface slime-highlight-edits-face
  12. `((((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)
  19. (define-minor-mode slime-highlight-edits-mode
  20. "Minor mode to highlight not-yet-compiled code." nil)
  21. (add-hook 'slime-highlight-edits-mode-on-hook
  22. 'slime-highlight-edits-init-buffer)
  23. (add-hook 'slime-highlight-edits-mode-off-hook
  24. 'slime-highlight-edits-reset-buffer)
  25. (defun slime-highlight-edits-init-buffer ()
  26. (make-local-variable 'after-change-functions)
  27. (add-to-list 'after-change-functions
  28. 'slime-highlight-edits)
  29. (add-to-list 'slime-before-compile-functions
  30. 'slime-highlight-edits-compile-hook))
  31. (defun slime-highlight-edits-reset-buffer ()
  32. (setq after-change-functions
  33. (remove 'slime-highlight-edits after-change-functions))
  34. (slime-remove-edits (point-min) (point-max)))
  35. ;; FIXME: what's the LEN arg for?
  36. (defun slime-highlight-edits (beg end &optional len)
  37. (save-match-data
  38. (when (and (slime-connected-p)
  39. (not (slime-inside-comment-p))
  40. (not (slime-only-whitespace-p beg end)))
  41. (let ((overlay (make-overlay beg end)))
  42. (overlay-put overlay 'face 'slime-highlight-edits-face)
  43. (overlay-put overlay 'slime-edit t)))))
  44. (defun slime-remove-edits (start end)
  45. "Delete the existing Slime edit hilights in the current buffer."
  46. (save-excursion
  47. (goto-char start)
  48. (while (< (point) end)
  49. (dolist (o (overlays-at (point)))
  50. (when (overlay-get o 'slime-edit)
  51. (delete-overlay o)))
  52. (goto-char (next-overlay-change (point))))))
  53. (defun slime-highlight-edits-compile-hook (start end)
  54. (when slime-highlight-edits-mode
  55. (let ((start (save-excursion (goto-char start)
  56. (skip-chars-backward " \t\n\r")
  57. (point)))
  58. (end (save-excursion (goto-char end)
  59. (skip-chars-forward " \t\n\r")
  60. (point))))
  61. (slime-remove-edits start end))))
  62. (defun slime-only-whitespace-p (beg end)
  63. "Contains the region from BEG to END only whitespace?"
  64. (save-excursion
  65. (goto-char beg)
  66. (skip-chars-forward " \n\t\r" end)
  67. (<= end (point))))
  68. (provide 'slime-highlight-edits)