[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/macrostep 9cd6742 016/110: Try to be smarter about maintai
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/macrostep 9cd6742 016/110: Try to be smarter about maintaining buffer state |
Date: |
Sat, 7 Aug 2021 09:17:54 -0400 (EDT) |
branch: elpa/macrostep
commit 9cd674287e39447dbd4bb186a087dab7e38828fe
Author: joddie <jonxfield@gmail.com>
Commit: joddie <jonxfield@gmail.com>
Try to be smarter about maintaining buffer state
- save and restore buffer-read-only
- exit macrostep-mode correctly if the buffer is made writable again
- save and restore buffer-undo-list, and disable undo recording while
macrostep is active
- use `with-silent-modifications' to not mark buffer as modified.
Caveats: This is nicer for the user when inspecting an unmodified
buffer, but could be dangerous if we somehow manage leave the buffer
in an inconsistent state without warning. Is there a better way?
---
macrostep.el | 84 +++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 57 insertions(+), 27 deletions(-)
diff --git a/macrostep.el b/macrostep.el
index 6cae0ec..38f0bc1 100644
--- a/macrostep.el
+++ b/macrostep.el
@@ -190,6 +190,13 @@
"t if gensyms have been encountered during current level of macro
expansion.")
(make-variable-buffer-local 'macrostep-gensyms-this-level)
+(defvar macrostep-saved-undo-list nil
+ "Saved value of buffer-undo-list upon entering macrostep mode.")
+(make-variable-buffer-local 'macrostep-saved-undo-list)
+
+(defvar macrostep-saved-read-only nil
+ "Saved value of buffer-read-only upon entering macrostep mode.")
+(make-variable-buffer-local 'macrostep-saved-read-only)
;;; Faces
(defgroup macrostep nil
@@ -293,14 +300,34 @@ quit and return to normal editing.
nil " Macro-Stepper"
:keymap macrostep-keymap
:group macrostep
- (setq buffer-read-only macrostep-mode)
(if macrostep-mode
- (message
- (substitute-command-keys
- "\\<macrostep-keymap>Entering macro stepper mode. Use
\\[macrostep-expand] to expand, \\[macrostep-collapse] to collapse,
\\[macrostep-collapse-all] to exit."))
+ (progn
+ ;; Disable recording of undo information
+ (setq macrostep-saved-undo-list buffer-undo-list
+ buffer-undo-list t)
+ ;; Remember whether buffer was read-only
+ (setq macrostep-saved-read-only buffer-read-only
+ buffer-read-only t)
+ ;; Set up post-command hook to bail out on leaving read-only
+ (add-hook 'post-command-hook 'macrostep-command-hook nil t)
+ (message
+ (substitute-command-keys
+ "\\<macrostep-keymap>Entering macro stepper mode. Use
\\[macrostep-expand] to expand, \\[macrostep-collapse] to collapse,
\\[macrostep-collapse-all] to exit.")))
;; Exiting mode: collapse any remaining overlays
- (when macrostep-overlays (macrostep-collapse-all))))
+ (when macrostep-overlays (macrostep-collapse-all))
+ :; Restore undo info & read-only state
+ (setq buffer-undo-list macrostep-saved-undo-list
+ buffer-read-only macrostep-saved-read-only
+ macrostep-saved-undo-list nil)
+ ;; Remove our post-command hook
+ (remove-hook 'post-command-hook 'macrostep-command-hook t)))
+
+;; Post-command hook: bail out of macrostep-mode if the user types C-x
+;; C-q to make the buffer writable again.
+(defun macrostep-command-hook ()
+ (if (not buffer-read-only)
+ (macrostep-mode 0)))
;;; Interactive functions
@@ -342,21 +369,22 @@ buffer and expand the next macro form found, if any."
priority 1
macrostep-gensym-depth -1))
- (atomic-change-group
- (macrostep-replace-sexp-at-point expansion)
- (let ((new-ol
- (make-overlay (point)
- (scan-sexps (point) 1))))
- ;; move overlay over newline to make it prettier
- (when (equal (char-after (overlay-end new-ol)) ?\n)
- (move-overlay new-ol
- (overlay-start new-ol) (+ (overlay-end new-ol) 1)))
- (overlay-put new-ol 'face 'macrostep-expansion-highlight-face)
- (overlay-put new-ol 'evaporate t)
- (overlay-put new-ol 'priority priority)
- (overlay-put new-ol 'macrostep-original-text text)
- (overlay-put new-ol 'macrostep-gensym-depth macrostep-gensym-depth)
- (push new-ol macrostep-overlays))))))
+ (with-silent-modifications
+ (atomic-change-group
+ (macrostep-replace-sexp-at-point expansion)
+ (let ((new-ol
+ (make-overlay (point)
+ (scan-sexps (point) 1))))
+ ;; move overlay over newline to make it prettier
+ (when (equal (char-after (overlay-end new-ol)) ?\n)
+ (move-overlay new-ol
+ (overlay-start new-ol) (+ (overlay-end new-ol) 1)))
+ (overlay-put new-ol 'face 'macrostep-expansion-highlight-face)
+ (overlay-put new-ol 'evaporate t)
+ (overlay-put new-ol 'priority priority)
+ (overlay-put new-ol 'macrostep-original-text text)
+ (overlay-put new-ol 'macrostep-gensym-depth macrostep-gensym-depth)
+ (push new-ol macrostep-overlays)))))))
(defun macrostep-collapse ()
"Collapse the innermost macro expansion near point to its source text.
@@ -367,8 +395,9 @@ If no more macro expansions are visible after this, exit
(let ((overlay (macrostep-overlay-at-point)))
(when (not overlay) (error "No macro expansion at point"))
(let ((buffer-read-only nil))
- (atomic-change-group
- (macrostep-collapse-overlay overlay))))
+ (with-silent-modifications
+ (atomic-change-group
+ (macrostep-collapse-overlay overlay)))))
(if (not macrostep-overlays)
(macrostep-mode 0)))
@@ -376,11 +405,12 @@ If no more macro expansions are visible after this, exit
"Collapse all visible macro expansions and exit `macrostep-mode'."
(interactive)
(let ((buffer-read-only nil))
- (dolist (overlay macrostep-overlays)
- (let ((outermost (= (overlay-get overlay 'priority) 1)))
- ;; We only need restore the original text for the outermost
- ;; overlays
- (macrostep-collapse-overlay overlay (not outermost)))))
+ (with-silent-modifications
+ (dolist (overlay macrostep-overlays)
+ (let ((outermost (= (overlay-get overlay 'priority) 1)))
+ ;; We only need restore the original text for the outermost
+ ;; overlays
+ (macrostep-collapse-overlay overlay (not outermost))))))
(setq macrostep-overlays nil)
(macrostep-mode 0))
- [nongnu] elpa/macrostep e35b61d 047/110: Add compiler-macro support for SLIME, (continued)
- [nongnu] elpa/macrostep e35b61d 047/110: Add compiler-macro support for SLIME, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 3766ffb 043/110: Hack to propertize macros in SLIME expansions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 522226f 050/110: Improve `macrostep-slime-macro-form-p`, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 059dda6 066/110: Also hook into slime-repl-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep e582ca7 078/110: Fix trivial bug printing a single non-list form, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 84e5bfa 086/110: Make tests pass again, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 2dd3447 004/110: Fix bug with output of macros that expand to a string (e.g. `rx'), ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 6c4afbe 002/110: Got rid of `macrostep-change-group'. Updated some documentation., ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep e2bf1aa 005/110: Change :reverse-video to :inverse-video for e24, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 993a79f 010/110: bump version number, add changelog, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 9cd6742 016/110: Try to be smarter about maintaining buffer state,
ELPA Syncer <=
- [nongnu] elpa/macrostep cb2019e 017/110: acknowledgements in docs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 5c62a4c 021/110: Merge remote-tracking branch 'georgek/backquotes', ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep f026495 025/110: Fix comment typos, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 77c0c1a 023/110: update readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep b04f8db 026/110: Basic support for expanding macros bound by `macrolet', ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 7acce07 028/110: Require `cl-macs` at runtime, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 51d5b6a 036/110: Fix a bug with printing the first element of a list., ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 07e14e2 032/110: Test for macrostep-environment-at-point, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep c93c2d6 053/110: Language-agnostic macro-form boundaries, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep e3e5c12 034/110: Merge branch 'expand-macrolet', ELPA Syncer, 2021/08/07