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

In dev build, toggle_record_macro and start_record_macro commands don't work when run from a plugin #6062

Closed
Jayshua opened this issue Jul 30, 2023 · 3 comments

Comments

@Jayshua
Copy link

Jayshua commented Jul 30, 2023

Description of the bug

I've written this plugin:

import sublime
import sublime_plugin

class TestRecMacCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		self.view.run_command("toggle_record_macro")

and added this keybinding:

{"keys": ["="], "command": "test_rec_mac"}

When pressing = on build 4143 this works as expected and macro recording begins. Ending the recording with toggle_record_macro or by using the menu option also works as expected.

In 4150 however, pressing = causes the status bar to display "Starting to record macro..." but no macro recording actually appears to occur. Running "toggle_record_macro" or "stop_record_macro" and then getting the macro with sublime.get_macro() returns an empty array.

The menu bar "Tools -> Record Macro" option appears to work correctly in 4150, as does running "toggle_record_macro" from a keybinding, as does running view.run_command("toggle_record_macro") from the debug console.

Steps to reproduce

Option 1:

  1. Start ST in Safe Mode
  2. Create a TestRecMac.py plugin with the contents above.
  3. Create a keybinding to run the command like above.
  4. Press = in a file to start recording a macro. Observe the "Starting to record macro..." text in the status bar.
  5. Observe that a macro isn't recording by opening the Tools menu and noting the "Record Macro" menu option is available rather than the "Stop Recording Macro" menu option. Or observe that a macro isn't recording by pressing = again and seeing the "Starting to record macro..." text appear in the status bar again, rather than the "Recorded macro with n commands" text.

Option 2:

  1. Start ST in Safe Mode
  2. Enable the Vintage plugin
  3. Attempt to record a macro by entering command mode and pressing
    qq (Record macro into the q register [the status bar displays "Starting to record macro..." but it doesn't appear to actually be recording a macro. Check Tools -> Record Macro, or continue to verify.])
    x (delete character under cursor)
    q (Stop recording macro. [Since no macro is actually being recorded, this doesn't work. Note that the status bar does not display "Recorded macro with n commands"])
    @q (Run the macro in the q register. No macro was recorded, so this does not work.)
    

Expected behavior

Macros should record.

Actual behavior

Macros do not record.

Sublime Text build number

Fails in 4150, works in 4143

Operating system & version

Void Linux, Kernel 6.3.12

(Linux) Desktop environment and/or window manager

bspwm

Additional information

No response

OpenGL context information

No response

@Jayshua Jayshua changed the title toggle_record_macro and start_record_macro commands don't work when run from a plugin In dev build, toggle_record_macro and start_record_macro commands don't work when run from a plugin Jul 30, 2023
@BenjaminSchaaf
Copy link
Member

Macro recording is based on the undo/redo stack. TextCommands are for making text buffer modifications and thus their actions are recorded on the undo/redo stack. Because of this you can't start recording a macro inside of a TextCommand. You'll need to use a WindowCommand or ApplicationCommand.

@Jayshua
Copy link
Author

Jayshua commented Jul 31, 2023

Thank you, three questions if you have a moment: This is a breaking change since it used to work, right? I couldn't find a comment about this change in the release notes, should it/is it included in those somewhere? Since the Vintage plugin uses TextCommands to implement macro recording, it's now broken and needs to be updated for the new API expectations, correct?

@BenjaminSchaaf
Copy link
Member

It's a breaking change in the sense of https://xkcd.com/1172/. Starting recording a macro inside a text command leads to broken behavior: #5781.

Since the Vintage plugin uses TextCommands to implement macro recording, it's now broken and needs to be updated for the new API expectations, correct?

Looks like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants