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

Macro Scripts #13

Open
d-akara opened this issue Mar 26, 2018 · 11 comments
Open

Macro Scripts #13

d-akara opened this issue Mar 26, 2018 · 11 comments
Assignees
Labels

Comments

@d-akara
Copy link
Owner

d-akara commented Mar 26, 2018

VSCode currently does not support recordable macros.
We also can not implement this as an extension since the API's don't let us track all user activity.

This is an attempt at hopefully providing the next best option, macros as scripts.

Feature ideas:

  • Write a macro script which can invoke any vscode command
  • Provide intellisense for commands for quicker authoring
  • Preview in near realtime the script transformation as applied to a document while authoring a script
    • Allow to play macro script step by step, forwards and backwards in preview
  • Save scripts for reuse
  • Provide command which can rerun last macro, useful for repeating via key binding
@d-akara
Copy link
Owner Author

d-akara commented Mar 26, 2018

Preview of the macro script authoring

  1. Intellisense provided for all commands
  2. Cursor location is highlighted in preview editor for each step
  3. Each command is executed in right most preview editor
  4. Using the cursor to navigate up and down in the script, we can step backwards or forwards through each command in the macro and see the effect.
  5. When script authoring is complete, the user will be able to save the macro or run it in any other document

macro_preview

@jpsala
Copy link

jpsala commented Mar 26, 2018

Hi @dakaraphi , how can I test this, it seems great, can we use for example the search capabilities as part of a script?

@d-akara
Copy link
Owner Author

d-akara commented Mar 26, 2018

@jpsala I am planning to support search; however, I will need to write some helper functions, since invoking search through the normal vscode commands is not going to work so well.

As far as testing, It is still a bit too early. I expect within a week or two I will have something that is useful enough to play around with. I will probably just publish an update for this extension to the marketplace at that time.

@jpsala
Copy link

jpsala commented Mar 26, 2018

Thanks a lot @dakaraphi , I'll be waiting :)

@d-akara
Copy link
Owner Author

d-akara commented Apr 3, 2018

Progress update:

  1. I'm going to publish a preview. Consider it experimental.
  2. Issues:
    1. Moving the cursor up and down in the script editor causes flickering
    2. Sometimes focus might shift from the script editor to the preview editor when moving cursor up and down
    3. There are probably lots of vscode commands that aren't going to work as a script. Many are simply not useful in that context. I haven't had time to trim the list of intellisense provided commands down to only those that both work and will be useful
  3. Which vscode commands work?
    1. Most vscode commands that move the cursor, alter a selection or perform some edit on text in the editor

Features overview

  1. Write a script of vscode commands which can be recalled and executed

  2. Intellisense for vscode commands

    1. Currently I've broken some commands into groups.
    2. t - types literal text.
    3. c - cursor commands
    4. s - selection commands
    5. v - all vscode commands unfiltered
    6. x - macro script helper commands
  3. Saving of scripts. Currently saved as macros.json in the workspace .vscode folder

  4. Live Preview of Script

    1. Macro Preview opens when editing a script
    2. The preview will open with whatever text was selected when the macro create command was issued
    3. The preview can also be set to any text using the code lens at the top Set current text as starting point for macro test
      1. The cursor starting point for running the macro will be set from the current cursor position in the preview editor when the code lens is clicked
  5. Script must be saved using the Save Script: code lens in the script editor

  6. A macro can be executed repeatedly for multiple lines by first making a selection over multiple lines. The macro will then be executed on each line and the cursor will start at the beginning of each line

Future Considerations

  • Running vscode commands as a script has a number of challenges
    • There is no API to directly execute a command against a particular editor
    • Focus must be shifted to the preview editor, commands executed, focus returned to script editor. This causes some flickering and flashing
    • Executing commands are not very fast. Might not work so well for large documents
    • Without some helper commands, the vscode commands will not be very useful
      • There is currently one helper command to perform a search like function to move the cursor forward until finding matching text. x cursorForwardUntil sometext
  • We might can provide better experience using only helper functions
    • Likely filtering and performance issues could be eliminated
    • However, we would need to implement ourselves all of the useful cursor, selection etc vscode functions

@d-akara
Copy link
Owner Author

d-akara commented Apr 11, 2018

@jpsala just wanted to follow up to see if you had a chance to try the macros and if you have any feedback in regards to #13 (comment)

@d-akara d-akara self-assigned this Apr 14, 2018
@sonenko
Copy link

sonenko commented Jun 15, 2018

screenshot at jun 16 00-39-27

Hi thanks a lot for contributing here. But is seems it does not works for OSX. Please see error in attachment.

@d-akara
Copy link
Owner Author

d-akara commented Jun 28, 2018

@sonenko @aaronmyatt
The macro script is not actually a file. So you have to click on the code lens - Save Script: to save the script.

image

@faustinoaq
Copy link

@ArturoDent
Copy link

This is great work so far. A couple of points:

  1. I am unable to use the mouse in the quick open panel (or whatever it is called) to select which macro script to run, I can only use the arrow and enter keys to choose which script to run. [Not a big deal.]

  2. There are a some more complex commands, see https://code.visualstudio.com/docs/extensionAPI/vscode-api-commands that could be implemented - they all take arguments though - especially the cursor move since it is more powerful, although I suppose all its actions can be replicated in a much more verbose way with the existing simple commands. The macros/macrosRe extensions do support at least some of these complex commands.

  3. This extension's own commands, like "dakara-transformer.sortLines" do work in the macros scripts although they do not show up in the "v" command intellisense.

  4. Is there a way to assign an individual macro script to a keybinding?

Thanks.

@d-akara
Copy link
Owner Author

d-akara commented Aug 2, 2018

@ArturoDent Thanks for the feedback.

  1. This seems to work ok for me. This is not something I actually control. I'm just using vscode's provided pickers. Not sure what the issue is in your case.
  2. I'm still uncertain which direction I want to take macro commands. See Macro Scripts #13 (comment) Future considerations
  3. I've noticed this issue, although haven't had a chance to look into it yet.
  4. Not currently, but I think I could provide a command that accept a parameter for script that you could configure in keybindings

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

No branches or pull requests

5 participants