-
Notifications
You must be signed in to change notification settings - Fork 10
/
term-keys-konsole.el
118 lines (96 loc) · 3.83 KB
/
term-keys-konsole.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
;;; term-keys-konsole.el --- term-keys support for Konsole
;; 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 Konsole terminal emulator to interoperate with
;; the term-keys package.
;; For more information, please see the accompanying README.md file.
;;; Code:
(require 'term-keys)
(defgroup term-keys/konsole nil
"`term-keys' options for the Konsole terminal emulator."
:group 'term-keys)
(define-widget 'term-keys/konsole-modifier 'lazy
"Choice for Konsole key binding modifiers and state flags."
:type '(choice (const "Shift")
(const "Ctrl")
(const "Alt")
(const "Meta")
(const "KeyPad")
(const "AppScreen")
(const "AppCursorKeys")
(const "NewLine")
(const "Ansi")
(const "AnyModifier")
(const "AppKeypad")
(const :tag "(none)" nil)))
(defcustom term-keys/konsole-modifier-map ["Shift" "Ctrl" "Alt" "Meta" nil nil]
"Modifier keys for Konsole key bindings.
This should be a vector of 6 elements, with each element being a
string indicating the name of the Konsole modifier or state flag
corresponding to the Emacs modifiers Shift, Control, Meta, Super,
Hyper and Alt respectively, as they should appear in generated
Konsole .keytab files. nil indicates that there is no mapping
for this modifier."
:type '(vector
(term-keys/konsole-modifier :tag "Shift")
(term-keys/konsole-modifier :tag "Control")
(term-keys/konsole-modifier :tag "Meta")
(term-keys/konsole-modifier :tag "Super")
(term-keys/konsole-modifier :tag "Hyper")
(term-keys/konsole-modifier :tag "Alt"))
:group 'term-keys/konsole)
(defun term-keys/konsole-keytab ()
"Construct Konsole key binding configuration as .keytab file syntax.
This function returns, as a string, a Konsole keytab which can be
used to configure Konsole to encode term-keys key sequences,
according to the term-keys configuration.
The returned string is suitable to be pasted as-is to the end of
an existing Konsole .keytab file."
(apply #'concat
(term-keys/iterate-keys
(lambda (index keymap mods)
;; Skip key combinations with unrepresentable modifiers
(unless (cl-reduce (lambda (x y) (or x y)) ; any
(mapcar (lambda (n) ; active modifier mapped to nil
(and (elt mods n)
(not (elt term-keys/konsole-modifier-map n))))
(number-sequence 0 (1- (length mods))))) ; 0..5
(format "key %s%s : \"%s\"\n"
(or ; Apply shift
(and (elt mods 0) ; With Shift?
(elt keymap 9)) ; Use shifted column
(elt keymap 3)) ; Use non-shifted column
(mapconcat
(lambda (n)
(if (elt term-keys/konsole-modifier-map n)
(concat
(if (elt mods n) "+" "-")
(elt term-keys/konsole-modifier-map n))
""))
(number-sequence 0 (1- (length mods)))
"")
(mapconcat ; hex-escaped sequence
(lambda (x) (format "\\x%02X" x))
(append
term-keys/prefix
(term-keys/encode-key index mods)
term-keys/suffix
nil)
"")))))))
(provide 'term-keys-konsole)
;;; term-keys-konsole.el ends here