-
Notifications
You must be signed in to change notification settings - Fork 10
/
term-keys-xterm.el
140 lines (108 loc) · 4.11 KB
/
term-keys-xterm.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
;;; term-keys-xterm.el --- term-keys support for xterm
;; This file is not part of GNU Emacs.
;; This program 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 2 of the License, or
;; (at your option) any later version.
;;
;; This program 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 this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This file contains supplementary code for aiding in the
;; configuration of the xterm terminal emulator to interoperate with
;; the term-keys package.
;; For more information, please see the accompanying README.md file.
;;; Code:
(require 'term-keys)
(defconst term-keys/xterm-modifier-names ["Shift" "Ctrl" "Meta" "Super" "Hyper" "Alt"]
"Modifier key names in xterm key translation syntax.")
(defun term-keys/xterm-format-key (key mods)
"Format key modifiers in xterm key translation syntax.
Returns the xterm translation string corresponding to the KEY and
modifier state MODS."
(concat
(cl-loop for modflag across mods
for index from 0
concat
(concat
(if modflag " " "~")
(elt term-keys/xterm-modifier-names index)
" "))
"<Key> "
key))
(defun term-keys/xterm-translations ()
"Construct xterm configuration in the form of translation entries.
This function returns, as a list of strings (one string per
line), the xterm translation entries necessary to configure xterm
to encode term-keys key sequences, according to the term-keys
configuration."
(term-keys/iterate-keys
(lambda (index keymap mods)
(format "%-55s: %s"
(term-keys/xterm-format-key (elt keymap 1) mods)
(mapconcat
(lambda (c) (format "string(0x%02x)" c))
(append
term-keys/prefix
(term-keys/encode-key index mods)
term-keys/suffix
nil)
" ")))))
(defun term-keys/xterm-xresources ()
"Construct xterm configuration in the form of .Xresources entries.
This function returns, as a string, the .Xresources entries
necessary to configure xterm to encode term-keys key sequences,
according to the term-keys configuration.
The returned string is suitable to be added as-is to an
~/.Xresources file."
(concat
"\n*VT100.Translations: #override \\\n"
(mapconcat #'identity
(term-keys/xterm-translations)
" \\n\\\n")
"\n\n"))
(defun term-keys/xterm-args ()
"Construct xterm configuration in the form of command line arguments.
This function returns a list of xterm command line arguments
necessary to configure the terminal emulator to encode key
sequences, according to the term-keys configuration."
(list
"-xrm"
(mapconcat #'identity
(cons
"XTerm.VT100.translations: #override"
(term-keys/xterm-translations))
"\\n")))
(defun term-keys/xterm-script ()
"Construct xterm configuration in the form of a shell script.
This function returns, as a string, a shell script which launches
xterm configured to encode term-keys key sequences, according to
the term-keys configuration.
The returned string is suitable to be saved as-is in an
executable file and used for launching xterm."
(concat
"#!/bin/sh\n"
"exec xterm \\\n\t"
(mapconcat #'shell-quote-argument (term-keys/xterm-args) " \\\n\t")
" \\\n\t\"$@\"\n"))
(defun term-keys/xterm-run-emacs ()
"Launch Emacs via xterm enhanced with term-keys.
This function is used for testing and as an example."
(apply #'start-process "xterm" nil "xterm"
(append
(term-keys/xterm-args)
(list
"-xrm" "XTerm*eightBitInput: false"
"-e" (car command-line-args) "-nw"
"--load" term-keys/main-file-name
"--funcall" "term-keys/init"
))))
(provide 'term-keys-xterm)
;;; term-keys-xterm.el ends here