EditKeys plugin for Take Command / TCC / TCC/LE

beta version 0.99.12.2     2024-04-02

Charles Dye

Purpose:

This plugin adds a number of new keystrokes to the TCC command line. Features include hotkeys to exchange two characters or two arguments, insert the arguments from the previous command, clear the screen, do math, or expand an expression. You can easily enter Unicode characters by hex value or get the Unicode value of the character at the cursor. You can flip the case of the word at the cursor.

You can also copy the current command line to the clipboard, and copy or cut the word at the cursor. You can scroll up or down by commands.

You can print a picture of the console window, or the last 100 lines of the command history.

Key assignments can be changed or deleted.


EditKeys combines, updates, and replaces several of my earlier plugins, including AllArgs, CharValue, ClearKey, CMath, CopyLine, QuickEval, Scrolly, and SwapArgs.

Installation:

To use this plugin, copy EditKeys.dll and EditKeys.chm to some known location on your hard drive. (If you are still using the 32-bit version of Take Command, take EditKeys-x86.dll instead of EditKeys.dll.) Load the .DLL file with a PLUGIN /L command, for example:

plugin /l c:\bin\tcmd\test\editkeys.dll

If you copy these files to a subdirectory named PlugIns within your Take Command program directory, the plugin will be loaded automatically when TCC starts.

Plugin Features:

New Hotkeys:
Swap CharactersSwap ArgumentsInsert Last ArgsClear Screen
Math WordExpand ExpressionUnicode EntryCopy Line
Copy WordCut WordSwap Clipboard WordChange Word Case
Custom InsertCharacter InfoScroll Up By CommandsScroll Down By Commands
File To URIPrint Viewport PictureSave Viewport PicturePrint History
Search Path and ExpandAuto Close
New Command:
EDITKEYS
Other Features:
CMath

Syntax Note:

The syntax definitions in the following text use these conventions for clarity:

BOLD CODEindicates text which must be typed exactly as shown.
CODEindicates optional text, which may be typed as shown or omitted.
Bold italicnames a required argument; a value must be supplied.
Regular italicnames an optional argument.
ellipsis…after an argument means that more than one may be given.

New Hotkeys:

Alt-;: Swap Characters

The character under the cursor will be exchanged with the one before it. If the cursor is at the start or the end of the command line, the two characters closest to the cursor will be exchanged.

Alt-; is the default hotkey for this action, but you can change it with EDITKEYS /K1:key.



Alt-': Swap Arguments

Exchanges the two arguments before the cursor. Inside a function, arguments are separated by commas. Outside of a function, arguments are space-delimited words.

Alt-' is the default hotkey for this action, but you can change it with EDITKEYS /K2:key.



F3: Insert Last Args

All arguments from the previous command will be inserted at the cursor.

You can use EDITKEYS /A:n to tweak the way this key works. n is a bitmapped value; the default value is 2 (break on slash).

Value:Feature:
1Overwrite
2Break on slash
4Keep old args
8Space around args

Overwrite: Normally, pressing F3 inserts the last command’s arguments at the cursor, and pushes any remaining text right. If you set this bit, then the last command’s args will replace everything to the right of the cursor.

Break on slash: If this bit is set, an unquoted slash in the command is treated as the start of its arguments. This is useful if you are in the habit of not spacing between a command and its options, e.g. DIR/A/W.

Keep old args: This bit controls what happens when a command with no arguments — a one-word command — is entered. The default behavior is to discard any arguments from the previous command. If you set this bit, the plugin will instead retain the last set of arguments across any “argless” commands.

Space around args: By default, the last command’s arguments are inserted into the command line verbatim. If this bit is set, the plugin will automatically add spaces between the inserted arguments and any text already on the command line.


F3 is the default hotkey for this action, but you can change it with EDITKEYS /K3:key.



Alt-L: Clear Screen

This key doesn’t actually clear the screen; it scrolls the screen so the current command line is at the top. Unless the cursor is very close to the bottom of the console buffer, no text will be lost.

Alt-L is the default hotkey for this action, but you can change it with EDITKEYS /K4:key.



Alt-=: Math Word

The space-delimited word at the cursor will be evaluated as a math expression.

If you want to use spaces in your expression, wrap it in double quotes. They will be removed before the expression is evaluated.

•  Note:  = is the plus-and-equals key on the main keyboard. TCC version 24 and later will call it “Plus”, but it’s still the plus-and-equals key, not the plus-sign key on the numeric keypad. Take Command uses Alt-Num- and Alt-Num+ to change the font size.

Alt-= is the default hotkey for this action, but you can change it with EDITKEYS /K5:key.



Ctrl-Shift-X: Expand Expression

The variable or function at the cursor will be expanded.

If you have functions or variables nested within functions, the innermost variable or function at the cursor will be expanded. You can press Ctrl-Shift-X repeatedly to expand nested functions from the inside out.

This hotkey also recognizes funky constructions like %((math)) and %[[conditional]], provided they are properly closed: two consecutive close parentheses or close brackets.

Ctrl-Shift-X is the default hotkey for this action, but you can change it with EDITKEYS /K6:key.



Alt-U: Unicode Entry

Enter a Unicode character as a series of hexadecimal digits. To exit this mode, type any printable character other than a hex digit, or press Esc or End.

Characters outside the BMP are supported. For example, you can type Alt-U 1 F 4 3 1 to produce a cat face emoji.

Alt-U is the default hotkey for this action, but you can change it with EDITKEYS /K7:key.



Alt-C: Copy Line

Copies the current command line to the clipboard. The entire command line is copied; there is no need to highlight or select text first.

If the command line is empty, nothing happens. The clipboard is not emptied.

The plugin will chime to let you know that the copy succeeded. You can change or disable the chime with EDITKEYS /C:n.

Alt-C is the default hotkey for this action, but you can change it with EDITKEYS /K8:key.



Alt-W: Copy Word

Copies the space-delimited word at the cursor to the clipboard. There is no need to highlight or select text first.

If there is no word at the cursor, nothing happens. The clipboard is not emptied.

The plugin will chime to let you know that the copy succeeded. You can change or disable the chime with EDITKEYS /C:n.

Alt-W is the default hotkey for this action, but you can change it with EDITKEYS /K9:key.



Ctrl-Alt-W: Cut Word

Cuts the space-delimited word at the cursor to the clipboard. There is no need to highlight or select text first.

If there is no word at the cursor, nothing happens. The clipboard is not emptied.

Ctrl-Alt-W is the default hotkey for this action, but you can change it with EDITKEYS /K10:key.



Ctrl-Alt-Z: Swap Clipboard Word

Exchanges the word at the cursor with the word on the clipboard. This action combines a one-word cut and a one-word paste in a single keystroke.

If there is no word at the cursor, the plugin will beep and nothing will happen; the clipboard will not be emptied.

If there is no text on the clipboard, the word at the cursor will be cut to the clipboard. If there is more than one word on the clipboard, only the first word will be pasted; everything else will be lost.

Ctrl-Alt-Z is the default hotkey for this action, but you can change it with EDITKEYS /K11:key.



Ctrl-U: Change Word Case

Changes the case of the word at the cursor. Pressing this key repeatedly cycles the word: lowercase → Initial Caps → UPPERCASE →  lowercase…

Ctrl-U is the default hotkey for this action, but you can change it with EDITKEYS /K12:key.



Alt-I: Custom Insert

Performs variable expansion on an environment variable, and insert the results at the cursor. You can define up to three variables, each with its own hotkey(s).

nDefault Hotkey:Set Hotkey With:Environment Variable:
1Alt-IEDITKEYS /K13:keyInsert-1
2noneEDITKEYS /K14:keyInsert-2
3noneEDITKEYS /K15:keyInsert-3

You can use internal variables and functions in the environment variable. Be sure to either double all percent signs, or else enclose the entire value in strong quotes, when you SET the variable.

If the corresponding environment variable is not defined, the plugin will use %_ISODATE as a default value. If the variable is defined, but variable expansion produces an empty string, the plugin will beep.


rem   Use Alt-T to insert the current time:
editkeys /k14:alt-t
set insert-2=`%_time`

rem   Use Alt-N for the current directory's name:
editkeys /k15:alt-n
set insert-3=`%@name[%_cwd]`

EDITKEYS /S saves the three environment variables Insert-1, Insert-2, and Insert-3 to the registry. They will be restored when the plugin is reloaded, or by EDITKEYS /R.



Ctrl-A: Character Info

Shows information about the character at the cursor. You get the character’s Unicode value in hex and decimal, its UTF-8 encoding, and — if its value is higher than 0xFFFF — its UTF-16 encoding. If TCC is running in Take Command, character info will be displayed in the status bar. If TCC is in a standalone console window, you’ll get a popup window.

Ctrl-A is the default hotkey for this action, but you can change it with EDITKEYS /K16:key.



Ctrl-Alt-Up: Scroll Up By Commands

Every time you press Enter, this plugin marks the start of the current command line in the screen buffer. You can’t see the mark, but it’s there.

When you press Ctrl-Alt-Up, the plugin searches the screen buffer for marked lines, and scrolls the screen up to the previous mark. Only commands entered after the plugin was loaded are recognized, because they are the only ones marked.

If you scroll up past the top of the screen buffer, the default behavior is to wrap around to the bottom. You can change this behavior with EDITKEYS /Y:n.

Ctrl-Alt-Up is the default hotkey for this action, but you can change it with EDITKEYS /K17:key.



Ctrl-Alt-Down: Scroll Down By Commands

Every time you press Enter, this plugin marks the start of the current command line in the screen buffer. You can’t see the mark, but it’s there.

When you press Ctrl-Alt-Down, the plugin searches the screen buffer for marked lines, and scrolls the screen down to the next mark. Only commands entered after the plugin was loaded are recognized, because they are the only ones marked.

If you scroll down below the bottom of the screen buffer, the default behavior is to wrap around to the top. You can change this behavior with EDITKEYS /Y:n.

Ctrl-Alt-Down is the default hotkey for this action, but you can change it with EDITKEYS /K18:key.



Ctrl-Alt-F: File To URI

Toggles the word at the cursor from a filename to a file:/// URI, or vice versa.

This hotkey attempts to change the space-delimited word at the cursor. It knows nothing about function arguments, commas, or other argument separators. If you want to use it on a filename inside a function, you must supply spaces around the filename.

Ctrl-Alt-F is the default hotkey for this action, but you can change it with EDITKEYS /K19:key.



Ctrl-Shift-P: Print Viewport Picture

Prints the visible portion of the console buffer to the default printer.

A screenshot of the console window will be saved as a .PNG file, and then printed using the default handler.


•  Note:  Exactly how your system prints a .PNG file depends on your file assocations. To troubleshoot, you can use Ctrl-Shift-Q to save a .PNG file to your desktop; then right-click on it and choose Print to see what the system does.

Ctrl-Shift-P is the default hotkey for this action, but you can change it with EDITKEYS /K20:key.



Ctrl-Shift-Q: Save Viewport Picture

Saves the visible portion of the console buffer to a .PNG file.

This action is a variant of Print Viewport Picture. Instead of being printed, the file will be saved to the desktop. Two environment variables are available to customize this action:

Variable NameDefaultDescription
SavePicDiruser’s desktoplocation to save files
SavePicExt.PNGfile type for saved pictures

Ctrl-Shift-Q is the default hotkey for this action, but you can change it with EDITKEYS /K21:key.



Ctrl-P: Print History

Prints the last 100 lines of the command history to the default printer.

History lines will be saved as a .TXT file, and then printed using the default handler. Two environment variables are available to customize this action:

Variable NameDefaultDescription
PrintHistoryMaxLines100The maximum number of lines to print.
PrintHistoryFlags0Set to 1 to print line numbers.

History lines are numbered starting with the oldest as #1. If there are more than 100 history lines (or PrintHistoryMaxLines) in memory, then the first line printed will be greater than 1.


•  Note:  Exactly how your system prints a .TXT file depends on your file associations. To troubleshoot, you can create a text file on your desktop; then right-click on it and choose Print to see what the system does.

Ctrl-P is the default hotkey for this action, but you can change it with EDITKEYS /K22:key.



Ctrl-Alt-E: Search Path and Expand

Searches the path for a command or file matching the word at the cursor. The full filename of the first matching file will be returned. (Only the first; there is no provision for handling multiple matches.)

There is one environment variable available to customize this action:

Variable NameDefaultDescription
PathExpandFlags6Bitmapped:
1search the current directory before %PATH
2search the registry App Paths before %PATH
4check the environment for executable extensions
64return only the filename, not its complete path
128automatically expand REG_EXPAND_SZ values

Ctrl-Alt-E is the default hotkey for this action, but you can change it with EDITKEYS /K23:key.



[, (, {, ", ', `: Auto Close

This feature is disabled by default. You can use EDITKEYS /B:n to enable auto-close for any or all of these punctuation marks. n is a bitmapped value:

Value:Feature:
1Square brackets[ ]
2Parentheses( )
4Braces{ }
8Quotation marks" "
16Apostrophes' '
32Strong quotes` `

The default is zero, don’t auto-close anything. Note that this feature only works in insert mode. It is automatically disabled in overstrike mode, where it makes no sense.



New Command:

EDITKEYS — Display and change plugin settings.

Syntax:
EDITKEYS /A:n /B:n /C:n /D /E:n /Kn:key /L /Q /R /S /X:key /Y:n

/A:nchange the LastArgs flags2
/B:nchange the auto-close flags0
/C:nchange the copy chime sound1
/Drestore default plugin settings
/E:nchange the error sound2
/Kn:keydefine or change a hotkey
/Llist all supported hotkeys
/Qquietly
/Rrestore saved settings from the registry
/Ssave the current settings to the registry
/X:keydelete a hotkey
/Y:nchange the Scrolly flags1

EDITKEYS with no options displays the plugin’s current settings.


/Kn:key assigns a hotkey to an action. n is the action number, and key is the name of the key to perform that action:

nAction:Default:
1Swap CharactersAlt-;
2Swap ArgumentsAlt-'
3Insert Last ArgsF3
4Clear ScreenAlt-L
5Math WordAlt-=
6Expand ExpressionCtrl-Shift-X
7Unicode EntryAlt-U
8Copy LineAlt-C
9Copy WordAlt-W
10Cut WordCtrl-Alt-W
11Swap Clipboard WordCtrl-Alt-Z
12Change Word CaseCtrl-U
13Custom Insert 1Alt-I
14Custom Insert 2
15Custom Insert 3
16Character InfoCtrl-A
17Scroll Up By CommandsCtrl-Alt-Up
18Scroll Down By CommandsCtrl-Alt-Down
19File To URICtrl-Alt-F
20Print Viewport PictureCtrl-Shift-P
21Save Viewport PictureCtrl-Shift-Q
22Print HistoryCtrl-P
23Search Path and ExpandCtrl-Alt-E

A hotkey can only perform one action. If a key is assigned to an action, you can use /K to reassign it; the new action will replace the old one. On the other hand, you can assign multiple keys to the same action.

rem   Use Ctrl-Alt-C to clear the screen:
editkeys /k4:ctrl-alt-c


/X:key lets you delete a hotkey. key is the key’s name, e.g. Alt-L.

rem   Remove the Alt-L hotkey:
editkeys /x:alt-l


/E:n allows you to change the sound the plugin makes when an error is encountered.

n:Sound:
0none
1TCC’s internal beep
2the Windows “Asterisk” sound
3the Windows “Default Beep” sound
4the Windows “Exclamation” sound
5the Windows “Critical Stop” sound
6the Windows “Question” sound

Sound number 1 can be customized via the Option dialog; look for the “Default beep” settings on the Advanced tab. Numbers 2 through 6 can be redefined in the Control Panel “Sound” applet.


/C:n lets you change the sound the plugin makes when text is copied to the clipboard.

n:Sound:
0none
1chime sound (built into the plugin)
2the Windows “Asterisk” sound
3the Windows “Default Beep” sound
4the Windows “Exclamation” sound
5the Windows “Critical Stop” sound
6the Windows “Question” sound

Numbers 2 through 6 can be redefined in the Control Panel “Sound” applet.


/A:n sets options which affect the insert last args hotkey. n is a bitmapped value:

Value:Feature:
1Overwrite
2Break on slash
4Keep old args
8Space around args

See insert last args for details on these options.


/B:n determines which characters are automatically closed as you type them. n is a bitmapped value:

Value:Feature:
1Square brackets[ ]
2Parentheses( )
4Braces{ }
8Quotation marks" "
16Apostrophes' '
32Strong quotes` `

The default is zero, don’t auto-close anything. Note that this feature only works in insert mode. It is automatically disabled in overstrike mode, where it makes no sense.

rem   Auto-close square brackets and parentheses:
editkeys /b:3


/Y:n sets options which affect the Scroll Up and and Down By Commands feature. n is a bitmapped value:

Value:Feature:
1Wrap around
2Visible marks (debugging feature)

/D restores the original plugin default settings (shown in the third column of the table above) and the default hotkey assignments (shown in the third column of this table). Environment variables will not be affected.

/R restores the settings, hotkey assignments, and environment variables saved to the registry, if any. If you specify both /D and /R, EditKeys will try to read settings from the registry first, and then restore the original plugin defaults only if restoring from the registry failed.

/S saves the current settings, including hotkey assignments and environment variables, to the registry. They will be loaded automatically the next time you load this plugin.


/S and /R save and restore these environment variables:

Variable Name:Function:
Insert-1Custom insert string #1
Insert-2Custom insert string #2
Insert-3Custom insert string #3
SavePicDirSave location for Save Viewport Picture
SavePicExtFile type for Save Viewport Picture
SavePicFlags
PrintHistoryMaxLinesMaximum lines for Print History to print
PrintHistoryFlagsPrint History features
PathExpandFlagsSearch Path and Expand features

When saving with /S, all of the above environment variables will be saved to the registry if defined. If a variable is not defined, it will be deleted from the registry.

When restoring with /R, any of the above variables which are saved to the registry will be restored to the environment. However, if a variable is not present in the registry, it will not be deleted from the environment.



Other Features:

CMath — Evaluate a math expression at the command line.

To evaluate a math expression, type a colon followed by the expression. Then press Enter:

:1+2*3

The answer, 7, will be displayed below your expression. It will also be saved to the environment variable ANS. You can use this variable in your next expression:

:ans*2

Just remember that the value of ANS changes every time you use CMath. After the second line, ANS will be 14, not 7.


CMath calls the same function that @EVAL uses internally. You can use any operator or function that is legal in @EVAL:

:log(100)


set r=4
:pi*r**2



You do not need to quote or escape special characters:

:(1+2)*3


:1 << 8


:1024 >> 3


:5 & 9


:5 | 9


:5 ^ 9



The one special character which needs attention is the percent sign. If you want to use a percent sign as the modulo operator, you will need to double it. (But it’s probably easier just to type MOD.)

:100%%7


:100 mod 7



You do not need a percent sign before environment variables. You do need a percent sign before internal variables and variable functions:

:%_pid =x


:3 * %@dec[foo]



@EVAL’s built-in functions do not take a percent sign:

set n=52
set r=5
:fact(n) / fact(n-r) / fact(r)


Startup Message:

This plugin displays an informational line when it initializes. The message will be suppressed in transient or pipe shells. You can disable it for all shells by defining an environment variable named NOLOADMSG, for example:

set /e /u noloadmsg=1

Acknowledgments:

The chime sound which plays when you copy text to the clipboard is by Samuel Gremaud. I downloaded it from FreeSound.org and modified it slightly (trimmed it for length and reduced the volume) before including it in the plugin .DLL file.

Status and Licensing:

Consider this beta software. It may well have issues. Try it at your own risk. If you find a problem, you can report it in the JP Software support forum.

EditKeys is currently licensed only for testing purposes. I may make binaries and source code available under some free license once I consider it ready for use.

Download:

You can download the current version of the plugin from http://charlesdye.net/dl/editkeys.zip.