mirrored from git://git.sv.gnu.org/emacs.git
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathterm.el
4747 lines (4280 loc) · 187 KB
/
term.el
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
;;; term.el --- general command interpreter in a window stuff -*- lexical-binding: t -*-
;; Copyright (C) 1988, 1990, 1992, 1994-1995, 2001-2025 Free Software
;; Foundation, Inc.
;; Author: Per Bothner <per@bothner.com>
;; Maintainer: Dan Nicolaescu <dann@ics.uci.edu>, Per Bothner <per@bothner.com>
;; Based on comint mode written by: Olin Shivers <shivers@cs.cmu.edu>
;; Keywords: processes
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;; March 13 2001
;; Fixes for CJK support by Yong Lu <lyongu@yahoo.com>.
;; Dir/Hostname tracking and ANSI colorization by
;; Marco Melgazzi <marco@techie.com>.
;; To see what I've modified and where it came from search for '-mm'
;;; Commentary:
;; This file defines a general command-interpreter-in-a-buffer package
;; (term mode). The idea is that you can build specific process-in-a-buffer
;; modes on top of term mode -- e.g., Lisp, shell, Scheme, T, soar, ....
;; This way, all these specific packages share a common base functionality,
;; and a common set of bindings, which makes them easier to use (and
;; saves code, implementation time, etc., etc.).
;; If, instead of `term', you call `ansi-term', you get multiple term
;; buffers, after every new call ansi-term opens a new
;; "*ansi-term*<xx>" window, where <xx> is, as usual, a number...
;; For hints on converting existing process modes (e.g., tex-mode,
;; background, dbx, gdb, kermit, prolog, telnet) to use term-mode
;; instead of shell-mode, see the notes at the end of this file.
;; Speed considerations and a few caveats
;; --------------------------------------
;;
;; While the message passing and the colorization surely introduce some
;; overhead this has became so small that IMHO it is surely outweighed by
;; the benefits you get but, as usual, YMMV.
;;
;; Important caveat, when deciding the cursor/'gray keys' keycodes I had to
;; make a choice: on my Linux box this choice allows me to run all the
;; ncurses applications without problems but make these keys
;; incomprehensible to all the cursesX programs. Your mileage may vary so
;; you may consider changing the default 'emulation'. Just search for this
;; piece of code and modify it as you like:
;;
;; ;; Which would be better: "\e[A" or "\eOA"? readline accepts either.
;; ;; For my configuration it's definitely better \eOA but YMMV. -mm
;; ;; For example: vi works with \eOA while elm wants \e[A ...
;; (defun term-send-up () (interactive) (term-send-raw-string "\eOA"))
;; (defun term-send-down () (interactive) (term-send-raw-string "\eOB"))
;; (defun term-send-right () (interactive) (term-send-raw-string "\eOC"))
;; (defun term-send-left () (interactive) (term-send-raw-string "\eOD"))
;;
;;
;; IMPORTANT: additions & changes
;; ------------------------------
;;
;; With this enhanced ansi-term.el you will get a reliable mechanism of
;; directory/username/host tracking: the only drawback is that you will
;; have to modify your shell start-up script. It's worth it, believe me :).
;;
;; When you ssh/sudo/su and the account you access has a modified
;; startup script, you will be able to access the remote files as usual
;; with C-x C-f, if it's needed you will have to enter a password,
;; otherwise the file should get loaded straight away.
;;
;; This is useful even if you work only on one host: it often happens that,
;; for maintenance reasons, you have to edit files 'as root': before
;; patching term.el, I su-ed in a term.el buffer and used vi :), now I
;; simply do a C-x C-f and, via ange-ftp, the file is automatically loaded
;; 'as-root'. (If you don't want to enter the root password every time you
;; can put it in your .netrc: note that this is -not- advisable if you're
;; connected to the internet or if somebody else works on your workstation!)
;;
;; If you use wu-ftpd you can use some of its features to avoid root ftp
;; access to the rest of the world: just put in /etc/ftphosts something like
;;
;; # Local access
;; allow root 127.0.0.1
;;
;; # By default nobody can't do anything
;; deny root *
;;
;; ----------------------------------------
;;
;; With the variable term-buffer-maximum-size you can decide how many
;; scrollback lines to keep: its default is 8192.
;;
;; ----------------------------------------
;;
;;
;; ANSI colorization should work well. Blink, is not supported.
;; Currently it's mapped as bold.
;;
;; ----------------------------------------
;;
;; TODO:
;;
;; - Add hooks to allow raw-mode keys to be configurable
;; - Which keys are better ? \eOA or \e[A ?
;;
;; ----------------------------------------------------------------
;; You should/could have something like this in your .emacs to take
;; full advantage of this package
;;
;; (add-hook 'term-mode-hook
;; (lambda ()
;; (setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *")
;; (setq-local mouse-yank-at-point t)
;; (setq-local transient-mark-mode nil)
;; (auto-fill-mode -1)
;; (setq tab-width 8)))
;;
;; ----------------------------------------
;;
;; If you want to use color ls the best setup is to have a different file
;; when you use eterm ( see above, mine is named .emacs_dircolors ). This
;; is necessary because some terminals, rxvt for example, need non-ansi
;; hacks to work ( for example on my rxvt white is wired to fg, and to
;; obtain normal white I have to do bold-white :)
;;
;; ----------------------------------------
;;
;; # Configuration file for the color ls utility
;; # This file goes in the /etc directory, and must be world readable.
;; # You can copy this file to .dir_colors in your $HOME directory to
;; # override the system defaults.
;;
;; # COLOR needs one of these arguments: 'tty' colorizes output to ttys, but
;; # not pipes. 'all' adds color characters to all output. 'none' shuts
;; # colorization off.
;; COLOR tty
;; OPTIONS -F
;;
;; # Below, there should be one TERM entry for each termtype that is
;; # colorizable
;; TERM eterm
;;
;; # EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
;; EIGHTBIT 1
;;
;; # Below are the color init strings for the basic file types. A color init
;; # string consists of one or more of the following numeric codes:
;; # Attribute codes:
;; # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
;; # Text color codes:
;; # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
;; # Background color codes:
;; # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
;; NORMAL 00 # global default, although everything should be something.
;; FILE 00 # normal file
;; DIR 00;37 # directory
;; LINK 00;36 # symbolic link
;; FIFO 00;37 # pipe
;; SOCK 40;35 # socket
;; BLK 33;01 # block device driver
;; CHR 33;01 # character device driver
;;
;; # This is for files with execute permission:
;; EXEC 00;32
;;
;; # List any file extensions like '.gz' or '.tar' that you would like ls
;; # to colorize below. Put the extension, a space, and the color init
;; # string. (and any comments you want to add after a '#')
;; .tar 01;33 # archives or compressed
;; .tgz 01;33
;; .arj 01;33
;; .taz 01;33
;; .lzh 01;33
;; .zip 01;33
;; .z 01;33
;; .Z 01;33
;; .gz 01;33
;; .jpg 01;35 # image formats
;; .gif 01;35
;; .bmp 01;35
;; .xbm 01;35
;; .xpm 01;35
;;
;; ----------------------------------------
;;
;; There are actually two methods for directory tracking, one
;; implemented in `term-command-hook' which sets the directory
;; according to an escape sequence of the form "\032/<directory>\n".
;; Some shells like bash will already send this escape sequence when
;; they detect they are running in Emacs. This can be configured or
;; disabled on the Emacs side by setting `term-command-hook' to
;; a different function.
;;
;; The second method is in `term-handle-ansi-terminal-messages' which
;; sets user, host, and directory according to escape sequences of the
;; form "\033AnSiTc <directory>\n" (replace the "c" with "u" and "h"
;; for user and host, respectively). If the user and host don't
;; match, it will set directory to a remote one, so it is important to
;; set user and host correctly first. See the example bash
;; configuration below.
;;
;; ----------------------------------------
;;
;; # Set HOSTNAME if not already set.
;; : ${HOSTNAME=$(uname -n)}
;;
;; # su does not change this but I'd like it to
;; USER=$(whoami)
;;
;; # ...
;;
;; case $TERM in
;; eterm*)
;;
;; printf '%s\n' \
;; -------------------------------------------------------------- \
;; "Hello $USER" \
;; "Today is $(date)" \
;; "We are on $HOSTNAME running $(uname) under Emacs term mode" \
;; --------------------------------------------------------------
;;
;; # The \033 stands for ESC.
;; # There is a space between "AnSiT?" and $whatever.
;; printf '\033AnSiTh %s\n' "$HOSTNAME"
;; printf '\033AnSiTu %s\n' "$USER"
;; printf '\033AnSiTc %s\n' "$PWD"
;;
;; cd() { command cd "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
;; pushd() { command pushd "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
;; popd() { command popd "$@" && printf '\033AnSiTc %s\n' "$PWD"; }
;;
;; # Use custom dircolors in term buffers.
;; # eval $(dircolors $HOME/.emacs_dircolors)
;; esac
;;
;; # ...
;;
;; For troubleshooting in Bash, you can check the definition of the
;; custom functions with the "type" command. e.g. "type cd". If you
;; do not see the expected definition from the config below, then the
;; directory tracking will not work.
;; Brief Command Documentation:
;;============================================================================
;; Term Mode Commands: (common to all derived modes, like cmushell & cmulisp
;; mode)
;;
;; M-p term-previous-input Cycle backwards in input history
;; M-n term-next-input Cycle forwards
;; M-r term-previous-matching-input Previous input matching a regexp
;; M-s term-next-matching-input Next input that matches
;; return term-send-input
;; C-c C-a term-bol Beginning of line; skip prompt.
;; C-d term-delchar-or-maybe-eof Delete char unless at end of buff.
;; C-c C-u term-kill-input ^u
;; C-c C-w backward-kill-word ^w
;; C-c C-c term-interrupt-subjob ^c
;; C-c C-z term-stop-subjob ^z
;; C-c C-\ term-quit-subjob ^\
;; C-c C-o term-kill-output Delete last batch of process output
;; C-c C-r term-show-output Show last batch of process output
;; C-c C-h term-dynamic-list-input-ring List input history
;;
;; Not bound by default in term-mode
;; term-send-invisible Read a line without echo, and send to proc
;; (These are bound in shell-mode)
;; term-dynamic-complete Complete filename at point.
;; term-dynamic-list-completions List completions in help buffer.
;; term-replace-by-expanded-filename Expand and complete filename at point;
;; replace with expanded/completed name.
;; term-kill-subjob No mercy.
;; term-show-maximum-output Show as much output as possible.
;; term-continue-subjob Send CONT signal to buffer's process
;; group. Useful if you accidentally
;; suspend your process (with C-c C-z).
;; term-mode-hook is the term mode hook. Basically for your keybindings.
;; term-load-hook is run after loading in this package.
;;; Code:
;; This is passed to the inferior in the EMACS environment variable,
;; so it is important to increase it if there are protocol-relevant changes.
(defconst term-protocol-version "0.96")
(eval-when-compile
(require 'ange-ftp)
(require 'cl-lib))
(require 'comint) ; Password regexp.
(require 'ansi-color)
(require 'ehelp)
(require 'ring)
(require 'shell)
(defgroup term nil
"General command interpreter in a window."
:group 'processes)
;;; Buffer Local Variables:
;;============================================================================
;; Term mode buffer local variables:
;; term-prompt-regexp - string term-bol uses to match prompt.
;; term-delimiter-argument-list - list For delimiters and arguments
;; term-last-input-start - marker Handy if inferior always echoes
;; term-last-input-end - marker For term-kill-output command
;; For the input history mechanism:
(defvar term-input-ring-size 32 "Size of input history ring.")
;; term-input-ring-size - integer
;; term-input-ring - ring
;; term-input-ring-index - number ...
;; term-input-autoexpand - symbol ...
;; term-input-ignoredups - boolean ...
;; term-last-input-match - string ...
;; term-dynamic-complete-functions - hook For the completion mechanism
;; term-completion-fignore - list ...
;; term-get-old-input - function Hooks for specific
;; term-input-filter-functions - hook process-in-a-buffer
;; term-input-filter - function modes.
;; term-input-send - function
;; term-scroll-to-bottom-on-output - symbol ...
;; term-scroll-show-maximum-output - boolean...
(defvar term-height) ; Number of lines in window.
(defvar term-width) ; Number of columns in window.
(defvar term-home-marker) ; Marks the "home" position for cursor addressing.
(defvar term-saved-home-marker nil
"When using alternate sub-buffer,
contains saved `term-home-marker' from original sub-buffer.")
(defvar term-start-line-column 0
"(current-column) at start of screen line, or nil if unknown.")
(defvar term-current-column 0 "If non-nil, is cache for (current-column).")
(defvar term-current-row 0
"Current vertical row (relative to home-marker) or nil if unknown.")
(defvar term-insert-mode nil)
(defvar term-vertical-motion)
(defvar term-auto-margins t
"When non-nil, terminal will automatically wrap lines at the right margin.
This can be toggled by the application using DECAWM escape sequences.")
(defvar term-do-line-wrapping nil
"Last character was a graphic in the last column.
If next char is graphic, first move one column right
\(and line warp) before displaying it.
This emulates (more or less) the behavior of xterm.")
(defvar term-kill-echo-list nil
"A queue of strings whose echo we want suppressed.")
(defvar term-terminal-undecoded-bytes nil)
(defvar term-current-face 'term)
(defvar-local term-scroll-start 0
"Top-most line (inclusive) of the scrolling region.
`term-scroll-start' must be in the range [0,term-height). In addition, its
value has to be smaller than `term-scroll-end', i.e. one line scroll regions are
not allowed.")
(defvar-local term-scroll-end nil
"Bottom-most line (inclusive) of the scrolling region.
`term-scroll-end' must be in the range [0,term-height). In addition, its
value has to be greater than `term-scroll-start', i.e. one line scroll regions
are not allowed.")
(defvar term-pager-count nil
"Number of lines before we need to page; if nil, paging is disabled.")
(defvar term-saved-cursor nil)
(define-obsolete-variable-alias 'term-command-hook
'term-command-function "27.1")
(defvar term-command-function #'term-command-hook)
(defvar term-log-buffer nil)
(defvar term-scroll-with-delete nil
"If t, forward scrolling should be implemented by delete to
top-most line(s); and if nil, scrolling should be implemented
by moving `term-home-marker'. It is set to t if there is a
\(non-default) scroll-region OR the alternate buffer is used.")
(defvar term-pending-delete-marker) ; New user input in line mode
; needs to be deleted, because it gets echoed by the inferior.
; To reduce flicker, we defer the delete until the next output.
(defvar term-old-mode-map nil "Saves the old keymap when in char mode.")
(defvar term-old-mode-line-format) ; Saves old mode-line-format while paging.
(defvar term-pager-old-local-map nil "Saves old keymap while paging.")
(defvar term-pager-old-filter) ; Saved process-filter while paging.
(defvar-local term-line-mode-buffer-read-only nil
"The `buffer-read-only' state to set in `term-line-mode'.")
(defvar term-prompt-regexp "^"
"Regexp to recognize prompts in the inferior process.
Defaults to \"^\", the null string at BOL.
Good choices:
Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
kcl: \"^>+ *\"
shell: \"^[^#$%>\\n]*[#$%>] *\"
T: \"^>+ *\"
This is a good thing to set in mode hooks.")
(defvar term-delimiter-argument-list ()
"List of characters to recognize as separate arguments in input.
Strings comprising a character in this list will separate the arguments
surrounding them, and also be regarded as arguments in their own right
\(unlike whitespace). See `term-arguments'.
Defaults to the empty list.
For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?\\;).
This is a good thing to set in mode hooks.")
(defcustom term-input-autoexpand nil
"If non-nil, expand input command history references on completion.
This mirrors the optional behavior of tcsh (its autoexpand and histlit).
If the value is `input', then the expansion is seen on input.
If the value is `history', then the expansion is only when inserting
into the buffer's input ring. See also `term-magic-space' and
`term-dynamic-complete'.
This variable is buffer-local."
:type '(choice (const nil) (const t) (const input) (const history))
:group 'term)
(defcustom term-input-ignoredups nil
"If non-nil, don't add input matching the last on the input ring.
This mirrors the optional behavior of bash.
This variable is buffer-local."
:type 'boolean
:group 'term)
(defcustom term-input-ring-file-name nil
"If non-nil, name of the file to read/write input history.
See also `term-read-input-ring' and `term-write-input-ring'.
This variable is buffer-local, and is a good thing to set in mode hooks."
:type 'boolean
:group 'term)
(defcustom term-char-mode-buffer-read-only t
"If non-nil, only the process filter may modify the buffer in char mode.
A non-nil value makes the buffer read-only in `term-char-mode',
which prevents editing commands from making the buffer state
inconsistent with the state of the terminal understood by the
inferior process. Only the process filter is allowed to make
changes to the buffer.
Customize this option to nil if you want the previous behavior."
:version "26.1"
:type 'boolean
:group 'term)
(defcustom term-set-terminal-size nil
"If non-nil, set the LINES and COLUMNS environment variables."
:type 'boolean
:version "28.1")
(defcustom term-char-mode-point-at-process-mark t
"If non-nil, keep point at the process mark in char mode.
A non-nil value causes point to be moved to the current process
mark after each command in `term-char-mode' (provided that the
pre-command point position was also at the process mark). This
prevents commands that move point from making the buffer state
inconsistent with the state of the terminal understood by the
inferior process.
Mouse events are not affected, so moving point and selecting text
is still possible in char mode via the mouse, after which other
commands can be invoked on the mouse-selected point or region,
until the process filter (or user) moves point to the process
mark once again.
Customize this option to nil if you want the previous behavior."
:version "26.1"
:type 'boolean
:group 'term)
(defcustom term-scroll-to-bottom-on-output nil
"Controls whether interpreter output causes window to scroll.
If nil, then do not scroll. If t, scroll all windows showing buffer.
If `this', scroll only the selected window.
If `others', scroll only those that are not the selected window.
The default is nil.
See variable `term-scroll-show-maximum-output'.
This variable is buffer-local."
:type '(choice (const :tag "Don't scroll" nil)
(const :tag "Scroll selected window only" this)
(const :tag "Scroll unselected windows" others)
;; We also recognize `all', but we don't advertise it
;; anymore. (Bug#66071)
(other :tag "Scroll all windows" t))
:group 'term)
(defcustom term-scroll-snap-to-bottom t
"Control whether to keep the prompt at the bottom of the window.
If non-nil, when the prompt is visible within the window, then
scroll so that the prompt is on the bottom on any input or
output."
:version "28.1"
:type 'boolean)
(defcustom term-scroll-show-maximum-output nil
"Controls how interpreter output causes window to scroll.
If non-nil, then show the maximum output when the window is scrolled.
See variable `term-scroll-to-bottom-on-output'.
This variable is buffer-local."
:type 'boolean
:group 'term)
(defcustom term-suppress-hard-newline nil
"Non-nil means interpreter should not break long lines with newlines.
This means text can automatically reflow if the window is resized."
:version "24.4"
:type 'boolean
:group 'term)
(make-obsolete-variable 'term-suppress-hard-newline nil
"27.1")
(defcustom term-clear-full-screen-programs t
"Whether to clear contents of full-screen terminal programs after exit.
If non-nil, output of full-screen terminal programs is cleared after
exiting them. Note however that a minority of such programs
don't send an appropriate escape sequence to the terminal before
exiting so their output isn't cleared regardless of this option."
:version "29.1"
:type 'boolean
:group 'term)
;; Where gud-display-frame should put the debugging arrow. This is
;; set by the marker-filter, which scans the debugger's output for
;; indications of the current pc.
(defvar term-pending-frame nil)
;;; Here are the per-interpreter hooks.
(defvar term-get-old-input (function term-get-old-input-default)
"Function that submits old text in term mode.
This function is called when return is typed while the point is in old text.
It returns the text to be submitted as process input. The default is
`term-get-old-input-default', which grabs the current line, and strips off
leading text matching `term-prompt-regexp'.")
(defvar term-dynamic-complete-functions
'(term-replace-by-expanded-history term-dynamic-complete-filename)
"List of functions called to perform completion.
Functions should return non-nil if completion was performed.
See also `term-dynamic-complete'.
This is a good thing to set in mode hooks.")
(defvar term-input-filter
(lambda (str) (not (string-match "\\`\\s *\\'" str)))
"Predicate for filtering additions to input history.
Only inputs answering true to this function are saved on the input
history list. Default is to save anything that isn't all whitespace.")
(defvar term-input-filter-functions '()
"Functions to call before input is sent to the process.
These functions get one argument, a string containing the text to send.
This variable is buffer-local.")
(defvar term-input-sender #'term-simple-send
"Function to actually send to PROCESS the STRING submitted by user.
Usually this is just `term-simple-send', but if your mode needs to
massage the input string, this is your hook. This is called from
the user command `term-send-input'. `term-simple-send' just sends
the string plus a newline.")
(defcustom term-eol-on-send t
"Non-nil means go to the end of the line before sending input.
See `term-send-input'."
:type 'boolean
:group 'term)
(defcustom term-mode-hook '()
"Called upon entry into term mode.
This is run before the process is cranked up."
:type 'hook
:group 'term)
(defcustom term-exec-hook '()
"Called each time a process is exec'd by `term-exec'.
This is called after the process is cranked up. It is useful for things that
must be done each time a process is executed in a term mode buffer (e.g.,
`set-process-query-on-exit-flag'). In contrast, `term-mode-hook' is only
executed once, when the buffer is created."
:type 'hook
:group 'term)
(defvar term-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\ep" 'term-previous-input)
(define-key map "\en" 'term-next-input)
(define-key map "\er" 'term-previous-matching-input)
(define-key map "\es" 'term-next-matching-input)
(define-key map [?\A-\M-r]
'term-previous-matching-input-from-input)
(define-key map [?\A-\M-s] 'term-next-matching-input-from-input)
(define-key map "\e\C-l" 'term-show-output)
(define-key map "\C-m" 'term-send-input)
(define-key map "\C-d" 'term-delchar-or-maybe-eof)
(define-key map "\C-c\C-a" 'term-bol)
(define-key map "\C-c\C-u" 'term-kill-input)
(define-key map "\C-c\C-w" 'backward-kill-word)
(define-key map "\C-c\C-c" 'term-interrupt-subjob)
(define-key map "\C-c\C-z" 'term-stop-subjob)
(define-key map "\C-c\C-\\" 'term-quit-subjob)
(define-key map "\C-c\C-m" 'term-copy-old-input)
(define-key map "\C-c\C-o" 'term-kill-output)
(define-key map "\C-c\C-r" 'term-show-output)
(define-key map "\C-c\C-e" 'term-show-maximum-output)
(define-key map "\C-c\C-l" 'term-dynamic-list-input-ring)
(define-key map "\C-c\C-n" 'term-next-prompt)
(define-key map "\C-c\C-p" 'term-previous-prompt)
(define-key map "\C-c\C-d" 'term-send-eof)
(define-key map "\C-c\C-k" 'term-char-mode)
(define-key map "\C-c\C-j" 'term-line-mode)
(define-key map "\C-c\C-q" 'term-pager-toggle)
;; completion: (line mode only)
(easy-menu-define nil map "Complete menu for Term mode."
'("Complete"
["Complete Before Point" term-dynamic-complete t]
["Complete File Name" term-dynamic-complete-filename t]
["File Completion Listing" term-dynamic-list-filename-completions t]
["Expand File Name" term-replace-by-expanded-filename t]))
;; Input history: (line mode only)
(easy-menu-define nil map "In/Out menu for Term mode."
'("In/Out"
["Expand History Before Point" term-replace-by-expanded-history
term-input-autoexpand]
["List Input History" term-dynamic-list-input-ring t]
["Previous Input" term-previous-input t]
["Next Input" term-next-input t]
["Previous Matching Current Input"
term-previous-matching-input-from-input t]
["Next Matching Current Input" term-next-matching-input-from-input t]
["Previous Matching Input..." term-previous-matching-input t]
["Next Matching Input..." term-next-matching-input t]
["Backward Matching Input..." term-backward-matching-input t]
["Forward Matching Input..." term-forward-matching-input t]
["Copy Old Input" term-copy-old-input t]
["Kill Current Input" term-kill-input t]
["Show Current Output Group" term-show-output t]
["Show Maximum Output" term-show-maximum-output t]
["Backward Output Group" term-previous-prompt t]
["Forward Output Group" term-next-prompt t]
["Kill Current Output Group" term-kill-output t]))
map)
"Keymap for \"line mode\" in Term mode.
For custom keybindings purposes please note there is also `term-raw-map'")
(defvar term-escape-char nil
"Escape character for char sub-mode of term mode.
Do not change it directly; use `term-set-escape-char' instead.")
(defvar term-pager-break-map
(let ((map (make-keymap)))
;; (dotimes (i 128)
;; (define-key map (make-string 1 i) 'term-send-raw))
(define-key map "\e" (lookup-key (current-global-map) "\e"))
(define-key map "\C-x" (lookup-key (current-global-map) "\C-x"))
(define-key map "\C-u" (lookup-key (current-global-map) "\C-u"))
(define-key map " " 'term-pager-page)
(define-key map "\r" 'term-pager-line)
(define-key map "?" 'term-pager-help)
(define-key map "h" 'term-pager-help)
(define-key map "b" 'term-pager-back-page)
(define-key map "\177" 'term-pager-back-line)
(define-key map "q" 'term-pager-discard)
(define-key map "D" 'term-pager-disable)
(define-key map "<" 'term-pager-bob)
(define-key map ">" 'term-pager-eob)
map)
"Keymap used in Term pager mode.")
(defvar term-ptyp t
"Non-nil if communications via pty; false if by pipe. Buffer local.
This is to work around a bug in Emacs process signaling.")
(defvar term-last-input-match ""
"Last string searched for by term input history search, for defaulting.
Buffer local variable.")
(defvar term-input-ring nil)
(defvar term-last-input-start)
(defvar term-last-input-end)
(defvar term-input-ring-index nil
"Index of last matched history element.")
(defvar term-matching-input-from-input-string ""
"Input previously used to match input history.")
; This argument to set-process-filter disables reading from the process.
(defvar term-pager-filter t)
(put 'term-input-ring 'permanent-local t)
(put 'term-input-ring-index 'permanent-local t)
(put 'term-input-autoexpand 'permanent-local t)
(put 'term-input-filter-functions 'permanent-local t)
(put 'term-scroll-to-bottom-on-output 'permanent-local t)
(put 'term-scroll-show-maximum-output 'permanent-local t)
(put 'term-ptyp 'permanent-local t)
(defmacro term-in-char-mode () '(eq (current-local-map) term-raw-map))
(defmacro term-in-line-mode () '(not (term-in-char-mode)))
;; True if currently doing PAGER handling.
(defmacro term-pager-enabled () 'term-pager-count)
(defmacro term-handling-pager () 'term-pager-old-local-map)
(defmacro term-using-alternate-sub-buffer () 'term-saved-home-marker)
;; Let's silence the byte-compiler -mm
(defvar term-ansi-at-host nil)
(defvar term-ansi-at-dir nil)
(defvar term-ansi-at-user nil)
(defvar term-ansi-at-message nil)
(defvar term-ansi-at-save-user nil)
(defvar term-ansi-at-save-pwd nil)
(defvar term-ansi-at-save-anon nil)
(defvar term-ansi-current-bold nil)
(defvar term-ansi-current-faint nil)
(defvar term-ansi-current-italic nil)
(defvar term-ansi-current-underline nil)
(defvar term-ansi-current-slow-blink nil)
(defvar term-ansi-current-fast-blink nil)
(defvar term-ansi-current-color nil)
(defvar term-ansi-face-already-done nil)
(defvar term-ansi-current-bg-color nil)
(defvar term-ansi-current-reverse nil)
(defvar term-ansi-current-invisible nil)
(make-obsolete-variable 'term-ansi-face-already-done
"it doesn't have any effect." "29.1")
;;; Faces
(defvar ansi-term-color-vector
[term
term-color-black
term-color-red
term-color-green
term-color-yellow
term-color-blue
term-color-magenta
term-color-cyan
term-color-white
term-color-bright-black
term-color-bright-red
term-color-bright-green
term-color-bright-yellow
term-color-bright-blue
term-color-bright-magenta
term-color-bright-cyan
term-color-bright-white])
(defface term
`((t :inherit default))
"Default face to use in Term mode."
:group 'term)
(defface term-bold
'((t :inherit ansi-color-bold))
"Default face to use for bold text."
:group 'term
:version "28.1")
(defface term-faint
'((t :inherit ansi-color-faint))
"Default face to use for faint text."
:group 'term
:version "29.1")
(defface term-italic
'((t :inherit ansi-color-italic))
"Default face to use for italic text."
:group 'term
:version "29.1")
(defface term-underline
'((t :inherit ansi-color-underline))
"Default face to use for underlined text."
:group 'term
:version "28.1")
(defface term-slow-blink
'((t :inherit ansi-color-slow-blink))
"Default face to use for slowly blinking text."
:group 'term
:version "29.1")
(defface term-fast-blink
'((t :inherit ansi-color-fast-blink))
"Default face to use for rapidly blinking text."
:group 'term
:version "29.1")
(defface term-color-black
'((t :inherit ansi-color-black))
"Face used to render black color code."
:group 'term
:version "28.1")
(defface term-color-red
'((t :inherit ansi-color-red))
"Face used to render red color code."
:group 'term
:version "28.1")
(defface term-color-green
'((t :inherit ansi-color-green))
"Face used to render green color code."
:group 'term
:version "28.1")
(defface term-color-yellow
'((t :inherit ansi-color-yellow))
"Face used to render yellow color code."
:group 'term
:version "28.1")
(defface term-color-blue
'((t :inherit ansi-color-blue))
"Face used to render blue color code."
:group 'term
:version "28.1")
(defface term-color-magenta
'((t :inherit ansi-color-magenta))
"Face used to render magenta color code."
:group 'term
:version "28.1")
(defface term-color-cyan
'((t :inherit ansi-color-cyan))
"Face used to render cyan color code."
:group 'term
:version "28.1")
(defface term-color-white
'((t :inherit ansi-color-white))
"Face used to render white color code."
:group 'term
:version "28.1")
(defface term-color-bright-black
'((t :inherit ansi-color-bright-black))
"Face used to render bright black color code."
:group 'term
:version "28.1")
(defface term-color-bright-red
'((t :inherit ansi-color-bright-red))
"Face used to render bright red color code."
:group 'term
:version "28.1")
(defface term-color-bright-green
'((t :inherit ansi-color-bright-green))
"Face used to render bright green color code."
:group 'term
:version "28.1")
(defface term-color-bright-yellow
'((t :inherit ansi-color-bright-yellow))
"Face used to render bright yellow color code."
:group 'term
:version "28.1")
(defface term-color-bright-blue
'((t :inherit ansi-color-bright-blue))
"Face used to render bright blue color code."
:group 'term
:version "28.1")
(defface term-color-bright-magenta
'((t :inherit ansi-color-bright-magenta))
"Face used to render bright magenta color code."
:group 'term
:version "28.1")
(defface term-color-bright-cyan
'((t :inherit ansi-color-bright-cyan))
"Face used to render bright cyan color code."
:group 'term
:version "28.1")
(defface term-color-bright-white
'((t :inherit ansi-color-bright-white))
"Face used to render bright white color code."
:group 'term
:version "28.1")
(defcustom term-buffer-maximum-size 8192
"The maximum size in lines for term buffers.
Term buffers are truncated from the top to be no greater than this number.
Notice that a setting of 0 means \"don't truncate anything\". This variable
is buffer-local."
:group 'term
:type 'natnum
:version "27.1")
(defcustom term-bind-function-keys nil
"If nil, don't alter <f1>, <f2> and so on.
If non-nil, bind these keys in `term-mode' and send them to the
underlying shell."
:type 'boolean
:version "29.1")
;; Set up term-raw-map, etc.
(defvar term-raw-map
(let* ((map (make-keymap))
(esc-map (make-keymap))
(i 0))
(while (< i 128)
(define-key map (make-string 1 i) 'term-send-raw)
;; Avoid O and [. They are used in escape sequences for various keys.
(unless (or (eq i ?O) (eq i 91))
(define-key esc-map (make-string 1 i) 'term-send-raw-meta))
(setq i (1+ i)))
(define-key map [remap self-insert-command] 'term-send-raw)
(define-key map "\e" esc-map)
;; Added nearly all the 'gray keys' -mm
(define-key map [mouse-2] 'term-mouse-paste)
(define-key map [up] 'term-send-up)
(define-key map [down] 'term-send-down)
(define-key map [right] 'term-send-right)
(define-key map [left] 'term-send-left)
(define-key map [C-up] 'term-send-ctrl-up)
(define-key map [C-down] 'term-send-ctrl-down)
(define-key map [C-right] 'term-send-ctrl-right)
(define-key map [C-left] 'term-send-ctrl-left)
(define-key map [delete] 'term-send-del)
(define-key map [deletechar] 'term-send-del)
(define-key map [backspace] 'term-send-backspace)
(define-key map [home] 'term-send-home)
(define-key map [end] 'term-send-end)
(define-key map [insert] 'term-send-insert)
(define-key map [S-prior] 'scroll-down)
(define-key map [S-next] 'scroll-up)
(define-key map [S-insert] 'term-paste)
(define-key map [prior] 'term-send-prior)
(define-key map [next] 'term-send-next)
(define-key map [xterm-paste] #'term--xterm-paste)
(define-key map [?\C-/] #'term-send-C-_)
(define-key map [?\C- ] #'term-send-C-@)
(define-key map [?\C-\M-/] #'term-send-C-M-_)
(define-key map [?\C-\M- ] #'term-send-C-M-@)
(when term-bind-function-keys
(dotimes (key 21)
(keymap-set map (format "<f%d>" key) #'term-send-function-key)))
map)
"Keyboard map for sending characters directly to the inferior process.
For custom keybindings purposes please note there is also
`term-mode-map'")
(easy-menu-define term-terminal-menu
(list term-mode-map term-raw-map term-pager-break-map)
"Terminal menu for Term mode."
'("Terminal"
["Line mode" term-line-mode :active (term-in-char-mode)
:help "Switch to line (cooked) sub-mode of term mode"]
["Character mode" term-char-mode :active (term-in-line-mode)
:help "Switch to char (raw) sub-mode of term mode"]
["Paging" term-pager-toggle :style toggle :selected term-pager-count
:help "Toggle paging feature"]))
(defun term--update-term-menu (&optional force)
(when (and (lookup-key term-mode-map [menu-bar terminal])
(or force (frame-or-buffer-changed-p)))
(let ((buffer-list (match-buffers '(derived-mode . term-mode))))
(easy-menu-change
nil
"Terminal Buffers"
(mapcar
(lambda (buffer)
(vector (format "%s (%s)" (buffer-name buffer)
(abbreviate-file-name
(buffer-local-value 'default-directory buffer)))
(lambda ()
(interactive)
(switch-to-buffer buffer))))
buffer-list)
nil