-
Notifications
You must be signed in to change notification settings - Fork 6
/
mistty.texi
2075 lines (1486 loc) · 65.9 KB
/
mistty.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename mistty.info
@documentencoding UTF-8
@ifinfo
@*Generated by Sphinx.@*
@end ifinfo
@settitle MisTTY
@defindex ge
@paragraphindent 0
@exampleindent 4
@finalout
@dircategory Emacs
@direntry
* MisTTY: (mistty.info). Shell/comint alternative with a fully-functional
terminal
@end direntry
@c %**end of header
@copying
@quotation
MisTTY 1.3.1snapshot
Stephane Zermatten
Copyright @copyright{} 2023-2024, Stephane Zermatten
@end quotation
@end copying
@titlepage
@title MisTTY
@insertcopying
@end titlepage
@contents
@c %** start of user preamble
@c %** end of user preamble
@ifnottex
@node Top
@top MisTTY
@insertcopying
@end ifnottex
@c %**start of body
@anchor{index doc}@anchor{0}
`MisTTY' is a major mode for @code{Emacs} 29.1 and up that runs
a shell inside of a buffer, similarly to comint mode. It is built on
top of @code{term.el}. Check out its project page at
@indicateurl{https://github.com/szermatt/mistty}.
@code{M-x mistty} creates a buffer with an interactive shell. See
@ref{1,,Launching} for details.
MisTTY feels very much like comint mode: you can move around freely
and run any Emacs command you want - until you press TAB and end up
with the native completion or notice the shell autosuggestions. With
MisTTY you have access to both Emacs and the shell commands and
editing tools.
Additionally, commands that take over the @ref{2,,entire screen}, such as @code{less} or @code{vi} also
work, temporarily taking over the window, while scrollback remains
available in another buffer.
MisTTY is known to work on Linux and MacOS. It also supports non-shell
command-line programs, such as @code{python}.
The latest version of this documentation is available at
@indicateurl{https://mistty.readthedocs.io/en/latest/}. Once MisTTY is installed,
this documentation can be accessed from inside Emacs using @code{M-x
info gmistty}
@cartouche
@quotation Note
If you encounter issues, please take the time to file a bug. See
@ref{3,,Reporting issues} for details.
@end quotation
@end cartouche
@menu
* Comparison with other packages::
* Contents::
* Index::
@end menu
@node Comparison with other packages,Contents,Top,Top
@anchor{index comparison-with-other-packages}@anchor{4}@anchor{index mistty}@anchor{5}
@chapter Comparison with other packages
MisTTY isn’t a terminal emulator, but rather a frontend to an existing
terminal emulator, the built-in @code{term.el}. Its goal is to make
it more convenient to use while inside of Emacs and better integrate
with Emacs itself. In theory, other terminal emulators than
@code{term.el} might be used as engine for MisTTY, such as
@code{vterm} and @code{eat}.
MisTTY has some similarities with @code{coterm}; it offers the
same switch between full-screen and line mode.
@code{Coterm}, @code{ansi-term} and @code{eat} all have a
line mode, just like @code{comint} does, which allows you to edit
a command line as a whole before sending it to the shell. While in
line mode, rendering is done by Emacs and editing commands are Emacs
commands. In constrast, with MisTTY, all rendering is done by the
shell through the terminal. This is why native shell completion and
autosuggestion is available with MisTTY and not in line modes and why
you can freely mix shell commands with Emacs commands while editing
the command line.
@code{ansi-term} and @code{eat} also have a char mode, where
rendering and command execution is handled by the shell, and editing
with Emacs isn’t available. The difference with MisTTY is then that
MisTTY makes Emacs editing commands available when possible.
@code{eat} also has a semi-char mode, which is the closest there
is to MisTTY. In that mode, Emacs movements commands are available.
However, Emacs commands that modify the buffer, aren’t available to
edit the command line. In contrast, MisTTY allows Emacs to navigate to
and edit the whole buffer, then replays changes made to the
command-line.
@node Contents,Index,Comparison with other packages,Top
@anchor{index contents}@anchor{6}
@chapter Contents
@menu
* Usage::
* Shells::
* Extending MisTTY::
* FAQ::
* Contributing::
@end menu
@node Usage,Shells,,Contents
@anchor{usage doc}@anchor{7}@anchor{usage usage}@anchor{8}
@section Usage
@menu
* Installation::
* Launching::
* Terminal vs. Scrollback: Terminal vs Scrollback.
* Navigating the scrollback zone::
* Fullscreen Mode::
* Command History::
* Backward Search::
* Completion-at-point::
* Template Expansion::
* Directory Tracking::
* Remote Shells with TRAMP::
* Directory tracking and TRAMP::
* Fancy prompts::
@end menu
@node Installation,Launching,,Usage
@anchor{usage id1}@anchor{9}@anchor{usage installation}@anchor{a}
@subsection Installation
To use MisTTY, first install its package,
@quotation
@itemize -
@item
from MELPA or MELPA Stable@footnote{https://melpa.org/#/getting-started}, using @code{M-x
package-install mistty}
@item
from source using @code{M-x package-vc-install https://github.com/szermatt/mistty}
@end itemize
@end quotation
And then launch it with @code{M-x mistty}, as described in @ref{1,,Launching}.
You’ll likely want to eventually bind that to some shortcut:
@example
(use-package mistty
:bind (("C-c s" . mistty)))
@end example
and, unless you’re using @code{Bash}, configure your shell for
@ref{b,,Directory Tracking}, but read on for more details.
@node Launching,Terminal vs Scrollback,Installation,Usage
@anchor{usage id2}@anchor{c}@anchor{usage launching}@anchor{1}
@subsection Launching
To create a new interactive shell buffer in MisTTY mode, call
@code{M-x mistty}, which either creates a new shell or goes to an
existing MisTTY buffer, or @code{M-x mistty-create}, which creates a
new MisTTY buffer.
Here’s a quick list of the commands defined by the MisTTY package,
their behavior and arguments:
@quotation
@geindex command; mistty-create
@geindex command; mistty
@geindex command; mistty-create-other-window
@geindex command; mistty-other-window
@geindex variable; mistty-shell-command
@geindex variable; explicit-shell-file-name
@geindex variable; shell-file-name
@geindex variable; mistty-buffer-name
@itemize -
@item
@code{M-x mistty-create} launches a new interactive shell in a
MisTTY buffer in the current buffer’s @code{default-directory}.
The shell that is launched is the one that’s configured on
@code{M-x configure-option mistty-shell-command}. If
@code{mistty-shell-command} is not set, MisTTY falls back to
@code{explicit-shell-file-name}, @code{shell-file-name}, then
the environment variables
@geindex ESHELL
@geindex environment variable; ESHELL
@code{ESHELL} and
@geindex SHELL
@geindex environment variable; SHELL
@code{SHELL}.
With a prefix argument, this command asks for a directory for the
new shell, instead of using the current buffer’s current
directory. This is particularly useful if you want to run a
@ref{d,,Remote Shells with TRAMP}.
By default, new buffers are called “*mistty*”, or, if you use
TRAMP “*mistty@@hostname*”. You can configure this on @code{M-x
customize-option mistty-buffer-name}.
@item
@code{M-x mistty} creates a new MisTTY buffer the first time it is
called. Afterwards, it’ll try to guess what’s most appropriate,
displaying an existing MisTTY buffer or creating a new one.
With a prefix argument, this command always creates a new buffer.
@end itemize
@geindex command; mistty-other-window
@itemize -
@item
@code{M-x mistty-other-window} does the same as @code{mistty},
but opens the buffer in another window.
@item
@code{M-x mistty-create-other-window} does the same as
@code{mistty-create}, but opens the buffer in another window.
@quotation
If you need more control on how MisTTY windows are handled
than what’s provided by the @code{-other-window} variants,
you can configure it using @code{M-x customize-option
display-comint-buffer-action} or @code{M-x customize-option
display-buffer-alist}. In the latter case, note that MisTTY
buffers belong to the @code{comint} category, just like shell
buffers.
See the section “Window Choice” of the Emacs manual for
details.
@end quotation
@end itemize
@geindex command; mistty-in-project
@geindex command; mistty-ssh
@geindex command; mistty-docker
@itemize -
@item
@code{M-x mistty-in-project} creates a new MisTTY buffer in the
root directory of the current project the first time it is called.
Afterwards, it’ll try to guess what’s most appropriate, displaying
an existing MisTTY buffer or creating a new one.
With a prefix argument, this command always creates a new buffer.
Note that if you want @code{M-x project-kill-buffers} to kill such
buffers, you’ll want to execute
@code{mistty-project-init-kill-buffer} somewhere in your
configuration or tell @code{M-x configure-option
project-kill-buffer-conditions} about MisTTY.
@item
@code{M-x mistty-ssh} creates a new MisTTY buffer connected to
another host using SSH. This is just a shortcut that uses TRAMP to
connect to a remote host. See @ref{d,,Remote Shells with TRAMP} for details.
@item
@code{M-x mistty-docker} creates a new MisTTY buffer connected to
a docker instance. This requires the docker command-line tool to
be installed. This is just a shortcut that uses TRAMP to connect
to a remote host. See @ref{d,,Remote Shells with TRAMP} for details.
@end itemize
@end quotation
@node Terminal vs Scrollback,Navigating the scrollback zone,Launching,Usage
@anchor{usage term-vs-scroll}@anchor{e}@anchor{usage terminal-vs-scrollback}@anchor{f}
@subsection Terminal vs. Scrollback
MisTTY buffers are split into two zones, with different behaviors:
The `scrollback zone', is where you can see commands that have
been executed and their output.
The `terminal zone', marked by a purple line on the left of the
window, is where you can type command and interact with the
terminal. In this zone, @code{TAB} triggers the shell completion, if
available. With some shells, you’ll see autosuggestions as you type.
The scrollback zone behaves as a normal Emacs buffer. You can modify
it as you see fit.
The terminal zone, on the other hand, limits what you can do: When a
shell is attached to the terminal, you can edit the command you’re
about to run, but you can’t edit the prompt itself - or rather, if you
do change the prompt, your change will be undone by the shell.
The terminal zone is where the magic happens: this is where you can
use a mix of Emacs and shell key bindings to edit the command
line. The trickiest part is choosing which key bindings you want Emacs
to handle and which key bindings you want the shell to handle.
By default, Emacs handles everything but a few key bindings are sent
directly to the terminal, bypassing Emacs:
@itemize -
@item
@code{RET}, to ask the shell to run the command
@item
@code{TAB}, to ask the shell to run command completion,
@item
@code{C-a} to ask it to move the cursor to the beginning of the
line, and
@item
@code{C-e} to ask it to move the cursor to the end of the line.
@item
@code{C-d} to ask it to either delete the next character or exit the
program.
@item
@code{M-p} to ask it to go up, or up the command history, sending
@code{C-p} to the terminal.
@item
@code{M-n} to ask it to go down, or down the command history,
sending @code{C-n} to the terminal.
@item
@code{M-r} to ask it to do @ref{10,,Backward Search}, sending @code{C-r} to the terminal.
@item
@code{M-.} to ask the shell to insert the last history argument.
@end itemize
In addition, @code{C-c C-c} sends the TERM signal to the terminal.
The program attached to the terminal decides what the actual effect of
these shortcuts is. Most shells and command-line editing tools
supports the shortcuts above by default, but they might not work
everywhere as expected.
@cartouche
@quotation Warning
MisTTY will not work if you’ve configured your shell to turn on
`VI mode' by default. Please `turn it off' before trying out
MisTTY, for details on how to turn off VI mode only of MisTTY
buffers and leave it on otherwise, check out the instructions in
@ref{11,,Shells} for details. VI mode must be turned off even if you
just end up controlling it with VI commands using Evil.
@end quotation
@end cartouche
To get the most out of MisTTY, it’s worth it to take the time to
configure it to send to the terminal the shell key bindings that you
actually use and keep everything else behaving as usual for your Emacs
configuration.
@geindex map; mistty-prompt-map
@geindex map; mistty-mode-map
To bind keys only in the terminal zone, bind them to
@code{mistty-prompt-map}. To bind keys in both zones, bind them to
@code{mistty-mode-map}. See examples below.
The following commands are useful to send key sequences to the current
shell or program controlling the terminal:
@quotation
@geindex command; mistty-send-key
@itemize -
@item
The command @code{mistty-send-key}, called interactively,
forwards the key it was called from. It is meant to be bound to
the shell key bindings you want to work in the terminal zone map,
@code{mistty-prompt-map}.
For example, searching in the shell command history is usually
bound to @code{C-r}, MisTTY binds that to @code{M-r}, like comint
does, but if you’d like it to be accessible using the original key
binding, you can do:
@example
(keymap-set mistty-prompt-map "C-r" #'mistty-send-key)
@end example
If you’d prefer to have the key available in both the scrollback
and terminal zones, bind it @code{mistty-mode-map} instead.
You can also pass arbitrary keys to @code{mistty-send-key}, for
example:
@example
(defun my-mistty-M-s (n)
(interactive "p")
(mistty-send-key n (kbd "M-s")))
(keymap-set mistty-prompt-map "C-c a" #'my-mistty-M-s)
@end example
@end itemize
@geindex command; mistty-send-last-key
@itemize -
@item
The command @code{mistty-send-last-key} forwards the last key
combination of a sequence it was called from to the terminal. For
example, @code{C-c C-c} is bound to @code{mistty-send-last-key}
so that the terminal eventually just gets @code{C-c}.
@end itemize
@end quotation
To just try things out, or for shell shortcuts you don’t use
regularly, you can use the @code{C-q} prefix to bypass Emacs key
bindings and send keys directly to the terminal. For example,
@code{C-q <right>} sends a right arrow key press to the terminal
instead of moving the cursor.
If that’s not enough,
@quotation
@geindex command; mistty-send-key-sequence
@itemize -
@item
@code{C-c C-q}, @code{M-x mistty-send-key-sequence} sends all keys
you press to the terminal until you press @code{C-g}.
@end itemize
@end quotation
@node Navigating the scrollback zone,Fullscreen Mode,Terminal vs Scrollback,Usage
@anchor{usage navigating-the-scrollback-zone}@anchor{12}@anchor{usage navigation}@anchor{13}
@subsection Navigating the scrollback zone
@quotation
@geindex command; mistty-end-of-line-goto-cursor
@itemize -
@item
@code{C-e C-e} moves the point back inside the prompt. This is
handled by the interactive function
@code{mistty-end-of-line-or-goto-cursor}
@end itemize
@geindex command; mistty-goto-cursor
@itemize -
@item
@code{M-x mistty-goto-cursor} also moves the point back inside the
prompt. You can bind it to a custom shortcut if you don’t like
overloading C-e.
@end itemize
@geindex command; mistty-previous-output
@itemize -
@item
@code{C-c C-p} or @code{M-x mistty-goto-previous-output} goes to
the beginning of the previous command output. This is useful to if
the buffer has scrolled too far and you want to see it from the
beginning.
@end itemize
@geindex command; mistty-next-output
@itemize -
@item
@code{C-c C-n} or @code{M-x mistty-goto-next-output} does the
reverse, that is, it goes to the next command output.
@end itemize
@geindex command; mistty-select-output
@itemize -
@item
@code{C-c C-o} or @code{M-x mistty-select-output} selects the
command output at or before point. With an argument, selects the
Nth previous command output.
@end itemize
@geindex command; mistty-create-buffer-with-output
@itemize -
@item
@code{C-c C-r} or @code{M-x mistty-create-buffer-with-output}
creates a new buffer containing the command output at or before
point. With an argument, creates a buffer containing the Nth
previous command output.
@end itemize
@geindex command; mistty-goto-previous-input
@itemize -
@item
@code{M-x mistty-goto-previous-input} goes to the beginning of the
previous command input, that is, the previous prompt. While this
is a way of going back the command you’ve previously input, it’s
best to use the shell native command history, as discussed in
@ref{14,,Command History}.
@end itemize
@geindex command; mistty-goto-next-input
@itemize -
@item
@code{M-x mistty-goto-next-input} goes to the next command input.
@end itemize
@end quotation
@node Fullscreen Mode,Command History,Navigating the scrollback zone,Usage
@anchor{usage fullscreen}@anchor{2}@anchor{usage fullscreen-mode}@anchor{15}
@subsection Fullscreen Mode
MisTTY detects when a program such as @code{less} or @code{vi}
asks to run full screen and splits the MisTTY buffers into:
@itemize -
@item
a terminal buffer, which shows the program output and lets you
interact with it. This is a term-mode buffer.
@item
a scrollback buffer, which shows the previous command lines and
their output.
@end itemize
@geindex command; mistty-toggle-buffers
@code{C-c C-j} or @code{M-x mistty-toggle-buffers} switches between
these two.
When the program exits, the two buffers are again merged. Note that
the output of the full screen app isn’t available in the scrollback.
@node Command History,Backward Search,Fullscreen Mode,Usage
@anchor{usage command-history}@anchor{16}@anchor{usage history}@anchor{14}
@subsection Command History
MisTTY doesn’t track command history. It relies instead on being able
to access the history of the different interactive command-line tools.
The command history available in most shells and command-line editing tools is
available in MisTTY using the following shortcuts:
@itemize -
@item
@code{M-p} moves up command history
@item
@code{M-n} moves down command history
@item
@code{M-r} triggers a @ref{10,,Backward Search} in command history
@item
@code{M-.} insert the last argument from command history
@end itemize
To get the same key bindings you’d get in a normal terminal, you can
bind @code{C-p}, @code{C-n}, or @code{C-r} to @code{mistty-send-key}
in the terminal zone of the MisTTY buffer. For example:
@example
(keymap-set mistty-prompt-map "C-p" #'mistty-send-key)
(keymap-set mistty-prompt-map "C-n" #'mistty-send-key)
(keymap-set mistty-prompt-map "C-r" #'mistty-send-key)
@end example
@node Backward Search,Completion-at-point,Command History,Usage
@anchor{usage backward-search}@anchor{17}@anchor{usage bs}@anchor{10}
@subsection Backward Search
@geindex map; mistty-forbid-edit-map
@geindex variable; mistty-forbid-edit-regexps
@geindex variable; mistty-forbid-edit-map
Within the different shells @code{C-r} or @code{M-r} triggers a
special backward search mode, during which edition is very limited.
MisTTY detects this mode based on the regular expressions configured
in @code{M-x customize-option mistty-forbid-edit-regexps}.
While this mode is active:
@itemize -
@item
text can be appended or deleted, but not modified. While it is still
possible to yank text or delete a word in this mode, most Emacs
edition command will not work.
@item
the status modeline shows “FE:run”, for Forbid Edit mode
@item
arrow keys are sent directly to the terminal. This is useful when
the shell offers multiple choices that can be selected, as the Fish
shell does. To customize this behavior, add or remove key bindings
from @code{mistty-forbid-edit-map}, which extends
@code{mistty-prompt-map} while this mode is active.
@item
C-g is forwarded to the terminal. It normally exits the backward
search mode without selecting anything.
@end itemize
@node Completion-at-point,Template Expansion,Backward Search,Usage
@anchor{usage cap}@anchor{18}@anchor{usage completion-at-point}@anchor{19}
@subsection Completion-at-point
When in a MisTTY buffer, it’s best to rely on the completion or
autosuggestions provided by the shell or other command-line tool
currently running, as they’re more up-to-date and context-sensitive
than what Emacs can provide.
However, some form of Emacs-based completion can still be useful from
inside of a MisTTY buffer, to complete abbreviations, expand templates
or add emojis.
The following completion packages are known to work with MisTTY out of
the box, including auto-completion, if enabled:
@itemize -
@item
Emacs builtin @cite{complete-in-region}
@item
corfu@footnote{https://github.com/minad/corfu}
@item
company-mode@footnote{http://company-mode.github.io}
@end itemize
Emacs @cite{hippie-expand} also works. That’s not completion, but it’s
close.
Other packages might work or might be made to work with some efforts.
Auto-completion is usually the main challenge. See @ref{1a,,Auto-complete}
for some pointers. Please @ref{3,,file a bug} if you
encounter issues with other completion packages.
@menu
* Autosuggestions::
@end menu
@node Autosuggestions,,,Completion-at-point
@anchor{usage autosuggestions}@anchor{1b}
@subsubsection Autosuggestions
@geindex variable; mistty-wrap-capf-functions
@code{completion-at-point} completes the text `around' the point.
This is generally convenient, but gets confused by shell
autosuggestions, available in Fish or ZSH.
What if you typed “com” and the shell helpfully suggests “completion”?
The buffer would look like: “com<>pletion”, with <> representing
the point. @code{completion-at-point} would then think you typed
“completion” and not suggest anything else.
To avoid that problem MisTTY modifies the functions it finds in
@code{completion-at-point-functions} so that they just won’t see
anything after the point when in the terminal region. In the example
above, they’d only complete “com”, not “completion”.
That is, @code{completion-at-point} in the MisTTY terminal region
completes the text `before' the point.
If you don’t like that or don’t use a shell that supports
autosuggestions, you can turn this off with @code{M-x customize-option
mistty-wrap-capf-functions}
@node Template Expansion,Directory Tracking,Completion-at-point,Usage
@anchor{usage template-expansion}@anchor{1c}
@subsection Template Expansion
Template expansion and other form of long-running editing command
might be confused by the way MisTTY work in the terminal region. See
@ref{1d,,Long-running commands} for details.
The following template expansion packages are known to work with
MisTTY out of the box, if enabled:
@itemize -
@item
Emacs built-in @cite{tempo} package
@item
tempel@footnote{https://github.com/minad/tempel}
@item
yasnippet@footnote{https://github.com/joaotavora/yasnippet}
@end itemize
Other packages might work or might be made to work with some efforts.
Please @ref{3,,file a bug} if you encounter issues with
other packages.
@node Directory Tracking,Remote Shells with TRAMP,Template Expansion,Usage
@anchor{usage directory-tracking}@anchor{1e}@anchor{usage dirtrack}@anchor{b}
@subsection Directory Tracking
If you’re using @code{Bash} as a shell, you’ll discover that Emacs
keeps track of the shell’s current directory, so commands like
@code{M-x find-file} know where to start from.
If you’re using another shell, however, you’ll need to configure it to
tell Emacs about its current directory, as described in the sections
@ref{1f,,Directory Tracking for Fish} and @ref{20,,Directory Tracking for Zsh}.
@code{Bash} out-of-the-box directory tracking also doesn’t work in
shells you start using @code{ssh} or @code{docker}. For that
to work, the simplest solution is to start @ref{d,,remote shells with TRAMP}.
@node Remote Shells with TRAMP,Directory tracking and TRAMP,Directory Tracking,Usage
@anchor{usage remote-shells}@anchor{d}@anchor{usage remote-shells-with-tramp}@anchor{21}
@subsection Remote Shells with TRAMP
If the @cite{default-directory} that is current when a new MisTTY buffer is
created contains a TRAMP path whose method supports it, MisTTY runs
the shell with the method, user and host `of that path'.
@cartouche
@quotation Tip
@code{C-u M-x mistty-create} asks for a directory instead of using
the default one. This makes it possible to open a remote shell on a
host that no buffer is visiting. See @ref{1,,Launching}.
@end quotation
@end cartouche
For this to work, MisTTY needs to know the shell executable to use on
that host. The value of @code{mistty-shell-command} or
@code{explicit-shell-file-name} is interpreted as a local file within
that host, which might not always work.
To run different shells on different hosts, define different
connection local profiles that set @code{mistty-shell-command} and
bind them to the TRAMP host, machine or user you want, as shown in the
example below. This is described in details in the `Emacs Lisp'
manual, in the section `Connection Local Variables'.
Example:
@example
(connection-local-set-profile-variables
'profile-usr-local-fish
'((mistty-shell-command . ("/usr/local/bin/fish" "-i"))))
(connection-local-set-profiles '(:machine "myhost.example")
'profile-usr-local-fish)
@end example
By default, the name of TRAMP shells include the user and hostname, if
different from the current one. If you don’t want that, configure it
on @code{M-x customize-option mistty-buffer-name}.
@node Directory tracking and TRAMP,Fancy prompts,Remote Shells with TRAMP,Usage
@anchor{usage directory-tracking-and-tramp}@anchor{22}@anchor{usage tramp-dirtrack}@anchor{23}
@subsection Directory tracking and TRAMP
@geindex variable; mistty-allow-tramp-path
@geindex variable; mistty-host-to-tramp-path-alist
@ref{b,,Directory tracking} normally just works in TRAMP
shells started described in the previous section.
This isn’t necessarily true of shells started from a MisTTY buffers,
by calling @code{ssh}, @code{docker} or @code{sudo}, but
it is possible to make that work, as described below.
@cartouche
@quotation Tip
The simplest way to connect a host or docker instance you don’t
want to configure is to just start it as described in
@ref{d,,Remote Shells with TRAMP} and use @code{Bash} as your shell.
Everything then just work out of the box, at least for @ref{24,,Bash 4.4 and later}.
@end quotation
@end cartouche
If you haven’t already, configure your shell to tell Emacs about
directory changes, even @code{Bash}. This is described in
@ref{24,,Directory Tracking for Bash}, @ref{1f,,Directory Tracking for Fish} or @ref{20,,Directory Tracking for Zsh}.
Once this is done, the shell sends out file: URLs that include the
host name. By default, MisTTY will then use that to set the default
directory to remote file paths that include that hostname using the
default TRAMP method. For example, given the file: URL
@code{file:/example.com/var/log} reported by the shell, MisTTY will
set the directory of its buffer to @code{/-:example.com:/var/log}.
If you always connect to hosts using SSH, this is likely all you need,
if not, you can still make it work as follows:
@itemize -
@item
If you’re using some other way of connecting to your host, configure
it in @code{M-x configure-option tramp-default-method}. You can also
configure that on a per-host basis using @code{M-x configure-option
tramp-default-method-alist}
@item
If you’re connecting to hosts in more diverse ways, you can
configure the TRAMP path MisTTY should generate using @code{M-x
configure-option mistty-host-to-tramp-path-alist}
@item
If you want to configure the TRAMP path on the hosts, you can send
it from the prompt as Emacs-specific @code{\032/...\n} code
containing a TRAMP path instead of the standard file: URL
recommended in @ref{24,,Directory Tracking for Bash},
@ref{1f,,Directory Tracking for Fish} or
@ref{20,,Directory Tracking for Zsh}. Here’s an example
of such a code for @code{Bash} that tells TRAMP to connect to
the current docker instance:
@example
if [ "$TERM" = "eterm-color" ]; then
PS1='\032//docker:$HOSTNAME:/$PWD\n'$PS1
fi
@end example
@end itemize
That said, if you need more than just SSH to connect to other hosts,
it might be overall just easier to start @ref{d,,remote shells with TRAMP} instead of the command line, because directory
tracking just works in that case.
If everything fails, TRAMP is causing you too much trouble and you
just don’t want MisTTY to generate remote paths at all, unset the
option @code{M-x configure-option mistty-allow-tramp-paths}.
@node Fancy prompts,,Directory tracking and TRAMP,Usage
@anchor{usage fancy-prompts}@anchor{25}
@subsection Fancy prompts
MisTTY is known to work with powerline-shell prompts or Tide@comma{} on Fish@footnote{https://github.com/IlanCosman/tide}. This includes right prompts,
for the most part - though there might be temporary artifacts and
troublesome corner cases left.
If you suspect your shell prompt is causing issues, please first try
setting a traditional prompt to confirm, then @ref{3,,file a bug}, whatever the outcome.
@node Shells,Extending MisTTY,Usage,Contents
@anchor{shells doc}@anchor{26}@anchor{shells id1}@anchor{27}@anchor{shells shells}@anchor{11}
@section Shells
@menu
* Bash::
* Fish::
* Zsh::
* IPython::
@end menu
@node Bash,Fish,,Shells
@anchor{shells bash}@anchor{28}@anchor{shells id2}@anchor{29}
@subsection Bash
A recent version of Bash is preferable. Bash 5.1 or later is
recommended.
MisTTY works best with shells that support bracketed paste. Without
bracketed paste support, MisTTY will still work, but might behaves
unexpectedly when yanking text containing special characters.
Bash 4.5 to 5.0 supports bracketed paste, but it must be turned
on in your @code{.inputrc}, as follows:
@example
set enable-bracketed-paste on
@end example
Bash versions older than 4.5 don’t support bracketed paste.
Additionally, Bash versions older than 4.4 require extra setup to
enable directory tracking, as documented in @ref{24,,Directory tracking}.
@menu
* Multi-line prompts::
* Directory tracking::
* VI mode::
@end menu
@node Multi-line prompts,Directory tracking,,Bash
@anchor{shells multi-line-prompts}@anchor{2a}
@subsubsection Multi-line prompts
When you press @code{RET} on an incomplete command, @code{bash}
has the annoying habit of starting a secondary prompt which doesn’t
let you go back to the previous line with the default keybindings.
To work around that, type @code{S-<return>} instead of @code{RET}
while on the terminal zone of a MisTTY buffer. This sends a newline
without running the command. You’ll then end up with one multi-line
prompt that you can edit normally. This requires Bash 5.1 or an
earlier version with bracketed paste mode turned on.
You’ll get the same effect if you yank a multi-line command while in a
prompt or go up the command history to a previous multi-line command.
@node Directory tracking,VI mode,Multi-line prompts,Bash