├── COPYING.md ├── README.md ├── term-keys-alacritty.el ├── term-keys-glfw-mods.el ├── term-keys-kitty.el ├── term-keys-konsole.el ├── term-keys-linux.el ├── term-keys-st.el ├── term-keys-terminal-app.el ├── term-keys-urxvt.el ├── term-keys-wezterm.el ├── term-keys-windows-terminal.el ├── term-keys-x11.el ├── term-keys-xterm.el └── term-keys.el /COPYING.md: -------------------------------------------------------------------------------- 1 | ### GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 2, June 1991 4 | 5 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 6 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | 11 | ### Preamble 12 | 13 | The licenses for most software are designed to take away your freedom 14 | to share and change it. By contrast, the GNU General Public License is 15 | intended to guarantee your freedom to share and change free 16 | software--to make sure the software is free for all its users. This 17 | General Public License applies to most of the Free Software 18 | Foundation's software and to any other program whose authors commit to 19 | using it. (Some other Free Software Foundation software is covered by 20 | the GNU Lesser General Public License instead.) You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not 24 | price. Our General Public Licenses are designed to make sure that you 25 | have the freedom to distribute copies of free software (and charge for 26 | this service if you wish), that you receive source code or can get it 27 | if you want it, that you can change the software or use pieces of it 28 | in new free programs; and that you know you can do these things. 29 | 30 | To protect your rights, we need to make restrictions that forbid 31 | anyone to deny you these rights or to ask you to surrender the rights. 32 | These restrictions translate to certain responsibilities for you if 33 | you distribute copies of the software, or if you modify it. 34 | 35 | For example, if you distribute copies of such a program, whether 36 | gratis or for a fee, you must give the recipients all the rights that 37 | you have. You must make sure that they, too, receive or can get the 38 | source code. And you must show them these terms so they know their 39 | rights. 40 | 41 | We protect your rights with two steps: (1) copyright the software, and 42 | (2) offer you this license which gives you legal permission to copy, 43 | distribute and/or modify the software. 44 | 45 | Also, for each author's protection and ours, we want to make certain 46 | that everyone understands that there is no warranty for this free 47 | software. If the software is modified by someone else and passed on, 48 | we want its recipients to know that what they have is not the 49 | original, so that any problems introduced by others will not reflect 50 | on the original authors' reputations. 51 | 52 | Finally, any free program is threatened constantly by software 53 | patents. We wish to avoid the danger that redistributors of a free 54 | program will individually obtain patent licenses, in effect making the 55 | program proprietary. To prevent this, we have made it clear that any 56 | patent must be licensed for everyone's free use or not licensed at 57 | all. 58 | 59 | The precise terms and conditions for copying, distribution and 60 | modification follow. 61 | 62 | ### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 63 | 64 | **0.** This License applies to any program or other work which 65 | contains a notice placed by the copyright holder saying it may be 66 | distributed under the terms of this General Public License. The 67 | "Program", below, refers to any such program or work, and a "work 68 | based on the Program" means either the Program or any derivative work 69 | under copyright law: that is to say, a work containing the Program or 70 | a portion of it, either verbatim or with modifications and/or 71 | translated into another language. (Hereinafter, translation is 72 | included without limitation in the term "modification".) Each licensee 73 | is addressed as "you". 74 | 75 | Activities other than copying, distribution and modification are not 76 | covered by this License; they are outside its scope. The act of 77 | running the Program is not restricted, and the output from the Program 78 | is covered only if its contents constitute a work based on the Program 79 | (independent of having been made by running the Program). Whether that 80 | is true depends on what the Program does. 81 | 82 | **1.** You may copy and distribute verbatim copies of the Program's 83 | source code as you receive it, in any medium, provided that you 84 | conspicuously and appropriately publish on each copy an appropriate 85 | copyright notice and disclaimer of warranty; keep intact all the 86 | notices that refer to this License and to the absence of any warranty; 87 | and give any other recipients of the Program a copy of this License 88 | along with the Program. 89 | 90 | You may charge a fee for the physical act of transferring a copy, and 91 | you may at your option offer warranty protection in exchange for a 92 | fee. 93 | 94 | **2.** You may modify your copy or copies of the Program or any 95 | portion of it, thus forming a work based on the Program, and copy and 96 | distribute such modifications or work under the terms of Section 1 97 | above, provided that you also meet all of these conditions: 98 | 99 | 100 | **a)** You must cause the modified files to carry prominent notices 101 | stating that you changed the files and the date of any change. 102 | 103 | 104 | **b)** You must cause any work that you distribute or publish, that in 105 | whole or in part contains or is derived from the Program or any part 106 | thereof, to be licensed as a whole at no charge to all third parties 107 | under the terms of this License. 108 | 109 | 110 | **c)** If the modified program normally reads commands interactively 111 | when run, you must cause it, when started running for such interactive 112 | use in the most ordinary way, to print or display an announcement 113 | including an appropriate copyright notice and a notice that there is 114 | no warranty (or else, saying that you provide a warranty) and that 115 | users may redistribute the program under these conditions, and telling 116 | the user how to view a copy of this License. (Exception: if the 117 | Program itself is interactive but does not normally print such an 118 | announcement, your work based on the Program is not required to print 119 | an announcement.) 120 | 121 | These requirements apply to the modified work as a whole. If 122 | identifiable sections of that work are not derived from the Program, 123 | and can be reasonably considered independent and separate works in 124 | themselves, then this License, and its terms, do not apply to those 125 | sections when you distribute them as separate works. But when you 126 | distribute the same sections as part of a whole which is a work based 127 | on the Program, the distribution of the whole must be on the terms of 128 | this License, whose permissions for other licensees extend to the 129 | entire whole, and thus to each and every part regardless of who wrote 130 | it. 131 | 132 | Thus, it is not the intent of this section to claim rights or contest 133 | your rights to work written entirely by you; rather, the intent is to 134 | exercise the right to control the distribution of derivative or 135 | collective works based on the Program. 136 | 137 | In addition, mere aggregation of another work not based on the Program 138 | with the Program (or with a work based on the Program) on a volume of 139 | a storage or distribution medium does not bring the other work under 140 | the scope of this License. 141 | 142 | **3.** You may copy and distribute the Program (or a work based on it, 143 | under Section 2) in object code or executable form under the terms of 144 | Sections 1 and 2 above provided that you also do one of the following: 145 | 146 | 147 | **a)** Accompany it with the complete corresponding machine-readable 148 | source code, which must be distributed under the terms of Sections 1 149 | and 2 above on a medium customarily used for software interchange; or, 150 | 151 | 152 | **b)** Accompany it with a written offer, valid for at least three 153 | years, to give any third party, for a charge no more than your cost of 154 | physically performing source distribution, a complete machine-readable 155 | copy of the corresponding source code, to be distributed under the 156 | terms of Sections 1 and 2 above on a medium customarily used for 157 | software interchange; or, 158 | 159 | 160 | **c)** Accompany it with the information you received as to the offer 161 | to distribute corresponding source code. (This alternative is allowed 162 | only for noncommercial distribution and only if you received the 163 | program in object code or executable form with such an offer, in 164 | accord with Subsection b above.) 165 | 166 | The source code for a work means the preferred form of the work for 167 | making modifications to it. For an executable work, complete source 168 | code means all the source code for all modules it contains, plus any 169 | associated interface definition files, plus the scripts used to 170 | control compilation and installation of the executable. However, as a 171 | special exception, the source code distributed need not include 172 | anything that is normally distributed (in either source or binary 173 | form) with the major components (compiler, kernel, and so on) of the 174 | operating system on which the executable runs, unless that component 175 | itself accompanies the executable. 176 | 177 | If distribution of executable or object code is made by offering 178 | access to copy from a designated place, then offering equivalent 179 | access to copy the source code from the same place counts as 180 | distribution of the source code, even though third parties are not 181 | compelled to copy the source along with the object code. 182 | 183 | **4.** You may not copy, modify, sublicense, or distribute the Program 184 | except as expressly provided under this License. Any attempt otherwise 185 | to copy, modify, sublicense or distribute the Program is void, and 186 | will automatically terminate your rights under this License. However, 187 | parties who have received copies, or rights, from you under this 188 | License will not have their licenses terminated so long as such 189 | parties remain in full compliance. 190 | 191 | **5.** You are not required to accept this License, since you have not 192 | signed it. However, nothing else grants you permission to modify or 193 | distribute the Program or its derivative works. These actions are 194 | prohibited by law if you do not accept this License. Therefore, by 195 | modifying or distributing the Program (or any work based on the 196 | Program), you indicate your acceptance of this License to do so, and 197 | all its terms and conditions for copying, distributing or modifying 198 | the Program or works based on it. 199 | 200 | **6.** Each time you redistribute the Program (or any work based on 201 | the Program), the recipient automatically receives a license from the 202 | original licensor to copy, distribute or modify the Program subject to 203 | these terms and conditions. You may not impose any further 204 | restrictions on the recipients' exercise of the rights granted herein. 205 | You are not responsible for enforcing compliance by third parties to 206 | this License. 207 | 208 | **7.** If, as a consequence of a court judgment or allegation of 209 | patent infringement or for any other reason (not limited to patent 210 | issues), conditions are imposed on you (whether by court order, 211 | agreement or otherwise) that contradict the conditions of this 212 | License, they do not excuse you from the conditions of this License. 213 | If you cannot distribute so as to satisfy simultaneously your 214 | obligations under this License and any other pertinent obligations, 215 | then as a consequence you may not distribute the Program at all. For 216 | example, if a patent license would not permit royalty-free 217 | redistribution of the Program by all those who receive copies directly 218 | or indirectly through you, then the only way you could satisfy both it 219 | and this License would be to refrain entirely from distribution of the 220 | Program. 221 | 222 | If any portion of this section is held invalid or unenforceable under 223 | any particular circumstance, the balance of the section is intended to 224 | apply and the section as a whole is intended to apply in other 225 | circumstances. 226 | 227 | It is not the purpose of this section to induce you to infringe any 228 | patents or other property right claims or to contest validity of any 229 | such claims; this section has the sole purpose of protecting the 230 | integrity of the free software distribution system, which is 231 | implemented by public license practices. Many people have made 232 | generous contributions to the wide range of software distributed 233 | through that system in reliance on consistent application of that 234 | system; it is up to the author/donor to decide if he or she is willing 235 | to distribute software through any other system and a licensee cannot 236 | impose that choice. 237 | 238 | This section is intended to make thoroughly clear what is believed to 239 | be a consequence of the rest of this License. 240 | 241 | **8.** If the distribution and/or use of the Program is restricted in 242 | certain countries either by patents or by copyrighted interfaces, the 243 | original copyright holder who places the Program under this License 244 | may add an explicit geographical distribution limitation excluding 245 | those countries, so that distribution is permitted only in or among 246 | countries not thus excluded. In such case, this License incorporates 247 | the limitation as if written in the body of this License. 248 | 249 | **9.** The Free Software Foundation may publish revised and/or new 250 | versions of the General Public License from time to time. Such new 251 | versions will be similar in spirit to the present version, but may 252 | differ in detail to address new problems or concerns. 253 | 254 | Each version is given a distinguishing version number. If the Program 255 | specifies a version number of this License which applies to it and 256 | "any later version", you have the option of following the terms and 257 | conditions either of that version or of any later version published by 258 | the Free Software Foundation. If the Program does not specify a 259 | version number of this License, you may choose any version ever 260 | published by the Free Software Foundation. 261 | 262 | **10.** If you wish to incorporate parts of the Program into other 263 | free programs whose distribution conditions are different, write to 264 | the author to ask for permission. For software which is copyrighted by 265 | the Free Software Foundation, write to the Free Software Foundation; 266 | we sometimes make exceptions for this. Our decision will be guided by 267 | the two goals of preserving the free status of all derivatives of our 268 | free software and of promoting the sharing and reuse of software 269 | generally. 270 | 271 | **NO WARRANTY** 272 | 273 | **11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO 274 | WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 275 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 276 | OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY 277 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 278 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 279 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 280 | PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME 281 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 282 | 283 | **12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 284 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 285 | AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU 286 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 287 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 288 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 289 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 290 | FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF 291 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 292 | DAMAGES. 293 | 294 | ### END OF TERMS AND CONDITIONS 295 | 296 | ### How to Apply These Terms to Your New Programs 297 | 298 | If you develop a new program, and you want it to be of the greatest 299 | possible use to the public, the best way to achieve this is to make it 300 | free software which everyone can redistribute and change under these 301 | terms. 302 | 303 | To do so, attach the following notices to the program. It is safest to 304 | attach them to the start of each source file to most effectively 305 | convey the exclusion of warranty; and each file should have at least 306 | the "copyright" line and a pointer to where the full notice is found. 307 | 308 | one line to give the program's name and an idea of what it does. 309 | Copyright (C) yyyy name of author 310 | 311 | This program is free software; you can redistribute it and/or 312 | modify it under the terms of the GNU General Public License 313 | as published by the Free Software Foundation; either version 2 314 | of the License, or (at your option) any later version. 315 | 316 | This program is distributed in the hope that it will be useful, 317 | but WITHOUT ANY WARRANTY; without even the implied warranty of 318 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 319 | GNU General Public License for more details. 320 | 321 | You should have received a copy of the GNU General Public License 322 | along with this program; if not, write to the Free Software 323 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 324 | 325 | Also add information on how to contact you by electronic and paper 326 | mail. 327 | 328 | If the program is interactive, make it output a short notice like this 329 | when it starts in an interactive mode: 330 | 331 | Gnomovision version 69, Copyright (C) year name of author 332 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details 333 | type `show w'. This is free software, and you are welcome 334 | to redistribute it under certain conditions; type `show c' 335 | for details. 336 | 337 | The hypothetical commands \`show w' and \`show c' should show the 338 | appropriate parts of the General Public License. Of course, the 339 | commands you use may be called something other than \`show w' and 340 | \`show c'; they could even be mouse-clicks or menu items--whatever 341 | suits your program. 342 | 343 | You should also get your employer (if you work as a programmer) or 344 | your school, if any, to sign a "copyright disclaimer" for the program, 345 | if necessary. Here is a sample; alter the names: 346 | 347 | Yoyodyne, Inc., hereby disclaims all copyright 348 | interest in the program `Gnomovision' 349 | (which makes passes at compilers) written 350 | by James Hacker. 351 | 352 | signature of Ty Coon, 1 April 1989 353 | Ty Coon, President of Vice 354 | 355 | This General Public License does not permit incorporating your program 356 | into proprietary programs. If your program is a subroutine library, 357 | you may consider it more useful to permit linking proprietary 358 | applications with the library. If this is what you want to do, use the 359 | [GNU Lesser General Public 360 | License](https://www.gnu.org/licenses/lgpl.html) instead of this 361 | License. 362 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # term-keys - lossless keyboard input for Emacs 2 | 3 | This package allows configuring Emacs and a supported terminal emulator to handle keyboard input involving any combination of keys and modifiers. 4 | 5 | ## Table of Contents 6 | 7 | * [Introduction](#introduction) 8 | * [Installation](#installation) 9 | * [Setup](#setup) 10 | * [Configuring Emacs](#configuring-emacs) 11 | * [Configuring `term-keys`](#configuring-term-keys) 12 | * [Terminal Emulators](#terminal-emulators) 13 | * [urxvt (rxvt-unicode)](#urxvt-rxvt-unicode) 14 | * [xterm](#xterm) 15 | * [kitty](#kitty) 16 | * [wezterm](#wezterm) 17 | * [Alacritty](#alacritty) 18 | * [Konsole](#konsole) 19 | * [Yakuake](#yakuake) 20 | * [Linux console](#linux-console) 21 | * [st](#st) 22 | * [macOS Terminal](#macos-terminal) 23 | * [Windows Terminal](#windows-terminal) 24 | * [Unsupported terminals](#unsupported-terminals) 25 | * [Similar projects](#similar-projects) 26 | 27 | ## Introduction 28 | 29 | Generally, terminal emulators and applications running in a terminal cannot reliably transmit and receive certain keystrokes (keys in combination with modifiers). 30 | For some key combinations, there is no consensus on how these events should be encoded on the wire (F-keys and movement keys plus modifiers); 31 | some other key combinations cannot be represented at all (such as Ctrl1 or CtrlShiftA). 32 | This can be an impediment for Emacs users, especially when you've already configured your Emacs in an environment unrestricted by these limitations (X11) and now wish to use it in the terminal as well. 33 | 34 | The `term-keys` package allows solving this problem by giving these key combinations a custom, unique encoding, overcoming the limitations of the protocol implemented by the terminal emulators. 35 | 36 | ## Installation 37 | 38 | To install `term-keys`, first add my ELPA package archive. Add this to your `init.el` and evaluate it: 39 | 40 | ```elisp 41 | (require 'package) ; you may already have this line 42 | (add-to-list 'package-archives 43 | '("cselpa" . "https://elpa.thecybershadow.net/packages/")) 44 | ``` 45 | 46 | Then, install it like any ELPA package (M-x`package-install`RET`term-keys`). 47 | 48 | ## Setup 49 | 50 | Setting up `term-keys` is a three-part process: 51 | 52 | 1. Configure Emacs; 53 | 2. Configure `term-keys` (optional); 54 | 3. Configure your terminal emulator. 55 | 56 | See the sections below for more information. 57 | 58 | ### Configuring Emacs 59 | 60 | Setting up `term-keys` is as easy as: 61 | 62 | ```elisp 63 | (require 'term-keys) 64 | (term-keys-mode t) 65 | ``` 66 | 67 | This will automatically set up current and new TTY frames to decode `term-keys` key sequences. 68 | If you prefer to enable it for each frame manually, you can do so by invoking `(term-keys/init)`. 69 | 70 | ### Configuring `term-keys` 71 | 72 | `term-keys` is very configurable. Most things can be changed via Emacs' `customize` interface - use M-x`customize-group`RET`term-keys` to access it. 73 | 74 | Some of the supplementary code for terminal emulator configuration can be configured as well. 75 | Because it's not loaded by default (as it's only necessary for initial configuration), you need to load it explicitly before configuring it, e.g. using M-:`(require 'term-keys-konsole)`, and only then invoking Emacs' `customize` interface. 76 | See the terminal's section in this file for more information. 77 | 78 | The only part of `term-keys` which cannot be configured via the `customize` interface is the set of key combinations to support, as (counting all possible keys plus combinations of modifier keys) their total number is very large. 79 | For this purpose, `term-keys` allows specifying the name of a function to invoke, which shall implement this logic. 80 | See the documentation of `term-keys/want-key-p-func` and `term-keys/want-key-p-def` (as well as the definition of the latter) for more information. 81 | 82 | ### Terminal Emulators 83 | 84 | Each terminal emulator has its own method of configuration. Consult the section corresponding to your terminal emulator of choice below. 85 | 86 | Note that you will need to update the terminal emulator configuration every time you change the `term-keys` configuration. 87 | 88 | #### urxvt (rxvt-unicode) 89 | 90 | There's three ways to configure `urxvt` with `term-keys`: via command-line parameters, via X resources, or by invoking a `term-keys` function from Emacs. 91 | 92 | ##### Command-line parameters 93 | 94 | Command-line configuration consists in adding the key bindings to the `urxvt` invocation directly. 95 | You can use `term-keys/urxvt-script` to create a shell script in this manner: 96 | 97 | ```elisp 98 | (require 'term-keys-urxvt) 99 | (with-temp-buffer 100 | (insert (term-keys/urxvt-script)) 101 | (write-region (point-min) (point-max) "~/launch-urxvt-with-term-keys.sh")) 102 | ``` 103 | 104 | Afterwards, you can run e.g.: 105 | 106 | ```bash 107 | $ sh ~/launch-urxvt-with-term-keys.sh -e emacs -nw 108 | ``` 109 | 110 | This will launch Emacs under an `urxvt` instance configured for `term-keys`. 111 | 112 | ##### X resources 113 | 114 | X resource configuration consists in adding the `term-keys` configuration to the X resources. 115 | The X resources are global (per X session), and will apply to all newly-started `urxvt` instances. 116 | You can use `term-keys/urxvt-xresources` to create the necessary configuration in this manner: 117 | 118 | ```elisp 119 | (require 'term-keys-urxvt) 120 | (with-temp-buffer 121 | (insert (term-keys/urxvt-xresources)) 122 | (append-to-file (point-min) (point-max) "~/.Xresources")) 123 | ``` 124 | 125 | Then use `xrdb` to load the file into memory: 126 | 127 | ```bash 128 | $ xrdb -merge ~/.Xresources 129 | ``` 130 | 131 | ##### Direct invocation 132 | 133 | In addition to generating a static configuration as a shell script or X resources, you can ask `term-keys` to invoke `urxvt` directly. 134 | This has the benefit that it will always use the up-to-date `term-keys` configuration, but the downside that it must be done by invoking `emacs` or `emacsclient`. 135 | For example: 136 | 137 | ```bash 138 | $ emacsclient --eval '(term-keys/urxvt-run-emacs)' 139 | ``` 140 | 141 | See the `term-keys/urxvt-*` definitions for more urxvt-specific help code. 142 | 143 | You may also want to disable some default `urxvt` shortcuts which may interfere with using Emacs. 144 | Consider adding something like this to your `~/.Xresources`: 145 | 146 | ``` 147 | URxvt*iso14755: 0 148 | URxvt.keysym.Shift-Insert: builtin-string: 149 | URxvt.keysym.M-S: builtin-string: 150 | ``` 151 | 152 | #### xterm 153 | 154 | `xterm` is configured nearly identically as `urxvt`; 155 | thus, this section will be very similar to the `urxvt` section above. 156 | 157 | Note: `xterm` supports an extended input mode; see `modifyOtherKeys` et al in the `xterm(1)` man page. 158 | You may find it sufficient for your use case even without `term-keys`. 159 | 160 | As with `urxvt`, there's two ways to configure `xterm`: via command-line parameters or X resources. 161 | Command-line configuration consists in adding the key bindings to the `xterm` invocation directly. 162 | You can use `term-keys/xterm-script` to create a shell script in this manner: 163 | 164 | ```elisp 165 | (require 'term-keys-xterm) 166 | (with-temp-buffer 167 | (insert (term-keys/xterm-script)) 168 | (write-region (point-min) (point-max) "~/launch-xterm-with-term-keys.sh")) 169 | ``` 170 | 171 | Afterwards, you can run e.g.: 172 | 173 | ```bash 174 | $ sh ~/launch-xterm-with-term-keys.sh -e emacs -nw 175 | ``` 176 | 177 | This will launch Emacs under an `xterm` instance configured for `term-keys`. 178 | 179 | X resource configuration consists in adding the `term-keys` configuration to the X resources. 180 | The X resources are global (per X session), and will apply to all newly-started `xterm` instances. 181 | You can use `term-keys/xterm-xresources` to create the necessary configuration in this manner: 182 | 183 | ```elisp 184 | (require 'term-keys-xterm) 185 | (with-temp-buffer 186 | (insert (term-keys/xterm-xresources)) 187 | (append-to-file (point-min) (point-max) "~/.Xresources")) 188 | ``` 189 | 190 | Then use `xrdb` to load the file into memory: 191 | 192 | ```bash 193 | $ xrdb -merge ~/.Xresources 194 | ``` 195 | 196 | In addition to generating a static configuration as a shell script or X resources, you can ask `term-keys` to invoke `xterm` directly. 197 | This has the benefit that it will always use the up-to-date `term-keys` configuration, but the downside that it must be done by invoking `emacs` or `emacsclient`. 198 | For example: 199 | 200 | ```bash 201 | $ emacsclient --eval '(term-keys/xterm-run-emacs)' 202 | ``` 203 | 204 | See the `term-keys/xterm-*` definitions for more xterm-specific help code. 205 | 206 | You may also want to disable the `eightBitInput` `xterm` option, e.g. with `-xrm 'XTerm*eightBitInput: false'`. 207 | 208 | #### kitty 209 | 210 | [kitty](https://sw.kovidgoyal.net/kitty/) is configured via its `kitty.conf` configuration file. 211 | 212 | To configure kitty for `term-keys`, use `term-keys/kitty-conf` to generate a `kitty.conf` fragment: 213 | 214 | ```elisp 215 | (require 'term-keys-kitty) 216 | (with-temp-buffer 217 | (insert (term-keys/kitty-conf)) 218 | (write-region (point-min) (point-max) "~/kitty-for-term-keys.conf")) 219 | ``` 220 | 221 | Then, add the output to your main `kitty.conf` file. 222 | 223 | You can customize kitty's mapping of GLFW modifiers to Emacs modifiers in the generated configuration using the respective `customize` group, i.e.: M-:`(progn (require 'term-keys-kitty) (customize-group 'term-keys/glfw))` 224 | 225 | #### wezterm 226 | 227 | [wezterm](https://wezfurlong.org/wezterm/index.html) is configured via its `wezterm.lua` configuration file. 228 | 229 | To configure wezterm for `term-keys`, use `term-keys/wezterm-conf` to generate a `wezterm.lua` fragment: 230 | 231 | ```elisp 232 | (require 'term-keys-wezterm) 233 | (with-temp-buffer 234 | (insert (term-keys/wezterm-conf)) 235 | (write-region (point-min) (point-max) "~/wezterm-for-term-keys.lua")) 236 | ``` 237 | 238 | Then, add the output to your main `wezterm.lua` file. 239 | 240 | You can customize wezterm's mapping of GLFW modifiers to Emacs modifiers in the generated configuration using the respective `customize` group, i.e.: M-:`(progn (require 'term-keys-wezterm) (customize-group 'term-keys/glfw))` 241 | 242 | #### Alacritty 243 | 244 | [Alacritty](https://github.com/alacritty/alacritty) is configured via its `alacritty.yml` configuration file. 245 | 246 | To configure alacritty for `term-keys`, use `term-keys/alacritty-config` to generate a `alacritty.yml` fragment: 247 | 248 | ```elisp 249 | (require 'term-keys-alacritty) 250 | (with-temp-buffer 251 | (insert (term-keys/alacritty-config)) 252 | (write-region (point-min) (point-max) "~/alacritty-for-term-keys.yml")) 253 | ``` 254 | 255 | Then, add the output to your main `alacritty.yml` file. 256 | 257 | You can customize Alacritty's mapping of its supported modifiers to Emacs modifiers in the generated configuration using the respective `customize` group, i.e.: M-:`(progn (require 'term-keys-alacritty) (customize-group 'term-keys/alacritty))` 258 | 259 | #### Konsole 260 | 261 | Konsole provides an interface for adding new and editing existing escape sequences for key combinations 262 | (Settings → Edit current profile... → Keyboard → Edit). 263 | `term-keys` can generate a Konsole keyboard profile according to its settings. 264 | 265 | To do so: 266 | 267 | 1. Create a new keyboard profile, based on the default one. 268 | (Select "Default (XFree 4)", and click "New...".) 269 | Name it e.g. `Emacs`. 270 | 2. Append the output of `term-keys/konsole-keytab` to the newly created `.keytab` file, e.g.: 271 | 272 | ```elisp 273 | (require 'term-keys-konsole) 274 | (with-temp-buffer 275 | (insert (term-keys/konsole-keytab)) 276 | (append-to-file (point-min) (point-max) "~/.local/share/konsole/Emacs.keytab")) 277 | ``` 278 | 279 | 3. Assign the keyboard profile to a new or existing Konsole profile. 280 | 281 | You can customize the mapping of Konsole (Qt) modifiers to Emacs modifiers using the respective `customize` group, i.e.: M-:`(progn (require 'term-keys-konsole) (customize-group 'term-keys/konsole))` 282 | 283 | You may also want to disable some default Konsole shortcuts (Settings → Configure Shortcuts...), 284 | as they may interfere with standard Emacs commands. 285 | 286 | #### Yakuake 287 | 288 | Yakuake seems to share much with Konsole, and can be configured in the same way. 289 | See the section above for details. 290 | 291 | #### Linux console 292 | 293 | The Linux console can be customized using `.keymap` files and the `loadkeys` program. 294 | You can configure it for `term-keys` as follows: 295 | 296 | 1. Use `term-keys/linux-keymap` to create a `.keymap` file: 297 | 298 | ```elisp 299 | (require 'term-keys-linux) 300 | (with-temp-buffer 301 | (insert (term-keys/linux-keymap)) 302 | (write-region (point-min) (point-max) "~/term-keys.keymap")) 303 | ``` 304 | 305 | 2. Load the created `.keymap` file: 306 | 307 | ```bash 308 | $ sudo loadkeys ~/term-keys.keymap 309 | ``` 310 | 311 | To reset the layout to the default one, run `sudo loadkeys -d`. 312 | 313 | You will need to invoke `loadkeys` after every boot; alternatively, on 314 | systemd distributions, you can add a `KEYMAP=` line to 315 | `/etc/vconsole.conf`. 316 | 317 | You can customize some settings affecting the generated `.keymap` files using the respective `customize` group, i.e.: M-:`(progn (require 'term-keys-linux) (customize-group 'term-keys/linux))` 318 | 319 | Note that the `.keymap` files generated by `term-keys/linux-keymap` assume a QWERTY keyboard layout. 320 | If you use another layout (AZERTY, Dvorak, Colemak...), you will need to customize `term-keys/mapping` and set the alphanumeric keynumbers accordingly. 321 | 322 | Note also that Linux has a limitation on the number of customized keys. Custom key strings need to be assigned to "function keys", for which there are 256 slots by default (which includes the default strings for the F-keys and some other keys like Insert/Delete). This leaves about 234 slots for `term-keys`, which is sufficient for the default configuration, but may not be sufficient for a custom one, especially if you enable support for additional modifiers. 323 | 324 | #### st 325 | 326 | [st](https://st.suckless.org/) is configured by editing its `config.h` and recompiling. The key sequences can be configured in this way as well. 327 | 328 | You can configure st for `term-keys` as follows: 329 | 330 | 1. Generate the initial `config.h`, e.g. by building `st` once. 331 | 2. Use the `term-keys/st-config-*` functions to create header files: 332 | 333 | ```elisp 334 | (require 'term-keys-st) 335 | ;; Assuming st is checked out in ~/st 336 | (with-temp-buffer 337 | (insert (term-keys/st-config-key)) 338 | (write-region (point-min) (point-max) "~/st/config-term-keys-key.h")) 339 | (with-temp-buffer 340 | (insert (term-keys/st-config-mappedkeys)) 341 | (write-region (point-min) (point-max) "~/st/config-term-keys-mappedkeys.h")) 342 | ``` 343 | 344 | 3. Update the definition of `mappedkeys` in `config.h` as follows: 345 | 346 | ```c 347 | static KeySym mappedkeys[] = { 348 | #include "config-term-keys-mappedkeys.h" 349 | -1 350 | }; 351 | ``` 352 | 353 | 4. Update the definition of `key` in `config.h` as follows: 354 | 355 | ```c 356 | static Key key[] = { 357 | #include "config-term-keys-key.h" 358 | /* keysym mask string appkey appcursor crlf */ 359 | /* ( ... original definitions follow ... ) */ 360 | ``` 361 | 362 | 5. Rebuild st. 363 | 364 | You can customize st's mapping of X11 modifiers to Emacs modifiers in the generated configuration using the respective `customize` group, i.e.: M-:`(progn (require 'term-keys-st) (customize-group 'term-keys/x11))` 365 | 366 | #### macOS Terminal 367 | 368 | The standard macOS Terminal.app allows, to a certain extent, customizing escape sequences sent by key combinations 369 | (Terminal → Preferences... → Profiles → (select a profile) → Keyboard). 370 | `term-keys` can generate a configuration XML file, which can be injected into Terminal.app's preferences plist file. 371 | 372 | To do so: 373 | 374 | 1. Create a new profile. Name it e.g. `Emacs`. 375 | 2. Enable the "Use Option as Meta key" option on the Keyboard tab. 376 | 3. Export the `term-keys` keymap XML file: 377 | 378 | ```elisp 379 | (require 'term-keys-terminal-app) 380 | (with-temp-buffer 381 | (insert (term-keys/terminal-app-keymap-xml)) 382 | (append-to-file (point-min) (point-max) "~/term-keys.xml")) 383 | ``` 384 | 385 | 4. Import the keymap into Terminal.app's preferences file: 386 | 387 | ```bash 388 | $ plutil -replace 'Window Settings.Emacs.keyMapBoundKeys' \ 389 | -xml "$(cat ~/term-keys.xml)" \ 390 | ~/Library/Preferences/com.apple.Terminal.plist 391 | ``` 392 | 393 | (If you named your profile something other than `Emacs`, substitute its name in the command above.) 394 | 395 | 5. Restart Terminal.app. 396 | 397 | Note that the application's settings UI only allows configuring a small set of keys. 398 | This limitation does not carry over to the underlying configuration file format, and thus does not apply to `term-keys` - 399 | the generated keymap file will contain definitions for all keys that generate a Unicode key code on macOS. 400 | These entries will appear (displayed with the key's hex code instead of the key name) in the terminal emulator's configuration, but cannot be edited there. 401 | 402 | You can customize the mapping of Terminal.app modifiers to Emacs modifiers using the respective `customize` group, i.e.: M-:`(progn (require 'term-keys-terminal-app) (customize-group 'term-keys/terminal-app))` 403 | 404 | #### Windows Terminal 405 | 406 | To configure Windows Terminal for `term-keys`, use `term-keys/windows-terminal-json` to generate a json file. 407 | 408 | ```elisp 409 | (require 'term-keys-windows-terminal) 410 | (with-temp-file "~/windows-terminal.json" 411 | (insert (term-keys/windows-terminal-json))) 412 | ``` 413 | 414 | Then, add the contents to Windows Terminal settings. 415 | 416 | #### Unsupported terminals 417 | 418 | These terminals don't (directly) support customizing key bindings, and thus cannot be used with `term-keys`: 419 | 420 | - **PuTTY** - Custom key mappings are [a known frequently-requested feature](https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-mapping.html). 421 | - **GNOME Terminal** - Uses the [Gnome VTE widget](https://github.com/GNOME/vte), which doesn't seem to support key binding customization. 422 | - **tilix**, **Guake**, **tilda** - Use the same widget as GNOME Terminal. 423 | - **GNOME Terminator** - Uses the same widget as GNOME Terminal, however has a plugin system. Perhaps writing a plugin is possible? 424 | - **termite** - Uses the same widget as GNOME Terminal, however, it has a `modify_other_keys` option, similar to xterm's `modifyOtherKeys`. 425 | - **mintty** - No support for customizing key bindings, however, it already [has some support](https://github.com/mintty/mintty/wiki/CtrlSeqs) for xterm's `modifyOtherKeys` protocol extensions. 426 | - **Bitvise SSH Client** - No support for customizing key bindings. Supports a custom extended protocol (bvterm), which seems to allow lossless keyboard input (including key-up events), however it is full of Windows-isms (much of the protocol uses the same data types as used by the Windows API), and getting Emacs to speak it would be a non-trivial task that's not likely to be achievable using just Emacs Lisp code. 427 | - **Terminology** - No support for customizing key bindings at runtime (via a configuration file), however, this terminal generates its key/string translation tables using another terminal emulator (i.e. by sending keyboard events with `xdotool` to another terminal emulator and recording the resulting strings). Therefore, it may be possible to configure Terminology with `term-keys` by running its configuration script through another terminal pre-configured with `term-keys` (e.g. `xterm`), then rebuilding Terminology using the resulting configuration. 428 | 429 | ## Similar projects 430 | 431 | * [xterm-keybinder](https://github.com/yuutayamada/xterm-keybinder-el) is an Emacs package similar to this one. `term-keys` improves upon xterm-keybinder by supporting more terminals, better documentation, customizability, and extensibility, and improved wire efficiency. 432 | 433 | * [notty](https://github.com/withoutboats/notty) is an experimental terminal emulator which also aims at achieving lossless keyboard input by extending the ANSI protocol. `term-keys` does not use notty's protocol because its escape sequence prefix (`^[{`) conflicts with a default Emacs command binding (`backward-paragraph`). 434 | 435 | * [Fix Keyboard Input on Terminals](http://www.leonerd.org.uk/hacks/fixterms/) is a proposal to improve input in terminals, which is to some extent implemented in `xterm` and Emacs. Unfortunately, the proposed protocol is vague and incomplete, as it does not cover modifier keys and many PC keyboard keys. 436 | 437 | * The [kitty terminal emulator](https://github.com/kovidgoyal/kitty) (the one written in Python, not [the PuTTY fork](http://www.9bis.net/kitty/)) implements [its own protocol extensions for keyboard handling](https://github.com/kovidgoyal/kitty/blob/master/protocol-extensions.asciidoc#keyboard-handling) (though it can also be simply configured with term-keys as [described above](#kitty)). 438 | -------------------------------------------------------------------------------- /term-keys-alacritty.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-alacritty.el --- term-keys support for Alacritty 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the Alacritty terminal emulator to interoperate with 24 | ;; the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | 33 | 34 | (defgroup term-keys/alacritty nil 35 | "`term-keys' options for ALACRITTY-based terminal emulators." 36 | :group 'term-keys) 37 | 38 | (define-widget 'term-keys/alacritty-modifier 'lazy 39 | "Choice for Alacritty key modifier state flags." 40 | :type '(choice (const "Command") 41 | (const "Control") 42 | (const "Option") 43 | (const "Super") 44 | (const "Shift") 45 | (const "Alt") 46 | (const :tag "(none)" nil))) 47 | 48 | 49 | (defcustom term-keys/alacritty-modifier-map ["Shift" "Control" "Alt" "Super" "Command" "Option"] 50 | "Map of Alacritty modifiers to Emacs modifiers. 51 | 52 | This should be a vector of 6 elements, with each element being a 53 | string indicating the name of the Alacritty modifier name 54 | corresponding to the Emacs modifiers Shift, Control, Meta, Super, 55 | Hyper and Alt respectively. nil indicates that there is no 56 | mapping for this modifier." 57 | :type '(vector 58 | (term-keys/alacritty-modifier :tag "Shift") 59 | (term-keys/alacritty-modifier :tag "Control") 60 | (term-keys/alacritty-modifier :tag "Meta") 61 | (term-keys/alacritty-modifier :tag "Super") 62 | (term-keys/alacritty-modifier :tag "Hyper") 63 | (term-keys/alacritty-modifier :tag "Alt")) 64 | :group 'term-keys/alacritty) 65 | 66 | 67 | (defun term-keys/alacritty-mods-representable (mods) 68 | "Return non-nil if the given MODS vector is representable in ALACRITTY." 69 | (cl-reduce (lambda (x y) (and x y)) ; all 70 | (mapcar (lambda (n) 71 | (or (not (elt mods n)) ; inactive modifier 72 | (elt term-keys/alacritty-modifier-map n))) ; mapped 73 | (number-sequence 0 (1- (length mods)))))) ; 0..5 74 | 75 | 76 | (defun term-keys/alacritty-format-mods (mods) 77 | "Format MODS in Alacritty syntax." 78 | (if (cl-reduce (lambda (x y) (or x y)) mods) 79 | (concat 80 | ", mods: " 81 | (mapconcat 82 | (lambda (n) 83 | (elt term-keys/alacritty-modifier-map n)) 84 | (cl-remove-if-not (lambda (n) (elt mods n)) 85 | (number-sequence 0 (1- (length mods)))) 86 | "|")) 87 | "")) 88 | 89 | 90 | (defun term-keys/alacritty-config () 91 | "Construct Alacritty configuration (alacritty.yml fragment). 92 | 93 | This function returns, as a string, an alacritty.yml fragment 94 | necessary to configure Alacritty to encode term-keys key 95 | sequences, according to the term-keys configuration." 96 | (apply #'concat 97 | "key_bindings:\n" 98 | (term-keys/iterate-keys 99 | (lambda (index keymap mods) 100 | (format "- { key: %s%s, chars: \"%s\" }\n" 101 | (elt keymap 8) 102 | (term-keys/alacritty-format-mods mods) 103 | (mapconcat 104 | (lambda (c) (format "\\x%02x" c)) 105 | (append 106 | term-keys/prefix 107 | (term-keys/encode-key index mods) 108 | term-keys/suffix 109 | nil) 110 | "")))))) 111 | 112 | 113 | (provide 'term-keys-alacritty) 114 | ;;; term-keys-alacritty.el ends here 115 | -------------------------------------------------------------------------------- /term-keys-glfw-mods.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-glfw-mods.el --- term-keys support for terminals with glfw mods 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of terminal emulators to interoperate with 24 | ;; the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | 33 | 34 | (defgroup term-keys/glfw nil 35 | "`term-keys' options for GLFW-based terminal emulators." 36 | :group 'term-keys) 37 | 38 | (define-widget 'term-keys/glfw-modifier 'lazy 39 | "Choice for GLFW key modifier state flags." 40 | :type '(choice (const "SHIFT") 41 | (const "CONTROL") 42 | (const "ALT") 43 | (const "SUPER") 44 | (const "CAPS_LOCK") 45 | (const "NUM_LOCK") 46 | (const :tag "(none)" nil))) 47 | 48 | 49 | (defcustom term-keys/glfw-modifier-map ["SHIFT" "CTRL" "ALT" "SUPER" nil nil] 50 | "Map of GLFW modifier state flags to Emacs modifiers. 51 | 52 | This should be a vector of 6 elements, with each element being a 53 | string indicating the name of the GLFW modifier name (sans the 54 | \"GLFW_MOD_\" prefix) corresponding to the Emacs modifiers Shift, 55 | Control, Meta, Super, Hyper and Alt respectively. nil indicates 56 | that there is no mapping for this modifier. 57 | 58 | https://www.glfw.org/docs/latest/group__mods.html" 59 | :type '(vector 60 | (term-keys/glfw-modifier :tag "Shift") 61 | (term-keys/glfw-modifier :tag "Control") 62 | (term-keys/glfw-modifier :tag "Meta") 63 | (term-keys/glfw-modifier :tag "Super") 64 | (term-keys/glfw-modifier :tag "Hyper") 65 | (term-keys/glfw-modifier :tag "Alt")) 66 | :group 'term-keys/glfw) 67 | 68 | 69 | (defun term-keys/glfw-mods-representable (mods) 70 | "Return non-nil if the given MODS vector is representable in GLFW." 71 | (cl-reduce (lambda (x y) (and x y)) ; all 72 | (mapcar (lambda (n) 73 | (or (not (elt mods n)) ; inactive modifier 74 | (elt term-keys/glfw-modifier-map n))) ; mapped 75 | (number-sequence 0 (1- (length mods)))))) ; 0..5 76 | 77 | 78 | (provide 'term-keys-glfw-mods) 79 | ;;; term-keys-glfw-mods.el ends here 80 | -------------------------------------------------------------------------------- /term-keys-kitty.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-kitty.el --- term-keys support for kitty 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the kitty terminal emulator to interoperate with 24 | ;; the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | (require 'term-keys-glfw-mods) 33 | 34 | 35 | (defun term-keys/kitty-format-key (keymap mods) 36 | "Format key and modifiers in kitty syntax. 37 | 38 | Returns the kitty key combination string corresponding to the 39 | KEYMAP and modifier state MODS." 40 | (concat 41 | (cl-loop for modflag across mods 42 | for index from 0 43 | if modflag 44 | concat 45 | (concat 46 | (elt term-keys/glfw-modifier-map index) 47 | "+")) 48 | (elt keymap 7))) 49 | 50 | 51 | (defun term-keys/kitty-conf () 52 | "Construct kitty configuration (kitty.conf fragment). 53 | 54 | This function returns, as a string, the kitty.conf map lines 55 | necessary to configure kitty to encode term-keys key sequences, 56 | according to the term-keys configuration." 57 | (apply #'concat 58 | (term-keys/iterate-keys 59 | (lambda (index keymap mods) 60 | (format "map %-55s send_text all %s\n" 61 | (term-keys/kitty-format-key keymap mods) 62 | (mapconcat 63 | (lambda (c) (format "\\x%02x" c)) 64 | (append 65 | term-keys/prefix 66 | (term-keys/encode-key index mods) 67 | term-keys/suffix 68 | nil) 69 | "")))))) 70 | 71 | 72 | (provide 'term-keys-kitty) 73 | ;;; term-keys-kitty.el ends here 74 | -------------------------------------------------------------------------------- /term-keys-konsole.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-konsole.el --- term-keys support for Konsole 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the Konsole terminal emulator to interoperate with 24 | ;; the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | 33 | 34 | (defgroup term-keys/konsole nil 35 | "`term-keys' options for the Konsole terminal emulator." 36 | :group 'term-keys) 37 | 38 | 39 | (define-widget 'term-keys/konsole-modifier 'lazy 40 | "Choice for Konsole key binding modifiers and state flags." 41 | :type '(choice (const "Shift") 42 | (const "Ctrl") 43 | (const "Alt") 44 | (const "Meta") 45 | (const "KeyPad") 46 | (const "AppScreen") 47 | (const "AppCursorKeys") 48 | (const "NewLine") 49 | (const "Ansi") 50 | (const "AnyModifier") 51 | (const "AppKeypad") 52 | (const :tag "(none)" nil))) 53 | 54 | 55 | (defcustom term-keys/konsole-modifier-map ["Shift" "Ctrl" "Alt" "Meta" nil nil] 56 | "Modifier keys for Konsole key bindings. 57 | 58 | This should be a vector of 6 elements, with each element being a 59 | string indicating the name of the Konsole modifier or state flag 60 | corresponding to the Emacs modifiers Shift, Control, Meta, Super, 61 | Hyper and Alt respectively, as they should appear in generated 62 | Konsole .keytab files. nil indicates that there is no mapping 63 | for this modifier." 64 | :type '(vector 65 | (term-keys/konsole-modifier :tag "Shift") 66 | (term-keys/konsole-modifier :tag "Control") 67 | (term-keys/konsole-modifier :tag "Meta") 68 | (term-keys/konsole-modifier :tag "Super") 69 | (term-keys/konsole-modifier :tag "Hyper") 70 | (term-keys/konsole-modifier :tag "Alt")) 71 | :group 'term-keys/konsole) 72 | 73 | 74 | (defun term-keys/konsole-keytab () 75 | "Construct Konsole key binding configuration as .keytab file syntax. 76 | 77 | This function returns, as a string, a Konsole keytab which can be 78 | used to configure Konsole to encode term-keys key sequences, 79 | according to the term-keys configuration. 80 | 81 | The returned string is suitable to be pasted as-is to the end of 82 | an existing Konsole .keytab file." 83 | (apply #'concat 84 | (term-keys/iterate-keys 85 | (lambda (index keymap mods) 86 | 87 | ;; Skip key combinations with unrepresentable modifiers 88 | (unless (cl-reduce (lambda (x y) (or x y)) ; any 89 | (mapcar (lambda (n) ; active modifier mapped to nil 90 | (and (elt mods n) 91 | (not (elt term-keys/konsole-modifier-map n)))) 92 | (number-sequence 0 (1- (length mods))))) ; 0..5 93 | (format "key %s%s : \"%s\"\n" 94 | (or ; Apply shift 95 | (and (elt mods 0) ; With Shift? 96 | (elt keymap 9)) ; Use shifted column 97 | (elt keymap 3)) ; Use non-shifted column 98 | (mapconcat 99 | (lambda (n) 100 | (if (elt term-keys/konsole-modifier-map n) 101 | (concat 102 | (if (elt mods n) "+" "-") 103 | (elt term-keys/konsole-modifier-map n)) 104 | "")) 105 | (number-sequence 0 (1- (length mods))) 106 | "") 107 | (mapconcat ; hex-escaped sequence 108 | (lambda (x) (format "\\x%02X" x)) 109 | (append 110 | term-keys/prefix 111 | (term-keys/encode-key index mods) 112 | term-keys/suffix 113 | nil) 114 | ""))))))) 115 | 116 | 117 | (provide 'term-keys-konsole) 118 | ;;; term-keys-konsole.el ends here 119 | -------------------------------------------------------------------------------- /term-keys-linux.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-linux.el --- term-keys support for the Linux console 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the Linux console to interoperate with the 24 | ;; term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | 33 | 34 | (defgroup term-keys/linux nil 35 | "`term-keys' options for the Linux console." 36 | :group 'term-keys) 37 | 38 | 39 | (define-widget 'term-keys/linux-modifier 'lazy 40 | "Choice for Linux modifiers for keymap files." 41 | :type '(choice (const "Shift") 42 | (const "AltGr") 43 | (const "Control") 44 | (const "Alt") 45 | (const "ShiftL") 46 | (const "ShiftR") 47 | (const "CtrlL") 48 | (const "CtrlR") 49 | (const "CapsShift") 50 | (const :tag "(none)" nil))) 51 | 52 | 53 | (defcustom term-keys/linux-modifier-map ["Shift" "Control" "Alt" nil nil "AltGr"] 54 | "Modifier keys for Linux console keymaps. 55 | 56 | This should be a vector of 6 elements, with each element being a 57 | string indicating the name of the modifier key corresponding to 58 | the Emacs modifiers Shift, Control, Meta, Super, Hyper and Alt 59 | respectively, as they should appear in generated .keymap files. 60 | nil indicates that there is no mapping for this modifier." 61 | :type '(vector 62 | (term-keys/linux-modifier :tag "Shift") 63 | (term-keys/linux-modifier :tag "Control") 64 | (term-keys/linux-modifier :tag "Meta") 65 | (term-keys/linux-modifier :tag "Super") 66 | (term-keys/linux-modifier :tag "Hyper") 67 | (term-keys/linux-modifier :tag "Alt")) 68 | :group 'term-keys/linux) 69 | 70 | 71 | (defcustom term-keys/linux-first-function-key 13 72 | "First Linux console keymap function key to use for term-keys bindings. 73 | 74 | The Linux console allows binding custom character sequences to 75 | keys only by assigning them to a \"function key\" (named thus 76 | after the usual F1, F2 etc. function keys found on a computer 77 | keyboard). Although most PC keyboards today only have 12 78 | function keys, some keyboards/computers had more, and (also for 79 | the purposes of key binding) the Linux kernel allows registering 80 | character sequences for as many as 246 function keys (see output 81 | for 'dumpkeys -l' for the exact figure on your machine). 82 | Crucially, these virtual keys provide the means to configure 83 | arbitrary character sequences for any key combination, which is 84 | necessary for term-keys to work. 85 | 86 | This variable specifies the first function key entry that's used 87 | by term-keys in the .keymap files it generates (see 88 | `term-keys/linux-keymap'). The default value (13) will make 89 | `term-keys' use F13 and onwards, and is fine for most uses, 90 | unless you happen to use a keyboard with more than 12 F-keys, or 91 | wish to use the F13-F20 keys through the shifted state of the 92 | F1-F8 keys." 93 | :type 'integer 94 | :group 'term-keys) 95 | 96 | 97 | (defun term-keys/linux-keymap () 98 | "Construct Linux console configuration in the form of a keymap. 99 | 100 | This function returns, as a string, a keymap which can be used to 101 | configure the Linux kernel's console to encode term-keys key 102 | sequences, according to the term-keys configuration. 103 | 104 | The returned string is suitable to be saved as-is in a .keymap 105 | file and loaded by the loadkeys program." 106 | (apply #'concat 107 | (let ((fkey term-keys/linux-first-function-key)) 108 | (term-keys/iterate-keys 109 | (lambda (index keymap mods) 110 | 111 | ;; Skip key combinations with unrepresentable modifiers 112 | (unless (cl-reduce (lambda (x y) (or x y)) ; any 113 | (mapcar (lambda (n) ; active modifier mapped to nil 114 | (and (elt mods n) 115 | (not (elt term-keys/linux-modifier-map n)))) 116 | (number-sequence 0 (1- (length mods))))) ; 0..5 117 | (prog1 118 | (format "# %s\n%s\tkeycode %3d = F%d\nstring F%d = \"%s\"\n\n" 119 | ;; Emacs key name for comment 120 | (term-keys/format-key keymap mods) 121 | 122 | (if (cl-reduce (lambda (x y) (or x y)) mods) 123 | ;; tab-separated mod list 124 | (mapconcat 125 | (lambda (n) 126 | (if (elt mods n) (elt term-keys/linux-modifier-map n) "")) 127 | (number-sequence 0 (1- (length mods))) 128 | "\t") 129 | ;; "plain" if no mods 130 | (concat "plain" (make-string (1- (length mods)) ?\t))) 131 | (elt keymap 2) ; keynumber 132 | fkey ; F-key number (use) 133 | fkey ; F-key number (declaration) 134 | (mapconcat ; octal-escaped sequence 135 | (lambda (x) (format "\\%03o" x)) 136 | (append 137 | term-keys/prefix 138 | (term-keys/encode-key index mods) 139 | term-keys/suffix 140 | nil) 141 | "")) 142 | (setq fkey (1+ fkey))))))))) 143 | 144 | 145 | (provide 'term-keys-linux) 146 | ;;; term-keys-linux.el ends here 147 | -------------------------------------------------------------------------------- /term-keys-st.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-st.el --- term-keys support for the st terminal emulator 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the st terminal emulator to interoperate with the 24 | ;; term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | (require 'term-keys-x11) 33 | 34 | 35 | (defun term-keys/st-config-key () 36 | "Construct st key binding configuration (key array entries). 37 | 38 | This function returns, as a string, C code of Key entries of the 39 | config.h 'key' array, which can be used to configure st to encode 40 | term-keys key sequences, according to the term-keys 41 | configuration. 42 | 43 | The returned string is suitable to be pasted as-is into the 'key' 44 | array in the st config.h configuration file; however, this is 45 | just one half of the necessary configuration (see 46 | `term-keys/st-config-mappedkeys' for the other half)." 47 | (apply #'concat 48 | (term-keys/iterate-keys 49 | (lambda (index keymap mods) 50 | 51 | (when (term-keys/x11-key-representable keymap mods) 52 | (format "{ XK_%-16s, %-40s, \"%s\", 0, 0},\n" 53 | (term-keys/x11-apply-mods keymap mods) ; X11 key name 54 | (if (cl-reduce (lambda (x y) (or x y)) mods) 55 | (mapconcat 56 | (lambda (n) 57 | (concat 58 | (elt term-keys/x11-modifier-map n) 59 | "Mask")) 60 | (cl-remove-if-not (lambda (n) (elt mods n)) 61 | (number-sequence 0 (1- (length mods)))) 62 | "|") 63 | "XK_NO_MOD") 64 | (mapconcat ; hex-escaped sequence 65 | (lambda (x) (format "\\x%02X" x)) 66 | (append 67 | term-keys/prefix 68 | (term-keys/encode-key index mods) 69 | term-keys/suffix 70 | nil) 71 | ""))))))) 72 | 73 | 74 | (defun term-keys/st-config-mappedkeys () 75 | "Construct st key binding configuration (mappedkeys array entries). 76 | 77 | This function returns, as a string, C code of KeySym entries of 78 | the config.h 'mappedkeys' array, which can be used to configure 79 | st to encode term-keys key sequences, according to the term-keys 80 | configuration. 81 | 82 | The returned string is suitable to be pasted as-is into the 83 | 'mappedkeys' array in the st config.h configuration file; 84 | however, this is just one half of the necessary 85 | configuration (see `term-keys/st-config-key' for the other 86 | half)." 87 | (apply #'concat 88 | (delete-dups 89 | (term-keys/iterate-keys 90 | (lambda (index keymap mods) 91 | (format "XK_%s,\n" 92 | (term-keys/x11-apply-mods keymap mods))))))) 93 | 94 | 95 | (provide 'term-keys-st) 96 | ;;; term-keys-st.el ends here 97 | -------------------------------------------------------------------------------- /term-keys-terminal-app.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-terminal-app.el --- term-keys support for Terminal.app 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the macOS Terminal.app terminal emulator to 24 | ;; interoperate with the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | (require 'xml) 33 | 34 | 35 | (defgroup term-keys/terminal-app nil 36 | "`term-keys' options for the macOS Terminal.app terminal emulator." 37 | :group 'term-keys) 38 | 39 | 40 | (define-widget 'term-keys/terminal-app-modifier 'lazy 41 | "Choice for Terminal.app key binding modifiers." 42 | :type '(choice 43 | (const :tag "⇧ (Shift)" "$") 44 | (const :tag "⌃ (Ctrl)" "^") 45 | (const :tag "⌥ (Option / Alt)" "~") 46 | ;; (const :tag "⌘ (Command / Windows Logo key)" "") 47 | (const :tag "# (Numpad)" "#") 48 | (const :tag "(none)" nil))) 49 | 50 | 51 | (defcustom term-keys/terminal-app-modifier-map ["$" "^" "~" nil nil nil] 52 | "Modifier keys for Terminal.app key bindings. 53 | 54 | This should be a vector of 6 elements, with each element being a 55 | string indicating the Terminal.app modifier corresponding to the 56 | Emacs modifiers Shift, Control, Meta, Super, Hyper and Alt 57 | respectively, as they should appear in generated Terminal.app 58 | configuration. nil indicates that there is no mapping for this 59 | modifier." 60 | :type '(vector 61 | (term-keys/terminal-app-modifier :tag "Shift") 62 | (term-keys/terminal-app-modifier :tag "Control") 63 | (term-keys/terminal-app-modifier :tag "Meta") 64 | (term-keys/terminal-app-modifier :tag "Super") 65 | (term-keys/terminal-app-modifier :tag "Hyper") 66 | (term-keys/terminal-app-modifier :tag "Alt")) 67 | :group 'term-keys/terminal-app) 68 | 69 | 70 | (defun term-keys/terminal-app-keymap-xml () 71 | "Construct Terminal.app key binding configuration. 72 | 73 | This function returns, as a string, a Terminal.app keymap as a 74 | property list fragment in XML format, which can be used to 75 | configure the terminal emulator to encode term-keys key sequences, 76 | according to the term-keys configuration. 77 | 78 | The returned string is suitable to be injected into the 79 | terminal's configuration, e.g. using the command: 80 | 81 | plutil -replace 'Window Settings.Basic.keyMapBoundKeys' \ 82 | -xml \"$(cat keymap.xml)\" \ 83 | ~/Library/Preferences/com.apple.Terminal.plist" 84 | 85 | (with-temp-buffer 86 | (let ((xml-invalid-characters-re "\\<\\>")) 87 | (xml-print 88 | `((plist ((version . "1.0")) 89 | (dict nil . 90 | ,(apply #'nconc 91 | (term-keys/iterate-keys 92 | (lambda (index keymap mods) 93 | 94 | (unless (and 95 | ;; Skip key combinations with unrepresentable modifiers 96 | (cl-reduce (lambda (x y) (or x y)) ; any 97 | (mapcar (lambda (n) ; active modifier mapped to nil 98 | (and (elt mods n) 99 | (not (elt term-keys/terminal-app-modifier-map n)))) 100 | (number-sequence 0 (1- (length mods))))) ; 0..5 101 | ;; Skip keys without a macOS Unicode key code 102 | (elt keymap 4)) 103 | 104 | `((key nil ,(concat 105 | (mapconcat 106 | (lambda (n) 107 | (when (elt mods n) 108 | (elt term-keys/terminal-app-modifier-map n))) 109 | (number-sequence 0 (1- (length mods))) ; 0..5 110 | "") 111 | (format "%04X" ; key code 112 | (or ; Apply shift 113 | (and (elt mods 1) ; With Control? 114 | (elt keymap 11)) ; Use control column 115 | (and (elt mods 0) ; With Shift? 116 | (elt keymap 10)) ; Use shifted column 117 | (elt keymap 4))))) ; Use non-shifted column 118 | (string nil ,(concat 119 | term-keys/prefix 120 | (term-keys/encode-key index mods) 121 | term-keys/suffix 122 | nil))))))))))) 123 | (buffer-string)))) 124 | 125 | 126 | (provide 'term-keys-terminal-app) 127 | ;;; term-keys-terminal-app.el ends here 128 | -------------------------------------------------------------------------------- /term-keys-urxvt.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-urxvt.el --- term-keys support for urxvt 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the urxvt terminal emulator to interoperate with 24 | ;; the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | (require 'term-keys-x11) 33 | 34 | 35 | (defun term-keys/urxvt-format-mods (mods) 36 | "Format modifiers into an urxvt prefix, 37 | 38 | Performs translation according to `term-keys/x11-modifier-map', 39 | and rxvt's keysym_vocabulary. To minimize the length of the 40 | resulting command line, the shortest prefix is used." 41 | (mapconcat 42 | (lambda (n) 43 | (if (elt mods n) 44 | (pcase (downcase (elt term-keys/x11-modifier-map n)) 45 | ("shift" "S-") 46 | ("lock" "L-") 47 | ("control" "C-") 48 | ("mod1" "1-") 49 | ("mod2" "2-") 50 | ("mod3" "3-") 51 | ("mod4" "4-") 52 | ("mod5" "5-") 53 | ;; These are private to urxvt: 54 | ("meta" "M-") 55 | ("numlock" "N-") 56 | ("appkeypad" "K-") 57 | ("level3" "I-") 58 | ;; Should be filtered ahead of time, using `term-keys/x11-key-representable' 59 | ('nil (error "Unsupported modifier: #%d" n)) 60 | (_ (error "Unknown modifier: %s" (elt term-keys/x11-modifier-map n)))) 61 | "")) 62 | (number-sequence 0 (1- (length mods))) 63 | "")) 64 | 65 | 66 | (defun term-keys/urxvt-format-key (keymap mods) 67 | "Format key modifiers in urxvt syntax. 68 | 69 | Returns key (given in KEYMAP, a `term-keys/mapping' row) 70 | prepended with appropriate modifiers depending on the elements of the bool vector 71 | MODS, and performing translation as necessary. 72 | 73 | If the KEY with MODS is unrepresentable, return nil." 74 | 75 | (when (term-keys/x11-key-representable keymap mods) 76 | (concat 77 | (term-keys/urxvt-format-mods mods) 78 | (term-keys/x11-apply-mods keymap mods)))) 79 | 80 | 81 | (defun term-keys/urxvt-args () 82 | "Construct urxvt configuration in the form of command line arguments. 83 | 84 | This function returns a list of urxvt (rxvt-unicode) command line 85 | arguments necessary to configure the terminal emulator to encode 86 | key sequences, according to the term-keys configuration." 87 | (apply #'nconc 88 | (term-keys/iterate-keys 89 | (lambda (index keymap mods) 90 | (list 91 | (concat 92 | "-keysym." 93 | (term-keys/urxvt-format-key keymap mods)) 94 | (concat 95 | "string:" 96 | term-keys/prefix 97 | (term-keys/encode-key index mods) 98 | term-keys/suffix)))))) 99 | 100 | 101 | (defun term-keys/urxvt-script () 102 | "Construct urxvt configuration in the form of a shell script. 103 | 104 | This function returns, as a string, a shell script which launches 105 | urxvt (rxvt-unicode) configured to encode term-keys key 106 | sequences, according to the term-keys configuration. 107 | 108 | The returned string is suitable to be saved as-is in an 109 | executable file and used for launching urxvt." 110 | (concat 111 | "#!/bin/sh\n" 112 | "exec urxvt \\\n\t" 113 | (mapconcat #'shell-quote-argument (term-keys/urxvt-args) " \\\n\t") 114 | " \\\n\t\"$@\"\n")) 115 | 116 | 117 | (defun term-keys/urxvt-xresources () 118 | "Construct urxvt configuration in the form of .Xresources entries. 119 | 120 | This function returns, as a string, the .Xresources entries 121 | necessary to configure urxvt to encode term-keys key 122 | sequences, according to the term-keys configuration. 123 | 124 | The returned string is suitable to be added as-is to an 125 | ~/.Xresources file." 126 | (apply #'concat 127 | (term-keys/iterate-keys 128 | (lambda (index keymap mods) 129 | (format "URxvt.keysym.%s: string:%s%s%s\n" 130 | (term-keys/urxvt-format-key keymap mods) 131 | term-keys/prefix 132 | (term-keys/encode-key index mods) 133 | term-keys/suffix))))) 134 | 135 | 136 | (defun term-keys/urxvt-run-emacs () 137 | "Launch Emacs via urxvt enhanced with term-keys. 138 | 139 | This function is used for testing and as an example." 140 | (apply #'start-process "urxvt" nil "urxvt" 141 | (append 142 | (term-keys/urxvt-args) 143 | (list 144 | "-e" (car command-line-args) "-nw" 145 | "--load" term-keys/main-file-name 146 | "--funcall" "term-keys/init" 147 | )))) 148 | 149 | 150 | (provide 'term-keys-urxvt) 151 | ;;; term-keys-urxvt.el ends here 152 | -------------------------------------------------------------------------------- /term-keys-wezterm.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-wezterm.el --- term-keys support for wezterm 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the wezterm terminal emulator to interoperate with 24 | ;; the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | (require 'term-keys-glfw-mods) 33 | 34 | 35 | (defun term-keys/wezterm-format-key (keymap mods) 36 | "Format key in wezterm syntax according to mods." 37 | (or ; Apply shift 38 | (and (elt mods 0) ; With Shift? 39 | (elt keymap 13)) ; Use shifted column 40 | (elt keymap 12))) ; Use non-shifted column 41 | 42 | 43 | (defun term-keys/wezterm-format-mods (mods) 44 | "Format modifiers in wezterm syntax. 45 | 46 | Returns the wezterm key combination string corresponding to the 47 | KEYMAP and modifier state MODS." 48 | (string-join 49 | (cl-loop for modflag across mods 50 | for index from 0 51 | if modflag 52 | collect 53 | (elt term-keys/glfw-modifier-map index)) 54 | "|")) 55 | 56 | 57 | (defun term-keys/wezterm-conf () 58 | "Construct wezterm configuration (wezterm.lua fragment). 59 | 60 | This function returns, as a string, the wezterm.lua key map lines 61 | necessary to configure wezterm to encode term-keys key sequences, 62 | according to the term-keys configuration." 63 | (concat "enable_kitty_keyboard = true,\nkeys = {\n" 64 | (apply #'concat 65 | (term-keys/iterate-keys 66 | (lambda (index keymap mods) 67 | (format " {key = \"%s\", mods = \"%s\", action = wezterm.action{SendString=\"%s\"}},\n" 68 | (term-keys/wezterm-format-key keymap mods) 69 | (term-keys/wezterm-format-mods mods) 70 | (mapconcat 71 | (lambda (c) (format "\\x%02x" c)) 72 | (append 73 | term-keys/prefix 74 | (term-keys/encode-key index mods) 75 | term-keys/suffix 76 | nil) 77 | ""))))) 78 | "},")) 79 | 80 | 81 | (provide 'term-keys-wezterm) 82 | ;;; term-keys-wezterm.el ends here 83 | -------------------------------------------------------------------------------- /term-keys-windows-terminal.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-windows-terminal.el --- term-keys support for Windows Terminal -*- lexical-binding: t; -*- 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software: you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation, either version 3 of the License, or 8 | ;; (at your option) any later version. 9 | 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program. If not, see . 17 | 18 | ;;; Commentary: 19 | 20 | ;; This file contains supplementary code for aiding in the 21 | ;; configuration of Windows Terminal terminal emulator to interoperate 22 | ;; with the term-keys package. 23 | 24 | ;; For more information, please see the accompanying README.me file. 25 | 26 | ;;; Code: 27 | 28 | (require 'term-keys) 29 | (require 'json) 30 | 31 | (defgroup term-keys/windows-terminal nil 32 | "`term-keys' options for Windows Terminal." 33 | :group 'term-keys) 34 | 35 | (define-widget 'term-keys/windows-terminal-modifier 'lazy 36 | "Choice for Windows Terminal key binding modifiers and state flags." 37 | :type '(choice (const :tag "Shift" "shift+") 38 | (const :tag "Ctrl" "ctrl+") 39 | (const :tag "Alt" "alt+") 40 | (const :tag "Win" "win+") 41 | (const :tag "(none)" nil))) 42 | 43 | (defcustom term-keys/windows-terminal-modifier-map ["shift+" "ctrl+" "alt+" "win+" nil nil] 44 | "Modifier keys for Windows Terminal key bindings. 45 | 46 | This should be a vector of 6 elements, with each element being a 47 | string indicating the name of the Windows Terminal modifier 48 | corresponding to the Emacs modifiers Shift, Control, Meta, Super, 49 | Hyper and Alt respectively, as they should appear in generated 50 | Windows Terminal settings JSON files. nil indicates that there 51 | is no mapping for this modifier." 52 | :type '(vector 53 | (term-keys/windows-terminal-modifier :tag "Shift") 54 | (term-keys/windows-terminal-modifier :tag "Control") 55 | (term-keys/windows-terminal-modifier :tag "Meta") 56 | (term-keys/windows-terminal-modifier :tag "Super") 57 | (term-keys/windows-terminal-modifier :tag "Hyper") 58 | (term-keys/windows-terminal-modifier :tag "Alt"))) 59 | 60 | (defun term-keys/windows-terminal-json () 61 | "Construct Windows Terminal settings. 62 | 63 | This function returns, as a string, the Windows Terminal settings 64 | in JSON format used to configure Windows Terminal to encode 65 | term-keys key sequences, according to the term-keys 66 | configuration." 67 | (let ((actions nil)) 68 | (term-keys/iterate-keys 69 | (lambda (index keymap mods) 70 | (unless (cl-reduce (lambda (x y) (or x y)) 71 | (mapcar (lambda (n) 72 | (and (elt mods n) 73 | (not (elt term-keys/windows-terminal-modifier-map n)))) 74 | (number-sequence 0 (1- (length mods))))) 75 | (let ((input (concat term-keys/prefix 76 | (term-keys/encode-key index mods) 77 | term-keys/suffix)) 78 | (keys (concat (mapconcat 79 | (lambda (n) 80 | (if (elt mods n) 81 | (elt term-keys/windows-terminal-modifier-map n))) 82 | (number-sequence 0 (1- (length mods)))) 83 | (elt keymap 14)))) 84 | (push `((:command . ((:action . "sendInput") 85 | (:input . ,input))) 86 | (:keys . ,keys)) 87 | actions))))) 88 | (let ((json-encoding-pretty-print t)) 89 | (json-encode `((:actions . ,(nreverse actions))))))) 90 | 91 | (provide 'term-keys-windows-terminal) 92 | ;;; term-keys-windows-terminal.el ends here 93 | -------------------------------------------------------------------------------- /term-keys-x11.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-x11.el --- term-keys X11 support code 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supporting code for aiding in the configuration 23 | ;; of X11 terminal emulators, such as st and urxvt, to interoperate 24 | ;; with the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | (require 'term-keys) 31 | 32 | (defgroup term-keys/x11 nil 33 | "`term-keys' options for X11-based terminal emulators." 34 | :group 'term-keys) 35 | 36 | 37 | (define-widget 'term-keys/x11-modifier 'lazy 38 | "Choice for X11 key modifier state flags." 39 | :type '(choice (const "Shift") 40 | (const "Lock") 41 | (const "Control") 42 | (const "Mod1" :tag "Mod1 (usually Alt)") 43 | (const "Mod2" :tag "Mod2 (usually Num Lock)") 44 | (const "Mod3") 45 | (const "Mod4" :tag "Mod4 (usually the Windows Logo key)") 46 | (const "Mod5") 47 | (const :tag "(none)" nil))) 48 | 49 | 50 | (defcustom term-keys/x11-modifier-map ["Shift" "Control" "Mod1" "Mod4" "Mod3" "Mod5"] 51 | "Map of X11 modifier state flags to Emacs modifiers. 52 | 53 | This should be a vector of 6 elements, with each element being a 54 | string indicating the name of the X11 modifier state mask (sans 55 | the -\"Mask\" suffix) corresponding to the Emacs modifiers Shift, 56 | Control, Meta, Super, Hyper and Alt respectively. nil indicates 57 | that there is no mapping for this modifier." 58 | :type '(vector 59 | (term-keys/x11-modifier :tag "Shift") 60 | (term-keys/x11-modifier :tag "Control") 61 | (term-keys/x11-modifier :tag "Meta") 62 | (term-keys/x11-modifier :tag "Super") 63 | (term-keys/x11-modifier :tag "Hyper") 64 | (term-keys/x11-modifier :tag "Alt")) 65 | :group 'term-keys/x11) 66 | 67 | 68 | (defun term-keys/x11-key-representable (keymap mods) 69 | "Return non-nil if the given KEYMAP + MODS vector is representable in X11." 70 | (and 71 | (elt keymap 1) ; Have X11 keysym? 72 | ;; Skip key combinations with unrepresentable modifiers 73 | (cl-reduce (lambda (x y) (and x y)) ; all 74 | (mapcar (lambda (n) 75 | (or (not (elt mods n)) ; inactive modifier 76 | (elt term-keys/x11-modifier-map n))) ; mapped 77 | (number-sequence 0 (1- (length mods))))))) ; 0..5 78 | 79 | 80 | (defun term-keys/x11-apply-mod-state (keymap shift lock control mod1 mod2 mod3 mod4 mod5) 81 | "Apply modifier state flags to an X11 KeySym. 82 | 83 | Given a key (given in KEYMAP, a `term-keys/mapping' row) which 84 | would be received by an application with no modifier flags, 85 | return the KeySym that would be received by the application if 86 | SHIFT, LOCK, CONTROL, MOD1, MOD2, MOD3, MOD4 and MOD5 modifier 87 | flags are respectively active." 88 | (or 89 | (and shift (elt keymap 6)) 90 | (elt keymap 1))) 91 | 92 | 93 | (defun term-keys/x11-apply-mods (keymap mods) 94 | "Apply Emacs modifiers to KEYMAP. 95 | 96 | Translate Emacs modifiers MODS to X11 modifiers (according to 97 | `term-keys/x11-modifier-map') and invoke 98 | `term-keys/x11-apply-mod-state'). KEYMAP is a 99 | `term-keys/mapping' row." 100 | (let (shift lock control mod1 mod2 mod3 mod4 mod5) 101 | (mapc 102 | (lambda (n) 103 | (when (elt mods n) 104 | (pcase (downcase (elt term-keys/x11-modifier-map n)) 105 | ("shift" 106 | (setq shift t)) 107 | ("lock" 108 | (setq lock t)) 109 | ("control" 110 | (setq control t)) 111 | ("mod1" 112 | (setq mod1 t)) 113 | ("mod2" 114 | (setq mod2 t)) 115 | ("mod3" 116 | (setq mod3 t)) 117 | ("mod4" 118 | (setq mod4 t)) 119 | ("mod5" 120 | (setq mod5 t)) 121 | ('nil) 122 | (_ (error "Unknown modifier: %s" (elt term-keys/x11-modifier-map n)))))) 123 | (number-sequence 0 (1- (length mods)))) 124 | (term-keys/x11-apply-mod-state keymap shift lock control mod1 mod2 mod3 mod4 mod5))) 125 | 126 | 127 | (provide 'term-keys-x11) 128 | ;;; term-keys-x11.el ends here 129 | -------------------------------------------------------------------------------- /term-keys-xterm.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys-xterm.el --- term-keys support for xterm 2 | 3 | ;; This file is not part of GNU Emacs. 4 | 5 | ;; This program is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2 of the License, or 8 | ;; (at your option) any later version. 9 | ;; 10 | ;; This program is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | ;; 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with this program; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file contains supplementary code for aiding in the 23 | ;; configuration of the xterm terminal emulator to interoperate with 24 | ;; the term-keys package. 25 | 26 | ;; For more information, please see the accompanying README.md file. 27 | 28 | ;;; Code: 29 | 30 | 31 | (require 'term-keys) 32 | 33 | 34 | (defconst term-keys/xterm-modifier-names ["Shift" "Ctrl" "Meta" "Super" "Hyper" "Alt"] 35 | "Modifier key names in xterm key translation syntax.") 36 | 37 | 38 | (defun term-keys/xterm-format-key (key mods) 39 | "Format key modifiers in xterm key translation syntax. 40 | 41 | Returns the xterm translation string corresponding to the KEY and 42 | modifier state MODS." 43 | (concat 44 | (cl-loop for modflag across mods 45 | for index from 0 46 | concat 47 | (concat 48 | (if modflag " " "~") 49 | (elt term-keys/xterm-modifier-names index) 50 | " ")) 51 | " " 52 | key)) 53 | 54 | 55 | (defun term-keys/xterm-translations () 56 | "Construct xterm configuration in the form of translation entries. 57 | 58 | This function returns, as a list of strings (one string per 59 | line), the xterm translation entries necessary to configure xterm 60 | to encode term-keys key sequences, according to the term-keys 61 | configuration." 62 | (term-keys/iterate-keys 63 | (lambda (index keymap mods) 64 | (format "%-55s: %s" 65 | (term-keys/xterm-format-key (elt keymap 1) mods) 66 | (mapconcat 67 | (lambda (c) (format "string(0x%02x)" c)) 68 | (append 69 | term-keys/prefix 70 | (term-keys/encode-key index mods) 71 | term-keys/suffix 72 | nil) 73 | " "))))) 74 | 75 | 76 | (defun term-keys/xterm-xresources () 77 | "Construct xterm configuration in the form of .Xresources entries. 78 | 79 | This function returns, as a string, the .Xresources entries 80 | necessary to configure xterm to encode term-keys key sequences, 81 | according to the term-keys configuration. 82 | 83 | The returned string is suitable to be added as-is to an 84 | ~/.Xresources file." 85 | (concat 86 | "\n*VT100.Translations: #override \\\n" 87 | (mapconcat #'identity 88 | (term-keys/xterm-translations) 89 | " \\n\\\n") 90 | "\n\n")) 91 | 92 | 93 | (defun term-keys/xterm-args () 94 | "Construct xterm configuration in the form of command line arguments. 95 | 96 | This function returns a list of xterm command line arguments 97 | necessary to configure the terminal emulator to encode key 98 | sequences, according to the term-keys configuration." 99 | (list 100 | "-xrm" 101 | (mapconcat #'identity 102 | (cons 103 | "XTerm.VT100.translations: #override" 104 | (term-keys/xterm-translations)) 105 | "\\n"))) 106 | 107 | 108 | (defun term-keys/xterm-script () 109 | "Construct xterm configuration in the form of a shell script. 110 | 111 | This function returns, as a string, a shell script which launches 112 | xterm configured to encode term-keys key sequences, according to 113 | the term-keys configuration. 114 | 115 | The returned string is suitable to be saved as-is in an 116 | executable file and used for launching xterm." 117 | (concat 118 | "#!/bin/sh\n" 119 | "exec xterm \\\n\t" 120 | (mapconcat #'shell-quote-argument (term-keys/xterm-args) " \\\n\t") 121 | " \\\n\t\"$@\"\n")) 122 | 123 | 124 | (defun term-keys/xterm-run-emacs () 125 | "Launch Emacs via xterm enhanced with term-keys. 126 | 127 | This function is used for testing and as an example." 128 | (apply #'start-process "xterm" nil "xterm" 129 | (append 130 | (term-keys/xterm-args) 131 | (list 132 | "-xrm" "XTerm*eightBitInput: false" 133 | "-e" (car command-line-args) "-nw" 134 | "--load" term-keys/main-file-name 135 | "--funcall" "term-keys/init" 136 | )))) 137 | 138 | 139 | (provide 'term-keys-xterm) 140 | ;;; term-keys-xterm.el ends here 141 | -------------------------------------------------------------------------------- /term-keys.el: -------------------------------------------------------------------------------- 1 | ;;; term-keys.el --- Lossless keyboard input in a terminal emulator 2 | 3 | ;; Version: 0.1.0 4 | ;; Author: Vladimir Panteleev 5 | ;; Url: https://github.com/CyberShadow/term-keys 6 | ;; Keywords: terminals 7 | ;; Package-Requires: ((emacs "24.3")) 8 | 9 | ;; This file is not part of GNU Emacs. 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation; either version 2 of the License, or 14 | ;; (at your option) any later version. 15 | ;; 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | ;; 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program; see the file COPYING. If not, write to 23 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 | ;; Boston, MA 02111-1307, USA. 25 | 26 | ;;; Commentary: 27 | 28 | ;; This package allows lossless keyboard input when using Emacs from a 29 | ;; terminal emulator. 30 | 31 | ;; For more information, please see the accompanying README.md file. 32 | 33 | ;;; Code: 34 | 35 | 36 | (require 'cl-lib) 37 | 38 | 39 | (defgroup term-keys nil 40 | "Lossless keyboard input in a terminal emulator. 41 | 42 | term-keys allows lossless keyboard input when using Emacs from a 43 | terminal emulator. 44 | 45 | For more information, please see the accompanying README.md 46 | file." 47 | :group 'convenience) 48 | 49 | 50 | (defcustom term-keys/mapping 51 | ;; Emacs X11 TTY Qt macOS Emacs shifted X11 shifted GLFW winit Qt sh. macOS-S macOS-C Wezterm Wez sh. Windows Terminal 52 | 53 | '(["" "Escape" 1 "Esc" #x001B nil nil "ESCAPE" "Escape" nil nil #x001b "Escape" nil "escape" ] 54 | ["" "F1" 59 "F1" #xF704 nil nil "F1" "F1" nil nil nil "F1" nil "f1" ] 55 | ["" "F2" 60 "F2" #xF705 nil nil "F2" "F2" nil nil nil "F2" nil "f2" ] 56 | ["" "F3" 61 "F3" #xF706 nil nil "F3" "F3" nil nil nil "F3" nil "f3" ] 57 | ["" "F4" 62 "F4" #xF707 nil nil "F4" "F4" nil nil nil "F4" nil "f4" ] 58 | ["" "F5" 63 "F5" #xF708 nil nil "F5" "F5" nil nil nil "F5" nil "f5" ] 59 | ["" "F6" 64 "F6" #xF709 nil nil "F6" "F6" nil nil nil "F6" nil "f6" ] 60 | ["" "F7" 65 "F7" #xF70A nil nil "F7" "F7" nil nil nil "F7" nil "f7" ] 61 | ["" "F8" 66 "F8" #xF70B nil nil "F8" "F8" nil nil nil "F8" nil "f8" ] 62 | ["" "F9" 67 "F9" #xF70C nil nil "F9" "F9" nil nil nil "F9" nil "f9" ] 63 | ["" "F10" 68 "F10" #xF70D nil nil "F10" "F10" nil nil nil "F10" nil "f10" ] 64 | ["" "F11" 87 "F11" #xF70E nil nil "F11" "F11" nil nil nil "F11" nil "f11" ] 65 | ["" "F12" 88 "F12" #xF70F nil nil "F12" "F12" nil nil nil "F12" nil "f12" ] 66 | ["" "Print" 99 "Print" #xF710 nil nil "PRINT_SCREEN" "Snapshot" nil nil nil "Print" nil nil ] 67 | ["" "Scroll_Lock" 70 "ScrollLock" nil nil nil "SCROLL_LOCK" "Scroll" nil nil nil "ScrollLock" nil nil ] 68 | ["" "Pause" 119 "Pause" nil nil nil "PAUSE" "Pause" nil nil nil "Pause" nil nil ] 69 | 70 | ["`" "grave" 43 "`" ?` "~" "asciitilde" "GRAVE_ACCENT" "Grave" "~" ?~ nil "`" "~" "`" ] 71 | ["1" "1" 2 "1" ?1 "!" "exclam" "1" "Key1" "!" ?! nil "1" "!" "1" ] 72 | ["2" "2" 3 "2" ?2 "@" "at" "2" "Key2" "@" ?@ nil "2" "@" "2" ] 73 | ["3" "3" 4 "3" ?3 "#" "numbersign" "3" "Key3" "#" ?# nil "3" "#" "3" ] 74 | ["4" "4" 5 "4" ?4 "$" "dollar" "4" "Key4" "$" ?$ nil "4" "$" "4" ] 75 | ["5" "5" 6 "5" ?5 "%" "percent" "5" "Key5" "%" ?% nil "5" "%" "5" ] 76 | ["6" "6" 7 "6" ?6 "^" "asciicircum" "6" "Key6" "^" ?^ nil "6" "^" "6" ] 77 | ["7" "7" 8 "7" ?7 "&" "ampersand" "7" "Key7" "&" ?& nil "7" "&" "7" ] 78 | ["8" "8" 9 "8" ?8 "*" "asterisk" "8" "Key8" "*" ?* nil "8" "*" "8" ] 79 | ["9" "9" 10 "9" ?9 "(" "parenleft" "9" "Key9" "(" ?\( nil "9" "(" "9" ] 80 | ["0" "0" 11 "0" ?0 ")" "parenright" "0" "Key0" ")" ?\) nil "0" ")" "0" ] 81 | ["-" "minus" 12 "-" ?- "_" "underscore" "MINUS" "Minus" "_" ?_ nil "-" "_" "-" ] 82 | ["=" "equal" 13 "=" ?= "+" "plus" "EQUAL" "Equals" "+" ?+ nil "=" "+" "=" ] 83 | ["" "BackSpace" 14 "Backspace" #x007F nil nil "BACKSPACE" "Back" nil nil nil "Backspace" nil "backspace" ] 84 | ["" "Tab" 15 "Tab" #x0009 "" "ISO_Left_Tab" "TAB" "Tab" nil nil nil "Tab" nil "tab" ] 85 | ["q" "q" 16 "Q" ?q "Q" "Q" "Q" "Q" nil ?Q #x0011 "Q" nil "q" ] 86 | ["w" "w" 17 "W" ?w "W" "W" "W" "W" nil ?W #x0017 "W" nil "w" ] 87 | ["e" "e" 18 "E" ?e "E" "E" "E" "E" nil ?E #x0005 "E" nil "e" ] 88 | ["r" "r" 19 "R" ?r "R" "R" "R" "R" nil ?R #x0012 "R" nil "r" ] 89 | ["t" "t" 20 "T" ?t "T" "T" "T" "T" nil ?T #x0014 "T" nil "t" ] 90 | ["y" "y" 21 "Y" ?y "Y" "Y" "Y" "Y" nil ?Y #x0019 "Y" nil "y" ] 91 | ["u" "u" 22 "U" ?u "U" "U" "U" "U" nil ?U #x0015 "U" nil "u" ] 92 | ["i" "i" 23 "I" ?i "I" "I" "I" "I" nil ?I #x0009 "I" nil "i" ] 93 | ["o" "o" 24 "O" ?o "O" "O" "O" "O" nil ?O #x000F "O" nil "o" ] 94 | ["p" "p" 25 "P" ?p "P" "P" "P" "P" nil ?P #x0010 "P" nil "p" ] 95 | ["[" "bracketleft" 26 "[" ?\[ "{" "braceleft" "LEFT_BRACKET" "LBracket" "{" ?{ #x001B "[" "{" "[" ] 96 | ["]" "bracketright" 27 "]" ?\] "}" "braceright" "RIGHT_BRACKET" "RBracket" "}" ?} #x001D "]" "}" "]" ] 97 | ["" "Return" 28 "Return" #x000D nil nil "ENTER" "Return" nil nil nil "Enter" nil "enter" ] 98 | ["" "Caps_Lock" 58 "CapsLock" nil nil nil "CAPS_LOCK" "Capital" nil nil nil "CapsLock" nil nil ] 99 | ["a" "a" 30 "A" ?a "A" "A" "A" "A" nil ?A #x0001 "A" nil "a" ] 100 | ["s" "s" 31 "S" ?s "S" "S" "S" "S" nil ?S #x0013 "S" nil "s" ] 101 | ["d" "d" 32 "D" ?d "D" "D" "D" "D" nil ?D #x0004 "D" nil "d" ] 102 | ["f" "f" 33 "F" ?f "F" "F" "F" "F" nil ?F #x0006 "F" nil "f" ] 103 | ["g" "g" 34 "G" ?g "G" "G" "G" "G" nil ?G #x0007 "G" nil "g" ] 104 | ["h" "h" 35 "H" ?h "H" "H" "H" "H" nil ?H #x0008 "H" nil "h" ] 105 | ["j" "j" 36 "J" ?j "J" "J" "J" "J" nil ?J #x000A "J" nil "j" ] 106 | ["k" "k" 37 "K" ?k "K" "K" "K" "K" nil ?K #x000B "K" nil "k" ] 107 | ["l" "l" 38 "L" ?l "L" "L" "L" "L" nil ?L #x000C "L" nil "l" ] 108 | [";" "semicolon" 39 ";" ?\; ":" "colon" "SEMICOLON" "Semicolon" ":" ?: nil ";" ":" ";" ] 109 | ["'" "apostrophe" 40 "'" ?' "\"" "quotedbl" "APOSTROPHE" "Apostrophe" "\"" ?\" nil "'" "\\\"" "'" ] 110 | [nil "Shift_L" 42 "Shift" nil nil nil "LEFT_SHIFT" "LShift" nil nil nil "LeftShift" nil nil ] 111 | ["\\" "backslash" 43 "\\" ?\\ "|" "bar" "BACKSLASH" "Backslash" "|" ?| #x001C "\\\\" "|" "\\" ] 112 | ["z" "z" 44 "Z" ?z "Z" "Z" "Z" "Z" nil ?Z #x001A "Z" nil "z" ] 113 | ["x" "x" 45 "X" ?x "X" "X" "X" "X" nil ?X #x0018 "X" nil "x" ] 114 | ["c" "c" 46 "C" ?c "C" "C" "C" "C" nil ?C #x0003 "C" nil "c" ] 115 | ["v" "v" 47 "V" ?v "V" "V" "V" "V" nil ?V #x0016 "V" nil "v" ] 116 | ["b" "b" 48 "B" ?b "B" "B" "B" "B" nil ?B #x0002 "B" nil "b" ] 117 | ["n" "n" 49 "N" ?n "N" "N" "N" "N" nil ?N #x000E "N" nil "n" ] 118 | ["m" "m" 50 "M" ?m "M" "M" "M" "M" nil ?M #x000D "M" nil "m" ] 119 | ["," "comma" 51 "," ?, "<" "less" "COMMA" "Comma" "<" ?< nil "," "<" "," ] 120 | ["." "period" 52 "." ?. ">" "greater" "PERIOD" "Period" ">" ?> nil "." ">" "." ] 121 | ["/" "slash" 53 "/" ?/ "?" "question" "SLASH" "Slash" "?" ?? nil "/" "?" "/" ] 122 | [nil "Shift_R" 54 "Shift" nil nil nil "RIGHT_SHIFT" "RShift" nil nil nil "RightShift" nil nil ] 123 | [nil "Control_L" 29 "Ctrl" nil nil nil "LEFT_CONTROL" "LControl" nil nil nil "LeftControl" nil nil ] 124 | [nil "Super_L" 125 "Meta" nil nil nil "LEFT_SUPER" "LWin" nil nil nil "LeftWindows" nil nil ] 125 | [nil "Alt_L" 56 "Alt" nil nil nil "LEFT_ALT" "LAlt" nil nil nil "LeftAlt" nil nil ] 126 | ["SPC" "space" 57 "Space" #x0020 nil nil "SPACE" "Space" nil nil #x0000 "Space" nil "space" ] 127 | [nil "Alt_R" 100 "Alt" nil nil nil "RIGHT_ALT" "RAlt" nil nil nil "RightAlt" nil nil ] 128 | [nil "Super_R" 126 "Meta" nil nil nil "RIGHT_SUPER" "RWin" nil nil nil "RightWindows" nil nil ] 129 | ["" "Menu" 127 "Menu" #x0010 nil nil "MENU" "Apps" nil nil nil "Applications" nil "menu" ] 130 | [nil "Control_R" 97 "Ctrl" nil nil nil "RIGHT_CONTROL" "RControl" nil nil nil "RightControl" nil nil ] 131 | 132 | ["" "Up" 103 "Up" #xF700 nil nil "UP" "Up" nil nil nil "UpArrow" nil "up" ] 133 | ["" "Down" 108 "Down" #xF701 nil nil "DOWN" "Down" nil nil nil "DownArrow" nil "down" ] 134 | ["" "Left" 105 "Left" #xF702 nil nil "LEFT" "Left" nil nil nil "LeftArrow" nil "left" ] 135 | ["" "Right" 106 "Right" #xF703 nil nil "RIGHT" "Right" nil nil nil "RightArrow" nil "right" ] 136 | 137 | ["" "Insert" 110 "Ins" #xF746 nil nil "INSERT" "Insert" nil nil nil "Insert" nil "insert" ] 138 | ["" "Delete" 111 "Del" #xF728 nil nil "DELETE" "Delete" nil nil nil "Delete" nil "delete" ] 139 | ["" "Home" 102 "Home" #xF729 nil nil "HOME" "Home" nil nil nil "Home" nil "home" ] 140 | ["" "End" 107 "End" #xF72B nil nil "END" "End" nil nil nil "End" nil "end" ] 141 | ["" "Prior" 104 "PgUp" #xF72C nil nil "PAGE_UP" "PageUp" nil nil nil "PageUp" nil "pageup" ] 142 | ["" "Next" 109 "PgDown" #xF72D nil nil "PAGE_DOWN" "PageDown" nil nil nil "PageDown" nil "pagedown" ] 143 | 144 | ;; Add new entries at the end of the list, to avoid disrupting 145 | ;; existing configurations. 146 | 147 | ;; TODO: numpad 148 | ) 149 | "List of keys supported by the `term-keys' package. 150 | 151 | Each item in the list is a 12-element vector: 152 | 153 | 0: The Emacs key name, as it occurs in `describe-key' or `kbd'. 154 | nil can be used to indicate keys which Emacs currently does 155 | not recognize (but are still known by other input systems), 156 | such as modifier keys (which Emacs can't process on its own, 157 | only in combination with a non-modifier key). 158 | 159 | 1: The X11 KeySym name, as returned by XKeysymToString. Used for 160 | urxvt/xterm configuration. 161 | 162 | 2: The keynumber (keycode) from the Linux TTY. You can obtain a 163 | key's keynumber by running the 'showkey' program in a TTY. 164 | 165 | 3: The Qt key name, as returned by QKeySequence::toString and 166 | accepted by QKeySequence::fromString. An easy way to obtain 167 | their name is using any KDE application's \"Configure 168 | Shortcuts\" dialog. 169 | 170 | 4: The Unicode character code emitted by the key on macOS. The 171 | program \"Key Codes\" by developer \"Many Tricks\" (available 172 | on the OS App Store) can display these values. 173 | 174 | 5: The shifted Emacs key name (i.e. the name when the same key 175 | is pressed while holding Shift), if it is different from the 176 | base name (index 1); otherwise, nil. Assumes a standard US 177 | ASCII layout. 178 | 179 | 6: The shifted X11 KeySym name (i.e. the name when the same key 180 | is pressed while holding Shift), if it is different from the 181 | base name (index 2); otherwise, nil. Assumes a standard US 182 | ASCII layout. 183 | 184 | 7: The GLFW key name, without the \"GLFW_KEY_\" prefix. 185 | A list can be found here: 186 | https://www.glfw.org/docs/3.3/group__keys.html 187 | 188 | 8: The key name as it appears in the Rust winit crate's 189 | VirtualKeyCode enumeration: 190 | https://docs.rs/glutin/0.28.0/glutin/event/enum.VirtualKeyCode.html 191 | 192 | 9: The shifted Qt key name (i.e. the name when the same key 193 | is pressed while holding Shift), if it is different from the 194 | base name (index 3); otherwise, nil. Assumes a standard US 195 | ASCII layout. 196 | 197 | 10: The shifted macOS key code (i.e. the code when the same key 198 | is pressed while holding Shift), if it is different from the 199 | base code (index 4); otherwise, nil. Assumes a standard US 200 | ASCII layout. 201 | 202 | 11: The control macOS key code (i.e. the code when the same key 203 | is pressed while holding Ctrl), if it is different from the 204 | base code (index 4); otherwise, nil. Assumes a standard US 205 | ASCII layout. Has precedence over index 10. 206 | 207 | 12: The wezterm key identifiers as described at: 208 | https://wezfurlong.org/wezterm/config/keys.html 209 | 210 | 13: The wezterm key identifiers for shifted keys. 211 | 212 | 14: The Windows Terminal key name. 213 | https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions#accepted-modifiers-and-keys" 214 | :type '(repeat 215 | (vector 216 | :tag "Key mapping" 217 | (choice 218 | :tag "Emacs key" 219 | (const 220 | :tag "No corresponding Emacs key" 221 | nil) 222 | (string 223 | :tag "Emacs key name")) 224 | (string 225 | :tag "X11 KeySym") 226 | (integer 227 | :tag "Linux TTY keynumber") 228 | (string 229 | :tag "Qt key name") 230 | (choice 231 | :tag "macOS Unicode character code" 232 | (const 233 | :tag "None" 234 | nil) 235 | (integer 236 | :tag "Character code")) 237 | (choice 238 | :tag "Shifted X11 KeySym" 239 | (const 240 | :tag "Same as non-shifted" 241 | nil) 242 | (string 243 | :tag "Shifted key name")) 244 | (string 245 | :tag "GLFW key name") 246 | (string 247 | :tag "winit key name") 248 | (choice 249 | :tag "Shifted Qt key name" 250 | (const 251 | :tag "Same as non-shifted" 252 | nil) 253 | (string 254 | :tag "Shifted key name")) 255 | (choice 256 | :tag "Shifted macOS Unicode character code" 257 | (const 258 | :tag "Same as non-shifted" 259 | nil) 260 | (integer 261 | :tag "Shifted character code")) 262 | (choice 263 | :tag "Control macOS Unicode character code" 264 | (const 265 | :tag "Same as without Control" 266 | nil) 267 | (integer 268 | :tag "Control character code")) 269 | (string 270 | :tag "Wezterm key name") 271 | (string 272 | :tag "Wezterm shifted key name") 273 | (string 274 | :tag "Windows Terminal key name"))) 275 | :group 'term-keys) 276 | 277 | 278 | (defcustom term-keys/prefix "\033\037" 279 | "Key sequence prefix. 280 | 281 | Indicates the byte string to be sent before a term-keys key code. 282 | 283 | The default value is \\033\\037 (0x1B 0x1F, or ^[^_). 284 | 285 | The prefix, or any starting substring of it, or any sequence 286 | beginning with it, should not be already bound to an action in 287 | Emacs. E.g. with the default, neither ^[, ^[^_, or ^[^_abc 288 | should by themselves be bound to an Emacs action." 289 | :type 'string 290 | :group 'term-keys) 291 | 292 | 293 | (defcustom term-keys/suffix "\037" 294 | "Key sequence suffix. 295 | 296 | Indicates the end of the data encoding the pressed key 297 | combination. Can be any character which isn't used in the 298 | `term-keys/encode-number' encoding scheme." 299 | :type 'string 300 | :group 'term-keys) 301 | 302 | 303 | (defun term-keys/want-key-p-def (key mods) 304 | "Default implementation for `term-keys/want-key-p-func'. 305 | 306 | This function controls which key combinations are to be encoded 307 | and decoded by default using the term-keys protocol extension. 308 | KEY is the KeySym name as listed in `term-keys/mapping'; MODS is 309 | a 6-element bool vector representing the modifiers Shift / 310 | Control / Meta / Super / Hyper / Alt respectively, with t or nil 311 | representing whether they are depressed or not. Returns non-nil 312 | if the specified key combination should be encoded. 313 | 314 | Note that the ALT modifier rarely actually corresponds to the Alt 315 | key on PC keyboards; the META modifier will usually be used 316 | instead." 317 | (let ((shift (elt mods 0)) 318 | (control (elt mods 1)) 319 | (meta (elt mods 2)) 320 | (super (elt mods 3)) 321 | (hyper (elt mods 4)) 322 | (alt (elt mods 5))) 323 | (and 324 | 325 | ;; We don't care about Super/Hyper/Alt modifiers 326 | (not super) 327 | (not hyper) 328 | (not alt) 329 | 330 | (or 331 | ;; https://lists.gnu.org/archive/html/bug-gnu-emacs/2004-03/msg00306.html 332 | (and (string-equal key "g") control meta) 333 | 334 | ;; Navigation keys and Control/Alt 335 | (and (member key '("Up" "Down" "Left" "Right" "Home" "End" "Prior" "Next")) (or meta (and control shift))) 336 | 337 | ;; S-PgUp/PgDn - usually used for scrolling the terminal, which is not useful in Emacs 338 | (and (member key '("Prior" "Next")) shift) 339 | 340 | ;; C-S-x is unrepresentable for letters 341 | (and (string-match-p "^[a-z]$" key) control shift) 342 | 343 | ;; C-x is unrepresentable for digits 344 | (and (string-match-p "^[0-9]$" key) control) 345 | 346 | ;; ...as well as punctuation and some special characters 347 | (and (member key '("Return" "Tab" "BackSpace" 348 | "grave" "minus" "equal" "bracketleft" "bracketright" "semicolon" 349 | "apostrophe" "backslash" "comma" "period" "slash" "space")) 350 | control) 351 | 352 | ;; Shift + special chars 353 | (and (member key '("Return" "BackSpace")) shift) 354 | 355 | ;; Menu (Apps) key 356 | (string-equal key "Menu") 357 | )))) 358 | 359 | 360 | (defcustom term-keys/want-key-p-func 'term-keys/want-key-p-def 361 | "Function for deciding whether to encode a key combination. 362 | 363 | This should be set to a function with the same signature and 364 | semantics as `term-keys/want-key-p-def'. Look at that function's 365 | documentation for more details. 366 | 367 | Customize this variable to a function or lambda defined by you to 368 | change which key combinations to encode." 369 | :type 'function 370 | :group 'term-keys) 371 | 372 | 373 | (defconst term-keys/modifier-chars "SCMsHA" 374 | "The characters for the Emacs modifiers supported by term-keys.") 375 | 376 | 377 | (defun term-keys/format-key (keymap mods) 378 | "Format key modifiers in Emacs syntax. 379 | 380 | Returns key (given in KEYMAP, a `term-keys/mapping' row) 381 | prepended with S-, C-, M-, s-, H-, or A- depending on the 382 | elements of the bool vector MODS are correspondingly non-nil." 383 | (concat 384 | (cl-loop for modflag across mods 385 | for index from 0 386 | if modflag 387 | concat (concat (string (elt term-keys/modifier-chars index)) 388 | "-")) 389 | 390 | ;; Perform Shift-translation 391 | ;; TODO: we probably should remove the "S-" prefix, but it doesn't 392 | ;; seem to matter in practice. 393 | (or 394 | (and (elt mods 0) (elt keymap 5)) 395 | (elt keymap 0)))) 396 | 397 | (defun term-keys/encode-number (num) 398 | "Efficiently encode non-negative integer NUM into a string. 399 | 400 | Use only characters that can safely occur on a command line or 401 | configuration file. Current implementation uses base-96 (ASCII 402 | \x20 .. \x7F)." 403 | (apply #'string 404 | (nreverse (cl-loop while (not (zerop num)) 405 | collect (+ 32 (% num 96)) 406 | do (setq num (/ num 96)))))) 407 | 408 | 409 | (defun term-keys/decode-number (str) 410 | "Decode a string STR encoded by `term-keys/encode-number'." 411 | (cl-do ((bytes (append str nil) 412 | (cdr bytes)) 413 | (num 0 (+ (* num 96) (- (car bytes) 32)))) 414 | ((not bytes) num))) 415 | 416 | (cl-loop for n in '(0 1 95 96 97 12345 123456789) 417 | do (cl-assert (eq (term-keys/decode-number 418 | (term-keys/encode-number n)) n))) 419 | 420 | 421 | (defun term-keys/encode-key (key mods) 422 | "Encode a key combination to term-keys' protocol. 423 | 424 | Returns a string ready to be sent by a terminal emulator (or 425 | received by Emacs running in a terminal) which encodes the 426 | combination of KEY (the key's index in the `term-keys/mapping' 427 | table) and the modifiers MODS (a 6-element bool vector indicating 428 | whether the respective modifier is pressed or not)." 429 | (term-keys/encode-number 430 | (cl-loop for index from 0 431 | for factor = 1 then (* factor 2) 432 | for modflag across mods 433 | if modflag 434 | sum factor into modflags 435 | finally return (+ modflags (* factor key))))) 436 | 437 | 438 | (defun term-keys/iterate-keys (fun) 439 | "Call FUN over every enabled key combination. 440 | 441 | Iterate over all elements of `term-keys/mapping' and modifier key 442 | combinations, filter the enabled ones using 443 | `term-keys/want-key-p-func', and call (FUN INDEX KEYMAP MODS), 444 | where INDEX is the key index in `term-keys/mapping', KEYMAP is 445 | the `term-keys/mapping' element vector at that index, and MODS is 446 | a bool vector for the active modifier keys. 447 | 448 | Collect FUN's return values in a list and return it." 449 | (cl-loop 450 | for keymap in term-keys/mapping 451 | for index from 0 452 | append 453 | (cl-loop 454 | ;; Iterate from 0 to 2^6-1 for a bitmask of all modifier combinations 455 | for modnum from 0 to (1- (lsh 1 (length term-keys/modifier-chars))) 456 | ;; Convert the integer bitmask to a bool-vector 457 | for mods = (apply #'bool-vector (mapcar (lambda (n) (not (zerop (logand modnum (lsh 1 n))))) 458 | (number-sequence 0 (1- (length term-keys/modifier-chars))))) 459 | if (and 460 | (elt keymap 0) ; Representable in Emacs? 461 | (funcall term-keys/want-key-p-func (elt keymap 1) mods)) ; Want this key combination? 462 | collect (funcall fun index keymap mods)))) 463 | 464 | 465 | ;;;###autoload 466 | (defun term-keys/init () 467 | "Set up configured key sequences for the current terminal." 468 | (interactive) 469 | 470 | ;; Hack for Emacs 28 and higher. 471 | ;; TODO: We want to remove this binding only from the input decode 472 | ;; step - it should still be accessible via the term-keys protocol. 473 | (let ((prefix-bind (key-binding term-keys/prefix))) 474 | (when prefix-bind 475 | (message "term-keys: term-keys/prefix (%S) is already bound to %s (as %s) - unbinding" 476 | term-keys/prefix 477 | prefix-bind 478 | (key-description term-keys/prefix)) 479 | (global-unset-key term-keys/prefix))) 480 | 481 | (term-keys/iterate-keys 482 | (lambda (index keymap mods) 483 | (define-key 484 | input-decode-map 485 | (concat 486 | term-keys/prefix 487 | (term-keys/encode-key index mods) 488 | term-keys/suffix) 489 | (kbd (term-keys/format-key keymap mods)))))) 490 | 491 | 492 | ;;;###autoload 493 | (define-minor-mode term-keys-mode 494 | "`term-keys' global minor mode. 495 | 496 | When enabled, automatically set up configured keys for new frames 497 | on TTY terminals. If the current frame is on a TTY, set it up as 498 | well." 499 | :global t 500 | :require 'term-keys 501 | (if term-keys-mode 502 | (progn 503 | (add-hook 'tty-setup-hook 'term-keys/init) 504 | (if (eq (framep-on-display) t) 505 | (term-keys/init))) 506 | (remove-hook 'tty-setup-hook 'term-keys/init))) 507 | 508 | 509 | (defconst term-keys/main-file-name (or load-file-name buffer-file-name) 510 | "Path to this file. Used for interop.") 511 | 512 | 513 | (provide 'term-keys) 514 | ;;; term-keys.el ends here 515 | --------------------------------------------------------------------------------