Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a shim for Macrostep. #637

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions meow-shims.el
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,79 @@
(add-hook 'sly-db-hook 'meow--sly-debug-hook-function)
(remove-hook 'sly-db-hook 'meow--sly-debug-hook-function)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; macrostep

(defvar macrostep-overlays)
(defvar macrostep-mode)

(defvar meow--macrostep-setup nil)
(defvar meow--macrostep-setup-previous-state nil)

(defun meow--macrostep-inside-overlay-p ()
"Return whether point is inside a `macrostep-mode' overlay."
(seq-some (let ((pt (point)))
(lambda (ov)
(and (<= (overlay-start ov) pt)
(< pt (overlay-end ov)))))
macrostep-overlays))

(defun meow--macrostep-post-command-function ()
"Function to run in `post-commmand-hook' when `macrostep-mode' is enabled.

`macrostep-mode' uses a local keymap for the overlay showing the
expansion. Switch to Motion state when we enter the overlay and
try to switch back to the previous state when leaving it."
(if (meow--macrostep-inside-overlay-p)
;; The overlay is not editable, so the `macrostep-mode' commands are
;; likely more important than the Beacon-state commands and possibly more
;; important than any custom-state commands. It is less important than
;; Keypad state.
(unless (eq meow--current-state 'keypad)
(meow--switch-to-motion))
(meow--switch-state meow--macrostep-setup-previous-state)))

(defun meow--macrostep-record-outside-state (state)
"Record the Meow STATE in most circumstances, so that we can return to it later.

This function receives the STATE to which one switches via `meow--switch-state'
inside `meow-switch-state-hook'.

Record the state if:
- We are outside the overlay and not in Keypad state.
- We are inside the overlay and not in Keypad or Motion state."
;; We assume that the user will not try to switch to Motion state for the
;; entire buffer while we are already in Motion state while inside an overlay.
(unless (eq state 'keypad)
(if (not (meow--macrostep-inside-overlay-p))
(setq-local meow--macrostep-setup-previous-state state)
(unless (eq state 'motion)
(setq-local meow--macrostep-setup-previous-state state)))))

(defun meow--macrostep-hook-function ()
"Switch Meow state when entering/leaving `macrostep-mode' or its overlays."
(if macrostep-mode
(progn
(setq-local meow--macrostep-setup-previous-state meow--current-state)
;; Add to end of `post-command-hook', so that this function is run after
;; the check for whether we should switch to Beacon state.
(add-hook 'post-command-hook #'meow--macrostep-post-command-function 90 t)
(add-hook 'meow-switch-state-hook #'meow--macrostep-record-outside-state nil t))
;; The command `macrostep-collapse' does not seem to trigger
;; `post-command-hook', so we switch back manually.
(meow--switch-state meow--macrostep-setup-previous-state)
(setq-local meow--macrostep-setup-previous-state nil)
(remove-hook 'meow-switch-state-hook #'meow--macrostep-record-outside-state t)
(remove-hook 'post-command-hook #'meow--macrostep-post-command-function t)))

(defun meow--setup-macrostep (enable)
"Setup macrostep.
Argument ENABLE non-nil means turn on."
(setq meow--macrostep-setup enable)
(if enable
(add-hook 'macrostep-mode-hook 'meow--macrostep-hook-function)
(remove-hook 'macrostep-mode-hook 'meow--macrostep-hook-function)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; realgud (debug)

Expand Down Expand Up @@ -366,15 +439,16 @@
(meow--setup-eldoc t)
(meow--setup-rectangle-mark t)

(eval-after-load "macrostep" (lambda () (meow--setup-macrostep t)))

Check warning on line 442 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 442 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 442 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "wdired" (lambda () (meow--setup-wdired t)))

Check warning on line 443 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 443 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 443 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "edebug" (lambda () (meow--setup-edebug t)))

Check warning on line 444 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 444 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 444 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "wgrep" (lambda () (meow--setup-wgrep t)))

Check warning on line 445 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 445 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 445 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "company" (lambda () (meow--setup-company t)))

Check warning on line 446 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 446 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 446 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "polymode" (lambda () (meow--setup-polymode t)))

Check warning on line 447 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 447 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 447 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "cider" (lambda () (meow--setup-cider t)))

Check warning on line 448 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 448 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "sly" (lambda () (meow--setup-sly t)))

Check warning on line 449 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 449 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "realgud" (lambda () (meow--setup-realgud t)))

Check warning on line 450 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 450 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "which-key" (lambda () (meow--setup-which-key t)))

Check warning on line 451 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 451 in meow-shims.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "undo-tree" (lambda () (meow--setup-undo-tree t)))
(eval-after-load "diff-hl" (lambda () (meow--setup-diff-hl t)))
(eval-after-load "quail" (lambda () (meow--setup-input-method t)))
Expand All @@ -383,6 +457,7 @@
(defun meow--disable-shims ()
"Remove shim setups."
(setq delete-active-region meow--backup-var-delete-activate-region)
(when meow--macrostep-setup (meow--setup-macrostep nil))
(when meow--eldoc-setup (meow--setup-eldoc nil))
(when meow--rectangle-mark-setup (meow--setup-rectangle-mark nil))
(when meow--wdired-setup (meow--setup-wdired nil))
Expand All @@ -398,3 +473,3 @@

;;; meow-shims.el ends here
(provide 'meow-shims)
Loading