QuickEval plugin for Take Command / TCC / TCC/LE

Version 1.31.0     2023-10-13

Charles Dye

Purpose:

This plugin provides a quick way to expand a variable or function, or do math, while composing a command line. When you press a hotkey, the variable or function at the cursor will be replaced with its value.

Installation:

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

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

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

Using QuickEval:

While typing a command line, move the cursor to a variable or function and press the variable-expansion hotkey (the default is Alt-X.) QuickEval will scan the command line and attempt to find an expression at the cursor position. If an expression is found, it will be expanded and the resulting value inserted into the original command line.

There is also a key to evaluate a mathematical expression at the cursor. Press the math hotkey (Alt-= by default) and the word at the cursor will be evaluated via TCC’s Evaluate() function. The value returned by Evaluate() will replace the word at the cursor.

QuickEval will beep if any error occurs. You can disable the error beep with QUICKEVAL /B:0.

QuickEval command:

This new command allows you to display or change options for the QuickEval plugin. The syntax is:

QUICKEVAL /B:n /D /L /Q /R /S expandkey mathkey

/B:nSet the error beep mode. n is 0 through 6; the default is 2.
/DRestore the original plugin default settings.
/LDump a list of all supported hotkeys to standard output.
/QQuietly.
/RRestore the previously saved options from the registry.
/SSave the current settings to the registry as the new default.
expandkeythe hotkey you will use to expand the variable or function at the cursor
mathkeythe hotkey you will use to evaluate the mathmatical expression at the cursor

Some examples of valid hotkeys are Alt-X, Alt-=, F2, or Shift-F10. The default expansion hotkey is Alt-X. The default math hotkey is Alt-=.

•  Note: Many of the hotkeys you can set are already used by Take Command, TCC, or Windows itself. If you change a hotkey and pressing it doesn’t work or causes strange things to happen, try reverting to the default values with QUICKEVAL /D. If those work as expected, the hotkey you tried is already used for some other function; try a different one.


The variable expansion hotkey evaluates the variable or function at the cursor. What happens if the cursor is on a variable or function which is inside another function? QuickEval evaluates the innermost expression. If the cursor is on a variable which is inside a function, which is inside another function…, then successive presses of Alt-X will evaluate them from the inside out. Want to expand a function, with all its arguments, all at once? Move the cursor onto the name of the function, or onto one of the brackets enclosing its arguments, and then press Alt-X.

The math hotkey evaluates the word at the cursor; it looks for a string of characters delimited by spaces. If you want to use spaces in the expression, quote it. The word from the command line will be passed to TCC’s internal Evaluate() function, and whatever Evaluate() returns will replace the original word in the command line. You can use any operators, functions, or format specifiers that @EVAL supports. For example, you can type a value like 912559=X and press Alt-= to convert it to hexadecimal. Pressing Alt-= a second time will convert it back to decimal.


/B:n sets the sound made on an error. Possible values of n are:

n:Sound:
0Off (disabled)
1Honk (TCC’s internal beep)
2Asterisk
3Default
4Exclamation
5Hand (“Critical Stop”)
6Question

You can tweak TCC’s internal Honk() sound via the settings under “Default beep” on the Advanced tab of the Options dialog. Sounds 2 through 6 can be changed with the Sound applet in Control Panel.


/S saves QuickEval’s current settings to the registry; they will be used by default the next time you load the plugin. The settings saved are the current hotkeys and the error beep setting. All settings are saved under the key HKCU\Software\JPPlugins\QuickEval.

/R attempts to restore any saved settings from the registry. /D resets the plugin to its built-in default settings: the hotkeys are Alt-X and Alt-=, and the error sound is 2. You cannot combine /D with /R.


/L displays a list of all the hotkeys which this plugin allows. You may not combine /L with any other option.

•  Note: The plugin hook for hotkeys has changed in version 24. The set of keys available, and their names, is different. Also, key names can refer to more than one key. For example, the = is now called Plus, and the + key on the numeric keypad is also called Plus. This can cause confusion! The default key to do math has not changed — it’s still Alt-= — but the plugin calls it Alt-Plus if you’re running TCC v24 or later. Don’t confuse it with the + key on the keypad. Take Command uses Alt-+ to increase the font size….

Limits and Limitations:

The maximum command line length is 65,535 characters, both before and after expansion. Exceeding this limit will make Bad Things happen.

QuickEval understands the structure of environment variables, internal variables, functions, array variables, and the %+ and %= pseudovariables. It can also recognize %((math)) and %[[conditional]] constructs provided they are properly closed: two consecutive close parentheses or close brackets.

QuickEval does not understand positional parameters (alias/batch file parameters) like %1, %5$, or %-2$. Since these parameters cannot be expanded at the command line anyway, this limitation should not be an issue.

QuickEval has a limited understanding of double quotes and escapes. It does not recognize strong quotes (backquotes).

QuickEval cannot recognize or understand anthropomorphism.

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:

Steve Fábián provided the original idea for this plugin.

Changes:


1.31.0.12023-10-13Updated the plugin’s web address.
1.31.02022-12-09Added support for %(command) (exit code of command) and %{command} (first line of command’s stdout).
1.30.02022-05-24Massively rewritten to use ExpandExpression.cpp and MathWord.cpp from EditKeys. /B:n now accepts values from 0 to 6 to allow for several different error sounds. Added /Q (quiet) and the semi-undocumented /S! to save the current settings to HKLM (requires elevation). Many other updates to make it behave more like my other plugins.
1.20.52021-09-28tweaks to the version info structure; minor code cleanup
1.20.42021-05-20changes the .DLL names; QuickEval.dll is now the 64-bit build
1.20.32018-12-03changes for TCC v24 compatibility
1.10.32014-10-20minor tweaks to DoMath()
1.10.22014-06-24bug fix: correctly check handle returned by CreateFile()
1.10.12014-05-14math hotkey recognizes quotes
1.10.02014-05-09added math hotkey Alt-=; Ctrl-\ allowed
1.0.02013-04-25first release

Status and Licensing:

This software is copyright © 2023, Charles Dye.

The binaries and documentation for this plugin may be freely redistributed without restriction. I make no guarantee and give no warranty for its operation. If you find a problem, you can report it in the JP Software support forum.

Download:

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