Modify cmd.exe properties using the command prompt - command-line

Isn't that nicely recursive?
I've got a portable command prompt on my external drive, and it has a nice .bat file to configure some initial settings, but I'd like more!
Here's what I know how to set from .bat:
Colors = (color XY) where x and y are hex digits for the predefined colors
Prompt = (prompt $p$g) sets the prompt to "C:\etc\etc >" the default prompt
Title = (title "text") sets the window title to "text"
Screen Size = (mode con: cols=XX lines=YY) sets the columns and lines size of the window
Path = (SET PATH=%~d0\bin;%PATH%) sets up local path to my tools and appends the computer's path
So that's all great. But there are a few settings I can't seem to set from the bat. Like, how would I set these up wihtout using the Properties dialogue:
Buffer = not screen size, but the buffer
Options like quick edit mode and autocomplete
Popup colors
Font. And can you use a font on the portable drive, or must it be installed to work?
Command history options

Regarding setting the buffer size:
Using mode con: cols=XX lines=YY sets not only the window (screen) size, but the buffer size too.
If you specify a size allowed by your system, based on available screen size, you'll see that both window and buffer dimension are set to the same value; .e.g:
mode con: cols=100 lines=30
results in the following (values are the same):
window size: Width=160, Height=78
buffer size: Width=160, Height=78
By contrast, if you specify values that are too large based on the available screen size, you'll see that the window size changes to its maximum, but the buffer size is changed to the values as specified.
mode con: cols=1600 lines=900
With a screen resolution of 1280x1024, you'll get:
window size: Width=160, Height=78
buffer size: Width=1600, Height=900

You can set these values through a shortcut (.INK file).
I have a shortcut on my desktop with this as the target:
%windir%\system32\cmd.exe /K %userprofile%\STARTUP.CMD
The /K switch tells CMD.exe to run the batch file (which sets some variables, the prompt, etc.) and then stay open.
If you right-click on the shortcut and view its properties, you can set the window and buffer size, popup colors, starting position (x,y axis), etc. The settings will be saved in the shortcut itself and will be applied every time you open CMD.exe using that shortcut.

Regarding auto-completion:
File and Directory name completion is
NOT enabled by default. You can
enable or disable file name completion
for a particular invocation of CMD.EXE
with the /F:ON or /F:OFF switch. You
can enable or disable completion for
all invocations of CMD.EXE on a
machine and/or user logon session by
setting either or both of the
following REG_DWORD values in the
registry using REGEDT32.EXE:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar
and/or
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar
with the hex value of a control
character to use for a particular
function (e.g. 0x4 is Ctrl-D and 0x6
is Ctrl-F). The user specific
settings take precedence over the
machine settings. The command line
switches take precedence over the
registry settings.
If completion is enabled with the
/F:ON switch, the two control
characters used are Ctrl-D for
directory name completion and Ctrl-F
for file name completion. To disable
a particular completion character in
the registry, use the value for space
(0x20) as it is not a valid control
character.
Couldn't find any command history options in there ( cmd /? ), and it looks like the other options you asked about are set exclusively through registry settings.

For true Buffer Size adjustment use DOSKEY /LISTSIZE=size
You can't change colors within the shell anymore since Microsoft took ANSI ESC control out of the command/cmd prompts.

Related

how to set variables interactively for ediff

I'm using ediff mode, and I'd like to split the windows horizontally instead of the vertical default. The ediff manual says this can be done interactively.
ediff-split-window-function
Controls the way you want the window be split between file-A and
file-B (and file-C, if applicable). It defaults to the vertical split
(split-window-vertically, but you can set it to
split-window-horizontally, if you so wish. Ediff also lets you switch
from vertical to horizontal split and back interactively.
Note that if Ediff detects that all the buffers it compares are
displayed in separate frames, it assumes that the user wants them to
be so displayed and stops splitting windows. Instead, it arranges for
each buffer to be displayed in a separate frame. You can switch to the
one-frame mode by hiding one of the buffers A/B/C.
You can also swap the windows where buffers are displayed by typing ~
I've tried using M-x set-variable to set this variable to split-window-horiztonally, but that did not change the layout. I want to do this interactively, I know I can set it as default in .emacs but I dont want to do that at this stage.
I want to do this interactively, I know I can set it as default in .emacs but I dont want to do that at this stage.
Type |
(n.b. that's the | pipe character; as opposed to I or l or 1.)
You should probably also type ? and review the information it shows you.

Ansi-coloured file editing

Context
Have some transcript files from terminal interaction, obtained using traditional Unix command "script".
Those transcripts contain lots of control character (like backspace when editing shell commands), and lots of color code sequences as result of running various commands. Occasionally, even colorful full-terminal (ncurses-based) applications like "emacs -nw" or "aptitude" were run.
At program runtime, TERM environment variable was set as "xterm".
Need 1: read (more or less solved)
I need to read those files again and sometimes copy-paste some small parts.
The trouble is : while one color change here and there is not so much of a problem, their actual density makes the output barely readable. Worse, edited command lines (with cursor jumps and edited words) are completely unreadable.
"Okay" solution
Browse through files using e.g. "less -r". Paging forward in the same terminal setup reproduces the various color and character style.
But many other features come out more or less broken, e.g. search backwards produces jumbled terminal output, often have to pres "Ctrl-L" to clean thing up.
Need 2: editing
My preferred editor is emacs. Some people have had a similar situation when running the shell inside emacs, e.g. Something wrong with Emacs shell.
Here is not the same situation. Examples of differences: here we don't have to run an actual shell, but we need to move cursor freely like in usual editing.
Editing here means easily open such a transcript file in editor and then:
at all times through editing, see character changes (color, attributes) as conveyed by the terminal codes
(optional) some character that are neighbour on the terminal grid but are separated in file by some control characters would have a visual hint about this
ability to insert some text,
delete sections,
use all editor features like search/replace etc.
copy & paste to & from file (including to external programs, which would receive just plain text)
in my wildest dreams, some kind of "flatten" action, like select a sequence with a heavily edited command line and replace it with a simple series of characters as if it was typed in one run. "Visual hints" mentioned above would disappear.
Type Alt-: to evaluate something in the minibuffer. Evaluate (ansi-color-apply-on-region (point-min) (point-max)) and it will convert ansi color codes to be font colors.

How to have find-file's prompt match Emacs shell's $PWD?

With Emacs, if the current buffer is one that's "visiting" a normal file (for example), whose full pathname is /path/to/somefile, and one runs find-file (C-x C-f), the prompt that appears in the mini-buffer is something like
Find file: /path/to/▮
...with the cursor placed as indicated above by ▮. IOW, the suggested path shown by default is always to the directory containing the file that the current buffer is visiting.
If, however, the current buffer is an Emacs shell process, and one runs find-file, then, AFAICT, the path shown in the prompt remains fixed at the value of $PWD when the shell process was started, irrespective of the current value of $PWD:
Find file: /pwd/at/startup/▮
This behavior is not so useful, because the $PWD at startup often becomes irrelevant later on. It would be really nice if the directory shown in find-file's prompt were instead the shell process's current $PWD.
Is there a simple way to modify find-file to behave this way whenever the current buffer is a shell process?
You want "shell directory tracking". E.g. check dirtrack-mode or shell-dirtrack-mode.
shell-dirtrack-mode tries to parse "cd" commands, (event_jr: which in my experience does not work consistently). dirtrack-mode uses the prompt regexp, which works very well.
There are a number of ways to manage this. As Stefan notes, there are a couple of built in packages that manage it.
My preferred way is to alter your prompt (when in Emacs) to have the $PWD embedded in it, and then Emacs strips it out and uses it. This has the benefit of always being up to date. I've found that dirtrack-mode sometimes gets out of sync.
Check out my solution here, which is a modification of a similar implementation on the Emacs Wiki.

Emacs: How can I automatically start a python interpreter in python-mode?

After every Emacs startup in python-mode I need to open the interpreter in a different buffer and
change the size of the new buffer that it fits emacs-code-browser's history. I want to automate
this activity.
How can I automate that an interactive python shell always appears (after Emacs startup) in an extra buffer like in the screenshot?
UPDATE: See below: workgroups.el and emacs-code-browser seem to collide. See screenshot
Before Editing
After Editing
I use Emacs23, emacs-code-browser and python-mode.el.
UPDATE: I tried to use workgroups.el. I defined a new python workgroup and added the following line to my .emacs: (wg-load "~/.emacs.d/workgroups/python_workgroup.wg"). The windows are, however, messed up. You can see it on the screenshot below:
It think that emacs-code-browser and the settings of my workgroup collide. Is there a way
to avoid this behavior?
also you may try desktop-save-mode:
desktop-save-mode is an interactive autoloaded Lisp
function.
(desktop-save-mode &optional ARG)
Toggle desktop saving (Desktop Save mode).
With a prefix argument ARG, enable Desktop Save mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
If Desktop Save mode is enabled, the state of Emacs is saved from
one session to another. See variable desktop-save' and function
desktop-read' for details.
How about using workgroups.el ?
It is used for saving your window configuration which is exactly what you need.
This way you can create a workgroup called for example Python, adjust buffers (including one containing interactive python shell) and everything and save the group, and next time you just open workgroup Python and all buffers open as they were before. If you want it to open automatically when emacs is started, just set your saved Python workgroup as a default workgroup.

pause shell output

In windows shell it's possible to pause the output just by selecting a text in the shell window (a QuickEdit mode must be enabled). The same is possible in the cygwin shell (again with a QuickEdit mode).
How can I pause the output in emacs shell?
I need to pause it because some tasks are very verbose and it's difficult to search the necessary text in a big buffer.
When I execute M-x comint-stop-subjob I get a message "No SIGTSTP support"
As an example try to pause the following:
find . -type f -name "*.txt" -exec cat {} ';'
Not exactly what you asked for, but clone-buffer will get you close to what you want. After binding it to a convenient key and running your find command, calling clone-buffer will copy the contents of the buffer to a new buffer. The find command in the original buffer keeps running, but the cloned buffer contains only the output of find up to the point that you cloned it.
You can invoke this command multiple times in the original window, giving you a series of stop points to examine. I don't know how to actually pause the original window though.
Note that the newly cloned buffers are fully functional shell buffers.
You can stop the job by pressing C-c C-z. Then just enter fg to make it work again.
I don't know about pausing the output, but you can presumably just narrow the buffer?
C-xnn to narrow-to-region
C-xnn to narrow-to-page
C-xnw to widen to full buffer