Skip to content

Commit

Permalink
Initial Alacritty support
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Dec 29, 2021
1 parent 75d0f50 commit 9584a86
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 94 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This package allows configuring Emacs and a supported terminal emulator to handl
* [urxvt (rxvt-unicode)](#urxvt-rxvt-unicode)
* [xterm](#xterm)
* [kitty](#kitty)
* [Alacritty](#alacritty)
* [Konsole](#konsole)
* [Yakuake](#yakuake)
* [Linux console](#linux-console)
Expand Down Expand Up @@ -212,6 +213,23 @@ Then, add the output to your main `kitty.conf` file.

You can customize kitty's mapping of GLFW modifiers to Emacs modifiers in the generated configuration using the respective `customize` group, i.e.: <kbd>M-:</kbd>`(progn (require 'term-keys-kitty) (customize-group 'term-keys/glfw))`

#### Alacritty

[Alacritty](https://github.com/alacritty/alacritty) is configured via its `alacritty.yml` configuration file.

To configure alacritty for `term-keys`, use `term-keys/alacritty-config` to generate a `alacritty.yml` fragment:

```elisp
(require 'term-keys-alacritty)
(with-temp-buffer
(insert (term-keys/alacritty-config))
(write-region (point-min) (point-max) "~/alacritty-for-term-keys.yml"))
```

Then, add the output to your main `alacritty.yml` file.

You can customize Alacritty's mapping of its supported modifiers to Emacs modifiers in the generated configuration using the respective `customize` group, i.e.: <kbd>M-:</kbd>`(progn (require 'term-keys-alacritty) (customize-group 'term-keys/alacritty))`

#### Konsole

Konsole provides an interface for adding new and editing existing escape sequences for key combinations
Expand Down
114 changes: 114 additions & 0 deletions term-keys-alacritty.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
;;; term-keys-alacritty.el --- term-keys support for Alacritty

;; 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 Alacritty 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/alacritty nil
"`term-keys' options for ALACRITTY-based terminal emulators."
:group 'term-keys)

(define-widget 'term-keys/alacritty-modifier 'lazy
"Choice for Alacritty key modifier state flags."
:type '(choice (const "Command")
(const "Control")
(const "Option")
(const "Super")
(const "Shift")
(const "Alt")
(const :tag "(none)" nil)))


(defcustom term-keys/alacritty-modifier-map ["Shift" "Control" "Alt" "Super" "Command" "Option"]
"Map of Alacritty modifiers to Emacs modifiers.
This should be a vector of 6 elements, with each element being a
string indicating the name of the Alacritty modifier name
corresponding to the Emacs modifiers Shift, Control, Meta, Super,
Hyper and Alt respectively. nil indicates that there is no
mapping for this modifier."
:type '(vector
(term-keys/alacritty-modifier :tag "Shift")
(term-keys/alacritty-modifier :tag "Control")
(term-keys/alacritty-modifier :tag "Meta")
(term-keys/alacritty-modifier :tag "Super")
(term-keys/alacritty-modifier :tag "Hyper")
(term-keys/alacritty-modifier :tag "Alt"))
:group 'term-keys/alacritty)


(defun term-keys/alacritty-mods-representable (mods)
"Return non-nil if the given MODS vector is representable in ALACRITTY."
(cl-reduce (lambda (x y) (and x y)) ; all
(mapcar (lambda (n)
(or (not (elt mods n)) ; inactive modifier
(elt term-keys/alacritty-modifier-map n))) ; mapped
(number-sequence 0 (1- (length mods)))))) ; 0..5


(defun term-keys/alacritty-format-mods (mods)
"Format MODS in Alacritty syntax."
(if (cl-reduce (lambda (x y) (or x y)) mods)
(concat
", mods: "
(mapconcat
(lambda (n)
(elt term-keys/alacritty-modifier-map n))
(cl-remove-if-not (lambda (n) (elt mods n))
(number-sequence 0 (1- (length mods))))
"|"))
""))


(defun term-keys/alacritty-config ()
"Construct Alacritty configuration (alacritty.yml fragment).
This function returns, as a string, an alacritty.yml fragment
necessary to configure Alacritty to encode term-keys key
sequences, according to the term-keys configuration."
(apply #'concat
"key_bindings:\n"
(term-keys/iterate-keys
(lambda (index keymap mods)
(format "- { key: %s%s, chars: \"%s\" }\n"
(elt keymap 8)
(term-keys/alacritty-format-mods mods)
(mapconcat
(lambda (c) (format "\\x%02x" c))
(append
term-keys/prefix
(term-keys/encode-key index mods)
term-keys/suffix
nil)
""))))))


(provide 'term-keys-alacritty)
;;; term-keys-alacritty.el ends here
192 changes: 98 additions & 94 deletions term-keys.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,98 +48,98 @@ file."


(defcustom term-keys/mapping
;; Emacs X11 TTY Qt macOS Emacs shifted X11 shifted GLFW

'(["<escape>" "Escape" 1 "Esc" #x001B nil nil "ESCAPE" ]
["<f1>" "F1" 59 "F1" #xF704 nil nil "F1" ]
["<f2>" "F2" 60 "F2" #xF705 nil nil "F2" ]
["<f3>" "F3" 61 "F3" #xF706 nil nil "F3" ]
["<f4>" "F4" 62 "F4" #xF707 nil nil "F4" ]
["<f5>" "F5" 63 "F5" #xF708 nil nil "F5" ]
["<f6>" "F6" 64 "F6" #xF709 nil nil "F6" ]
["<f7>" "F7" 65 "F7" #xF70A nil nil "F7" ]
["<f8>" "F8" 66 "F8" #xF70B nil nil "F8" ]
["<f9>" "F9" 67 "F9" #xF70C nil nil "F9" ]
["<f10>" "F10" 68 "F10" #xF70D nil nil "F10" ]
["<f11>" "F11" 87 "F11" #xF70E nil nil "F11" ]
["<f12>" "F12" 88 "F12" #xF70F nil nil "F12" ]
["<print>" "Print" 99 "Print" #xF710 nil nil "PRINT_SCREEN" ]
["<Scroll_Lock>" "Scroll_Lock" 70 "ScrollLock" nil nil nil "SCROLL_LOCK" ]
["<pause>" "Pause" 119 "Pause" nil nil nil "PAUSE" ]

["`" "grave" 43 "`" ?` "~" "asciitilde" "GRAVE_ACCENT" ]
["1" "1" 2 "1" ?1 "!" "exclam" "1" ]
["2" "2" 3 "2" ?2 "@" "at" "2" ]
["3" "3" 4 "3" ?3 "#" "numbersign" "3" ]
["4" "4" 5 "4" ?4 "$" "dollar" "4" ]
["5" "5" 6 "5" ?5 "%" "percent" "5" ]
["6" "6" 7 "6" ?6 "^" "asciicircum" "6" ]
["7" "7" 8 "7" ?7 "&" "ampersand" "7" ]
["8" "8" 9 "8" ?8 "*" "asterisk" "8" ]
["9" "9" 10 "9" ?9 "(" "parenleft" "9" ]
["0" "0" 11 "0" ?0 ")" "parenright" "0" ]
["-" "minus" 12 "-" ?- "_" "underscore" "MINUS" ]
["=" "equal" 13 "=" ?= "+" "plus" "EQUAL" ]
["<backspace>" "BackSpace" 14 "Backspace" #x007F nil nil "BACKSPACE" ]
["<tab>" "Tab" 15 "Tab" #x0009 "<backtab>" "ISO_Left_Tab" "TAB" ]
["q" "q" 16 "Q" ?q "Q" "Q" "Q" ]
["w" "w" 17 "W" ?w "W" "W" "W" ]
["e" "e" 18 "E" ?e "E" "E" "E" ]
["r" "r" 19 "R" ?r "R" "R" "R" ]
["t" "t" 20 "T" ?t "T" "T" "T" ]
["y" "y" 21 "Y" ?y "Y" "Y" "Y" ]
["u" "u" 22 "U" ?u "U" "U" "U" ]
["i" "i" 23 "I" ?i "I" "I" "I" ]
["o" "o" 24 "O" ?o "O" "O" "O" ]
["p" "p" 25 "P" ?p "P" "P" "P" ]
["[" "bracketleft" 26 "[" ?\[ "{" "braceleft" "LEFT_BRACKET" ]
["]" "bracketright" 27 "]" ?\] "}" "braceright" "RIGHT_BRACKET" ]
["<return>" "Return" 28 "Return" #x000D nil nil "ENTER" ]
["<Caps_Lock>" "Caps_Lock" 58 "CapsLock" nil nil nil "CAPS_LOCK" ]
["a" "a" 30 "A" ?a "A" "A" "A" ]
["s" "s" 31 "S" ?s "S" "S" "S" ]
["d" "d" 32 "D" ?d "D" "D" "D" ]
["f" "f" 33 "F" ?f "F" "F" "F" ]
["g" "g" 34 "G" ?g "G" "G" "G" ]
["h" "h" 35 "H" ?h "H" "H" "H" ]
["j" "j" 36 "J" ?j "J" "J" "J" ]
["k" "k" 37 "K" ?k "K" "K" "K" ]
["l" "l" 38 "L" ?l "L" "L" "L" ]
[";" "semicolon" 39 ";" ?\; ":" "colon" "SEMICOLON" ]
["'" "apostrophe" 40 "'" ?' "\"" "quotedbl" "APOSTROPHE" ]
[nil "Shift_L" 42 "Shift" nil nil nil "LEFT_SHIFT" ]
["\\" "backslash" 43 "\\" ?\\ "|" "bar" "BACKSLASH" ]
["z" "z" 44 "Z" ?z "Z" "Z" "Z" ]
["x" "x" 45 "X" ?x "X" "X" "X" ]
["c" "c" 46 "C" ?c "C" "C" "C" ]
["v" "v" 47 "V" ?v "V" "V" "V" ]
["b" "b" 48 "B" ?b "B" "B" "B" ]
["n" "n" 49 "N" ?n "N" "N" "N" ]
["m" "m" 50 "M" ?m "M" "M" "M" ]
["," "comma" 51 "," ?, "<" "less" "COMMA" ]
["." "period" 52 "." ?. ">" "greater" "PERIOD" ]
["/" "slash" 53 "/" ?/ "?" "question" "SLASH" ]
[nil "Shift_R" 54 "Shift" nil nil nil "RIGHT_SHIFT" ]
[nil "Control_L" 29 "Ctrl" nil nil nil "LEFT_CONTROL" ]
[nil "Super_L" 125 "Meta" nil nil nil "LEFT_SUPER" ]
[nil "Alt_L" 56 "Alt" nil nil nil "LEFT_ALT" ]
["SPC" "space" 57 "Space" #x0020 nil nil "SPACE" ]
[nil "Alt_R" 100 "Alt" nil nil nil "RIGHT_ALT" ]
[nil "Super_R" 126 "Meta" nil nil nil "RIGHT_SUPER" ]
["<menu>" "Menu" 127 "Menu" #x0010 nil nil "MENU" ]
[nil "Control_R" 97 "Ctrl" nil nil nil "RIGHT_CONTROL" ]

["<up>" "Up" 103 "Up" #xF700 nil nil "UP" ]
["<down>" "Down" 108 "Down" #xF701 nil nil "DOWN" ]
["<left>" "Left" 105 "Left" #xF702 nil nil "LEFT" ]
["<right>" "Right" 106 "Right" #xF703 nil nil "RIGHT" ]

["<insert>" "Insert" 110 "Ins" #xF746 nil nil "INSERT" ]
["<delete>" "Delete" 111 "Del" #xF728 nil nil "DELETE" ]
["<home>" "Home" 102 "Home" #xF729 nil nil "HOME" ]
["<end>" "End" 107 "End" #xF72B nil nil "END" ]
["<prior>" "Prior" 104 "PgUp" #xF72C nil nil "PAGE_UP" ]
["<next>" "Next" 109 "PgDown" #xF72D nil nil "PAGE_DOWN" ]
;; Emacs X11 TTY Qt macOS Emacs shifted X11 shifted GLFW winit

'(["<escape>" "Escape" 1 "Esc" #x001B nil nil "ESCAPE" "Escape" ]
["<f1>" "F1" 59 "F1" #xF704 nil nil "F1" "F1" ]
["<f2>" "F2" 60 "F2" #xF705 nil nil "F2" "F2" ]
["<f3>" "F3" 61 "F3" #xF706 nil nil "F3" "F3" ]
["<f4>" "F4" 62 "F4" #xF707 nil nil "F4" "F4" ]
["<f5>" "F5" 63 "F5" #xF708 nil nil "F5" "F5" ]
["<f6>" "F6" 64 "F6" #xF709 nil nil "F6" "F6" ]
["<f7>" "F7" 65 "F7" #xF70A nil nil "F7" "F7" ]
["<f8>" "F8" 66 "F8" #xF70B nil nil "F8" "F8" ]
["<f9>" "F9" 67 "F9" #xF70C nil nil "F9" "F9" ]
["<f10>" "F10" 68 "F10" #xF70D nil nil "F10" "F10" ]
["<f11>" "F11" 87 "F11" #xF70E nil nil "F11" "F11" ]
["<f12>" "F12" 88 "F12" #xF70F nil nil "F12" "F12" ]
["<print>" "Print" 99 "Print" #xF710 nil nil "PRINT_SCREEN" "Snapshot" ]
["<Scroll_Lock>" "Scroll_Lock" 70 "ScrollLock" nil nil nil "SCROLL_LOCK" "Scroll" ]
["<pause>" "Pause" 119 "Pause" nil nil nil "PAUSE" "Pause" ]

["`" "grave" 43 "`" ?` "~" "asciitilde" "GRAVE_ACCENT" "Grave" ]
["1" "1" 2 "1" ?1 "!" "exclam" "1" "Key1" ]
["2" "2" 3 "2" ?2 "@" "at" "2" "Key2" ]
["3" "3" 4 "3" ?3 "#" "numbersign" "3" "Key3" ]
["4" "4" 5 "4" ?4 "$" "dollar" "4" "Key4" ]
["5" "5" 6 "5" ?5 "%" "percent" "5" "Key5" ]
["6" "6" 7 "6" ?6 "^" "asciicircum" "6" "Key6" ]
["7" "7" 8 "7" ?7 "&" "ampersand" "7" "Key7" ]
["8" "8" 9 "8" ?8 "*" "asterisk" "8" "Key8" ]
["9" "9" 10 "9" ?9 "(" "parenleft" "9" "Key9" ]
["0" "0" 11 "0" ?0 ")" "parenright" "0" "Key0" ]
["-" "minus" 12 "-" ?- "_" "underscore" "MINUS" "Minus" ]
["=" "equal" 13 "=" ?= "+" "plus" "EQUAL" "Equals" ]
["<backspace>" "BackSpace" 14 "Backspace" #x007F nil nil "BACKSPACE" "Back" ]
["<tab>" "Tab" 15 "Tab" #x0009 "<backtab>" "ISO_Left_Tab" "TAB" "Tab" ]
["q" "q" 16 "Q" ?q "Q" "Q" "Q" "Q" ]
["w" "w" 17 "W" ?w "W" "W" "W" "W" ]
["e" "e" 18 "E" ?e "E" "E" "E" "E" ]
["r" "r" 19 "R" ?r "R" "R" "R" "R" ]
["t" "t" 20 "T" ?t "T" "T" "T" "T" ]
["y" "y" 21 "Y" ?y "Y" "Y" "Y" "Y" ]
["u" "u" 22 "U" ?u "U" "U" "U" "U" ]
["i" "i" 23 "I" ?i "I" "I" "I" "I" ]
["o" "o" 24 "O" ?o "O" "O" "O" "O" ]
["p" "p" 25 "P" ?p "P" "P" "P" "P" ]
["[" "bracketleft" 26 "[" ?\[ "{" "braceleft" "LEFT_BRACKET" "LBracket" ]
["]" "bracketright" 27 "]" ?\] "}" "braceright" "RIGHT_BRACKET" "RBracket" ]
["<return>" "Return" 28 "Return" #x000D nil nil "ENTER" "Return" ]
["<Caps_Lock>" "Caps_Lock" 58 "CapsLock" nil nil nil "CAPS_LOCK" "Capital" ]
["a" "a" 30 "A" ?a "A" "A" "A" "A" ]
["s" "s" 31 "S" ?s "S" "S" "S" "S" ]
["d" "d" 32 "D" ?d "D" "D" "D" "D" ]
["f" "f" 33 "F" ?f "F" "F" "F" "F" ]
["g" "g" 34 "G" ?g "G" "G" "G" "G" ]
["h" "h" 35 "H" ?h "H" "H" "H" "H" ]
["j" "j" 36 "J" ?j "J" "J" "J" "J" ]
["k" "k" 37 "K" ?k "K" "K" "K" "K" ]
["l" "l" 38 "L" ?l "L" "L" "L" "L" ]
[";" "semicolon" 39 ";" ?\; ":" "colon" "SEMICOLON" "Semicolon" ]
["'" "apostrophe" 40 "'" ?' "\"" "quotedbl" "APOSTROPHE" "Apostrophe" ]
[nil "Shift_L" 42 "Shift" nil nil nil "LEFT_SHIFT" "LShift" ]
["\\" "backslash" 43 "\\" ?\\ "|" "bar" "BACKSLASH" "Backslash" ]
["z" "z" 44 "Z" ?z "Z" "Z" "Z" "Z" ]
["x" "x" 45 "X" ?x "X" "X" "X" "X" ]
["c" "c" 46 "C" ?c "C" "C" "C" "C" ]
["v" "v" 47 "V" ?v "V" "V" "V" "V" ]
["b" "b" 48 "B" ?b "B" "B" "B" "B" ]
["n" "n" 49 "N" ?n "N" "N" "N" "N" ]
["m" "m" 50 "M" ?m "M" "M" "M" "M" ]
["," "comma" 51 "," ?, "<" "less" "COMMA" "Comma" ]
["." "period" 52 "." ?. ">" "greater" "PERIOD" "Period" ]
["/" "slash" 53 "/" ?/ "?" "question" "SLASH" "Slash" ]
[nil "Shift_R" 54 "Shift" nil nil nil "RIGHT_SHIFT" "RShift" ]
[nil "Control_L" 29 "Ctrl" nil nil nil "LEFT_CONTROL" "LControl" ]
[nil "Super_L" 125 "Meta" nil nil nil "LEFT_SUPER" "LWin" ]
[nil "Alt_L" 56 "Alt" nil nil nil "LEFT_ALT" "LAlt" ]
["SPC" "space" 57 "Space" #x0020 nil nil "SPACE" "Space" ]
[nil "Alt_R" 100 "Alt" nil nil nil "RIGHT_ALT" "RAlt" ]
[nil "Super_R" 126 "Meta" nil nil nil "RIGHT_SUPER" "RWin" ]
["<menu>" "Menu" 127 "Menu" #x0010 nil nil "MENU" "Apps" ]
[nil "Control_R" 97 "Ctrl" nil nil nil "RIGHT_CONTROL" "RControl" ]

["<up>" "Up" 103 "Up" #xF700 nil nil "UP" "Up" ]
["<down>" "Down" 108 "Down" #xF701 nil nil "DOWN" "Down" ]
["<left>" "Left" 105 "Left" #xF702 nil nil "LEFT" "Left" ]
["<right>" "Right" 106 "Right" #xF703 nil nil "RIGHT" "Right" ]

["<insert>" "Insert" 110 "Ins" #xF746 nil nil "INSERT" "Insert" ]
["<delete>" "Delete" 111 "Del" #xF728 nil nil "DELETE" "Delete" ]
["<home>" "Home" 102 "Home" #xF729 nil nil "HOME" "Home" ]
["<end>" "End" 107 "End" #xF72B nil nil "END" "End" ]
["<prior>" "Prior" 104 "PgUp" #xF72C nil nil "PAGE_UP" "PageUp" ]
["<next>" "Next" 109 "PgDown" #xF72D nil nil "PAGE_DOWN" "PageDown" ]

;; Add new entries at the end of the list, to avoid disrupting
;; existing configurations.
Expand All @@ -148,7 +148,7 @@ file."
)
"List of keys supported by the `term-keys' package.
Each item in the list is an 8-element vector:
Each item in the list is a 9-element vector:
0: The Emacs key name, as it occurs in `describe-key' or `kbd'.
nil can be used to indicate keys which Emacs currently does
Expand Down Expand Up @@ -183,7 +183,11 @@ Each item in the list is an 8-element vector:
7: The GLFW key name, without the \"GLFW_KEY_\" prefix.
A list can be found here:
https://www.glfw.org/docs/3.3/group__keys.html"
https://www.glfw.org/docs/3.3/group__keys.html
8: The key name as it appears in the Rust winit crate's
VirtualKeyCode enumeration:
https://docs.rs/glutin/0.28.0/glutin/event/enum.VirtualKeyCode.html"
:type '(repeat
(vector
:tag "Key mapping"
Expand Down

0 comments on commit 9584a86

Please sign in to comment.