Macro not behaving the same as keystrokes
-
So here’s an odd one; while writing code (html in this case), I like to use auto-complete to save having to type ending tags. However, what I don’t like is after typing the text between tags, having to move my fingers from the home row, type <END>, return to the home row and press <ENTER>. So I created a macro with just those two keystrokes: <END><ENTER>. I saved it to the <Ctrl-ENTER> combination (after clearing the existing macro which just filled in auto-complete because <TAB> does the same thing.)
This works really well EXCEPT when the line I’m on is indented. If I press the keys <END> and <ENTER> separately, the cursor goes to the end of the line, then creates a new line below it and auto indents. If I execute the macro instead, the new line is created, but the cursor is at the BEGINNING of the line. It doesn’t auto-indent. This is somewhat of a pain. I have worked around it by assigning <Ctrl-E> to a macro that just takes me to the end of line, then I press <ENTER> - one more keystroke that I shouldn’t have to make.
Is this an undocumented feature (bug), or am I missing something?
-
I can’t offer up a solution at the moment, but I agree with your assessment.
When trying this without macro-recording turned on, End followed by Enter causes the newly created line to be indented (with auto-indent turned on).
When trying it during macro recording the Enter press causes the new line below to NOT be indented.
-
Interesting.
So, if you record the macro, it inserts the actual characters:
<Macro name="EndEnter" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2451" wParam="0" lParam="0" sParam="" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="
" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="
" /> </Macro>
Looking at scintilla.h messages: 2451 is SCI_LINEENDWRAP; then, when you hit ENTER, it inserts the CR and LF characters using the 2170 = SCI_REPLACESEL (it replaces the empty selection with the character 13=CR, then replaces the empty selection with the character 10=LF).
I tried replacing both of those 2170’s with a single SCI_NEWLINE=2329
<Macro name="EndSciNewLine" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2451" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2329" wParam="0" lParam="0" sParam="" /> </Macro>
but it behaved identically to the CR and LF inserts.
While looking for more ideas, I came across Useful Macros: New line with exact indentation, which I was able to tweak into:
<Macro name="AddLineAutoIndent" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2469" wParam="0" lParam="0" sParam="" /><!-- SCI_SELECTIONDUPLICATE == Ctrl-D --> <Action type="0" message="2300" wParam="0" lParam="0" sParam="" /><!-- SCI_LINEDOWN == DownArrow --> <Action type="0" message="2451" wParam="0" lParam="0" sParam="" /><!-- SCI_LINEENDWRAP == END Key --> <Action type="1" message="2170" wParam="0" lParam="0" sParam="a" /><!-- SCI_REPLACESEL == a key --> <Action type="0" message="2453" wParam="0" lParam="0" sParam="" /><!-- SCI_VCHOMEWRAP == HOME or Alt+Home, depending on settings: go to first non-space character on the line --> <Action type="0" message="2396" wParam="0" lParam="0" sParam="" /><!-- SCI_DELLINERIGHT == Ctrl+Shift+DEL: delete from that to the right end of the line --> </Macro>
So, it’s a much more tedious sequence to enter if you’re recording the macro, but it is possible to get the same functionality into a recorded macro. (Or you can edit the 2451/2170/2170 to the 2469/2300/… after the fact).
IOt doesn’t really explain the “why” however. My is that in order to capture all the events for the the macro-record, it (intentionally or unintentionally) bypasses normal filters which would send the auto-indent sequence to scintilla instead of just the CR+LF characters. (Not that it helps you. Sorry.)
-
Hello, @russ-fisher, @scott-sumner, @peterjones and All,
I found an other sequence of keys, @russ-fisher, which :
-
Whatever the location of the cursor, on the current line
-
Whatever the current line is wrapped or not
-
Whatever the current line is indented or not
-
Whatever the
Word wrap
option is on or off
is able to create a new line, right below the current one, with its indentation !
Indeed, @peterjones, when the
View > Word wrap
option is set AND the current line is split on several lines, your macro does not seem to work :-((So, I propose this new keys sequence :
<Macro name="AddLineAutoIndented" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2451" wParam="0" lParam="0" sParam="" /> <!-- SCI_LINEENDWRAP = End --> <Action type="0" message="2451" wParam="0" lParam="0" sParam="" /> <!-- SCI_LINEENDWRAP = End --> <Action type="0" message="2469" wParam="0" lParam="0" sParam="" /> <!-- SCI_SELECTION DUPLICATE = Ctrl-D --> <Action type="0" message="2306" wParam="0" lParam="0" sParam="" /> <!-- SCI_CHARRIGHT = Right --> <Action type="0" message="2453" wParam="0" lParam="0" sParam="" /> <!-- SCI_LINEHOMEWRAP = Home --> <Action type="0" message="2396" wParam="0" lParam="0" sParam="" /> <!-- SCI_DELLINERIGHT = Ctrl-Shift-Del --> </Macro>
Notes :
-
After the two
End
sequences, you are sure that the cursor is at the true end of the current line, whatever its previous location -
The
Right
sequence, after duplication of the current line, places the cursor at the very beginning of the duplicated line ( at column1
) -
Then the
Home
sequence move the cursor after any possible indentation of the duplicated line or leave it at position1
if the line is not indented -
Finally, the
Ctrl-Shift-Del
sequence delete any character, from current position to the very end of the duplicated line
You may test my macro against the example text, below, from the license.txt file :
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. The licenses for most software are designed to take away your freedom to share and change it. The licenses for most software are designed to take away your freedom to share and change it.
Of course, select the
Word wrap
option, if you want to easily see the different steps, during manual executionCheers,
guy038
-
-
Thank you Peter and guy038,
Both solutions are very elegant, but I chose to use guy038’s - it works like a champ! This make coding with auto-complete symbols and tags so much easier.
I cut my programming teeth editing in Wordstar on CP/M machines (ok, my age is showing and many of you young folks have no clue what I’m talking about.) This was before there were cursor directional keys and all cursor movements were done with <Ctrl>-? sequences. I’m a relatively fast touch typist and hate leaving the home row to find <End>, <Home>, <Left-arrow> etc. I’ve also swapped the position of the <Ctrl> and <Caps lock> keys (registry hack) to put <Ctrl> back where God (and IBM) intended to be.
Thanks again for your help.
Cheers,
Russ