diff options
| author | 2026-07-14 00:03:09 -0700 | |
|---|---|---|
| committer | 2026-07-14 00:03:09 -0700 | |
| commit | 1d6fb807ee6fe7e628802a64134419765088efeb (patch) | |
| tree | 24eb035c62e1493365552f0236e46f3afb6fb80d | |
| parent | d6df1673b6835634baeb2710a1016945ab04f7c9 (diff) | |
| download | emacs-config-1d6fb807ee6fe7e628802a64134419765088efeb.tar.gz emacs-config-1d6fb807ee6fe7e628802a64134419765088efeb.zip | |
oni-scheme: Hide imports with overlays
Text properties are part of the text, but overlays are not. They also
automatically come with updated end position when text is added in between the
start and end of the overlay. This makes it much easier to manage and fixes the
issue that hiding the imports broke when a new import was added.
| -rw-r--r-- | oni-scheme.el | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/oni-scheme.el b/oni-scheme.el index 6c48414..baf71d9 100644 --- a/oni-scheme.el +++ b/oni-scheme.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse <tom@ryuslash.org> ;; Keywords: local -;; Version: 2025.0602.150536 +;; Version: 2026.0714.000130 ;; Package-Requires: (oni-company oni-paredit rainbow-delimiters geiser geiser-guile) ;; This program is free software; you can redistribute it and/or modify @@ -50,17 +50,16 @@ (make-local-variable 'minor-mode-overriding-map-alist) (push `(paredit-mode . ,newmap) minor-mode-overriding-map-alist))) +(defconst +oni-scheme-import-display+ " …" + "What to display instead of the scheme imports.") + (defun oni-scheme-toggle-import-display () (interactive) - (let ((start (get-text-property (point) 'oni-scheme-import-start)) - (end (get-text-property (point) 'oni-scheme-import-end)) - (visiblep (not (string= " ..." (get-text-property (point) 'display))))) - (with-silent-modifications - (unwind-protect - (progn - (buffer-disable-undo) - (put-text-property start end 'display (if visiblep " ..." nil))) - (buffer-enable-undo))))) + (let* ((overlay (seq-find (lambda (o) (overlay-get o 'oni-scheme-hidden-imports)) + (overlays-at (point)))) + (visiblep (not (string= +oni-scheme-import-display+ + (overlay-get overlay 'display))))) + (overlay-put overlay 'display (if visiblep +oni-scheme-import-display+ nil)))) (defun oni-scheme-hide-guile-imports () "Hide the imports in ‘define-module’." @@ -72,15 +71,13 @@ (setq start (line-end-position)) (forward-sexp) (setq end (1- (point))) - (with-silent-modifications - (unwind-protect - (progn - (buffer-disable-undo) - (set-text-properties start end `(display " ..." - keymap ,oni-scheme-hidden-imports-keymap - oni-scheme-import-start ,start - oni-scheme-import-end ,end))) - (buffer-enable-undo))))))) + (dolist (o (overlays-in start end)) + (when (overlay-get o 'oni-scheme-hidden-imports) + (delete-overlay o))) + (let ((overlay (make-overlay start end))) + (overlay-put overlay 'oni-scheme-hidden-imports t) + (overlay-put overlay 'display +oni-scheme-import-display+) + (overlay-put overlay 'keymap oni-scheme-hidden-imports-keymap)))))) (add-hook 'scheme-mode-hook 'company-mode) (add-hook 'scheme-mode-hook 'display-fill-column-indicator-mode) |
