Taming term-mode
First attempt
You can skip this and scroll down to the
solution or read it to see some of the
problems I was having with term.el
.
Problems with term.el
Any minor mode which is enabled while term is running will override bindings
Therefore, if you can, make any such bindings that may interfere with term into global mappings instead.
|
|
gud-mode
stole C-c C-a
C-a
is important in many programs for going to the start of the line.
gud-mode
creates a global prefix before we have time to prevent that from happening
Load this early before gud
is required
That way it will set its global binding to this prefix instead.
|
|
If you can, disable modes that interfere with term using manage-minor-mode
|
|
Give C-a
to term
This is needed so we can use C-a
in whatever
application needs it. Bash recognises C-a
as
the command to go to the start of the line,
for instance.
|
|
Obstacles to fixing term.el
It does not play well with manage-minor-mode.el
Also, manage-minor-mode
is not all-powerful:
you can’t enable a minor mode globally but
disable it for a single major mode, for
instance.
|
|
Ensure line-numbers-mode
, linum-mode
etc. are disabled
It messes up the term.
My line-numbers-mode
was globalised.
Therefore, disabling it with manage-minor-mode
wasn’t an option for me.
|
|
I tried using hooks but, due to the way term is started, the modes were not disabled until after term had exit.
term-load-hook
did nothing at all.
|
|
Therefore, I used advice to turn off my globalised modes. That worked for me.
|
|
The term-raw-mode
escape char is a problem. Reassign it to a key that doesn’t exist
Unfortunately, the C-c
prefix is populated with all manor of things.
There is no way to avoid it.
Reassign this key.
|
|
The solution: It requires a fair bit of emacs lisp
I can’t abolish C-c from all the minor modes, but at least I can control what happens when I press it!
|
|
Another issue is that you can’t have multiple terms unless you rename the buffer
|
|
See one of my other blog posts to see how this is done.
Uniqifying emacs apps // Bodacious Blog
One last issue is that sometimes it’s necessary to resize the program within term
term-mode
appears to only downsize the program but never upsize.
I will try to figure that out and return to this blog post.
Demonstration
enable 256 colors
https://github.com/dieggsy/eterm-256color
enable function keys
Use my function key branch of eterm-256color
Neither the terminfo file eterm-color.ti
nor
eterm-256color.ti
had definitions for the
function keys.
https://github.com/mullikine/eterm-256color/tree/add-function-keys
Add the following loop to term-send-function-key
This creates C-c <f1>
to C-c <f4>
for
sending those function keys through.
You can extend this to include more keys if you wish.
|
|
Finish writing the code. Just use the following
|
|
Adding a sentinel to tell me when the process closes
This means I can create shell scripts which start processes inside emacs and close the emacs frame when done.
|
|
Demonstration
Spacemacs needed me to remove this. It ignored the sentinel i made to force the way term-closes
|
|
Found it!
|
|
|
|
Solution
|
|
Preventing window margins from interfering with term
The problem makes term almost unusable.
Therefore, fixing it is important.
This appears to solve the problem
|
|
If this article appears incomplete, it may be intentional. Try prompting for a continuation.