Select Current Handler command

I would like to see a Select Current Handler command. Given that Go to Previous/Next Handler is already implemented, that should require only a bit more effort. This would support Copy/Cut of a handler, a not infrequent action.

It would also be lovely, but a much bigger project, to implement “expand selection one scope upward”, a command found in some IDEs and IDE-like editors. For instance, with the lines in a conditional selected, the command would extend the selection in both directions to encompass the if and end. Doing it again would go up another level, eventually to the encompass the entire handler, and even a script object that contains the handler.

In Script Debugger, this is the Balance (Command-B) command. Repeated invocations of this command select successively larger scopes. I think the Balance command also goes a long way towards addressing your feature request.

1 Like

Not surprised it’s already there — seems like the kind of thing SD would do. I misperceived the behavior of Balance – I thought it was just showing me the innermost balance, rather than moving outward.

That is a little-known SD Easter Egg. Hold down the option key when choosing from the Edit menu, and the menu item changes to “Buddha Balance.”

I thought a bit more about this. There are commands — or automatic actions — in some other editors/IDEs I use that just show expression balance without actually moving. They have separate commands for moving. I must have simply assumed that SD’s Balance command was like the former, rather than the latter. Carelessly, I didn’t test my assumption.

So Balance gives me what I thought would be more difficult, but it still doesn’t provide a one-click select-handler command. (Well, I could use Balance until I got there, but that would be tedious inside a deeply nested structure.) Since there are Next and Previous Handler commands I think it would be appropriate and easy to implement a Select Entire Handler command.

A variation on a straightforward Select Handler would be to implement shift + Previous/Next Handler to select the text skipped over during that movement, the way various shift-arrow keys do in standard OS X applications. (For example, ⌥⇧→ selects — or extends the selection — through the next word.) Movement and selection extension are closely tied together conceptually, and it shouldn’t be too hard to add a shift variation to already implemented movement commands.

I tried that and it doesn’t change the menu item name and doesn’t seem too do anything different. Pressing ⌥⌘B, however, does do something different — it comments out something enclosing where the cursor is. It’s idea of enclosing is different from straight ⌘B because it will, for instance, select the current line where as normal Balance moves up past lines.

Having now experimented with Balance, I was surprised to find that while it selects the quoted text the cursor is in it skipped up through parentheses.

Are you suggesting that the Balance command should select parentheses within a string literal? If that is the case, I would not consider that a workable feature.

No, I meant that after selecting the string containing the cursor, a subsequent balance will move upward through surrounding parentheses rather than stopping at the parenthesized expression in which the string is found. I should have given you the example where I thought I had encountered this because I cannot reproduce it. My apologies. I am usually pretty good about submitting examples and test cases.