Can we remap keys?

147 views
Skip to first unread message

Eric Simard

unread,
Jan 13, 2015, 9:40:45 AM1/13/15
to xi...@googlegroups.com
Good morning!
Already being picky, but can I remap some keys within xsh?
C-a C-e
How would I go about this?

Eric Simard

unread,
Jan 24, 2015, 5:28:18 PM1/24/15
to xi...@googlegroups.com
The reason I wanted to remap keys was because I always use C-{k,a,e} in emacs, and having those keys perform otherwise was making it difficult to move around.
But I noticed that I won't need to, xsh takes complete control over C-, but does not use M- keys. I will simply remap emacs M-{k,a,e}. I can live with that.
But in my search I found this comments that explains how to create key shortcut "C-":
 > Summary                                                                                                                                                                                
     
| Ways to use the Keys class, to define keyboard shortcuts etc.  Remember                                                                                                                
     
| that with xiki shortcuts you hold down the control key and "type the                                                                                                                  
      | acronym"
(the first letter in each word) while holding down the control                                                                                                                
     
| key.                                                                                                                                                                                  
     
|                                                                                                                                                                                        
     
> Define keyboard shortcuts                                                                                                                                                              
     
| Defines the key Control-e Control-y                                                                                                                                                    
     
|                                                                                                                                                                                        
     
|   Keys.enter_name { View << "Steve" }                                                                                                                                                  
     
|                                                                                                                                                                                        
     
| Defines the key Control-e Control-y (with no mnemonic)                                                                                                                                
     
|                                                                                                                                                                                        
     
|   Keys.EN { View << "Steve again" }                                                                                                                                                    
     
|                                                                                                                                                                                        
     
> Where to put them                                                                                                                                                                      
     
| You can put keyboard shortcuts into any file that gets required by xiki.                                                                                                              
     
| For example, you could create a file like this:                                                                                                                                        
     
|                                                                                                                                                                                        
     
- @~/my_xiki_stuff/                                                                                                                                                                      
       
- keys.rb                                                                                                                                                                              
         
| # My shortcuts                                                                                                                                                                    
         
| Keys.enter_name { View << "Steve" }                                                                                                                                                
         
| Keys.enter_yay { View << "Yay" }                                                                                                                                                  
     
|                                                                                                                                                                                        
     
| Then you could require this file when xiki loads by adding this line:                                                                                                                  
     
|                                                                                                                                                                                        
     
- @~/.el4r/                                                                                                                                                                              
       
- init.rb                                                                                                                                                                              
         
| require "~/my_xiki_stuff/keys"          

Craig Muth

unread,
Jan 25, 2015, 1:04:33 AM1/25/15
to xi...@googlegroups.com
> I will simply remap emacs M-{k,a,e}. I can live with that.

Short answer > add this stuff to your startup.rb file (or create it if
it's not there):

~/xiki/misc/startup.rb
: # Map Alt+A, Alt+E, and Alt+K
: $el.el4r_lisp_eval %`
: (progn
: (global-set-key (kbd "M-a") 'move-beginning-of-line)
: (global-set-key (kbd "M-e") 'move-end-of-line)
: (global-set-key (kbd "M-k") 'kill-line)
: )
: `

Long answer > maybe I should add those mappings by default, since many
people may want them.

The comment you found is a bit out of date. It's in the plans to make
meta (aka "alt" or "option") keys definable via this, but it's not
implemented yet:

Xiki.def("Alt+A"){ # ruby code }

Side note, I'll get to everyone's install issues within a few days.
I'm sidetracked working on something cool, re quickly jumping in and
out of Xsh from your shell. It's almost wrapped up!

--Craig
> --
> You received this message because you are subscribed to the Google Groups
> "Xiki" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to xiki+uns...@googlegroups.com.
> To post to this group, send email to xi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/xiki.
> For more options, visit https://groups.google.com/d/optout.

Craig Muth

unread,
Jan 25, 2015, 1:12:15 AM1/25/15
to xi...@googlegroups.com
Oh yeah, and grab the latest xiki, since I just fixed a bug where it
wasn't loading ~/xiki/misc/startup.rb:

https://github.com/trogdoro/xiki/commit/a9053440a272edf7060b6c2e717e8fc990751ca1

--Craig

Eric Simard

unread,
Jan 25, 2015, 4:00:16 PM1/25/15
to xi...@googlegroups.com

Awsome thanks for the clarification.
Works perfect!
Do you have a wiki setup up somewhere for documenting?
I would be willing to document this section if you like.

Craig Muth

unread,
Jan 25, 2015, 6:23:43 PM1/25/15
to xi...@googlegroups.com
Xiki itself is a wiki :) Since commands can have headings, paragraphs
and bullet points, and can link to each other.

The xiki way of finding documentation for key shortcuts is to type a
word that seems relevant, like "keys" or "key shortcuts" on a blank
line, and then expand it. I have a "key shortcut" command locally
that has some explanative text, but haven't committed it yet as it's
out of date. I thought about committing it, but it's so far different
from the current way key shortcuts work (and which ones should be
emphasized first) that it would be more misleading than helpful.

Also, when you type "manual" or "docs" or "tutorial" or anything like
that, there menu items should get you (maybe after a couple jumps) to
docs for key shortcuts and anything else.

At some point, I'll probably try to either have a generation step that
mirrors the commands to the github project wiki, or serve it off of
xiki.org/docs (and make the menu items work).

--Craig

Craig Muth

unread,
Jan 25, 2015, 7:27:29 PM1/25/15
to xi...@googlegroups.com
Though... a FAQ command (or page) might be a good place for people to
contribute stuff like this (thanks for the offer to help document!).
I just committed this as a starting point.

https://github.com/trogdoro/xiki/commit/b5874789b2eef048d4ad157935dc745876905081

You can view this faq (after grabbing the latest from github) by
typing "faq" on a blank line in xsh and expanding it:

faq/
: What key shortcuts are like Ctrl+A, Ctrl+E and Ctrl+X in bash?
| You can do Alt+A, Alt+E, and Alt+K ("option" instead of "alt"
| on the mac).
: Why aren't there more questions in this faq?
: How can I contribute to this faq?

...or, by running this in your regular shell:

$ xsh -faq

If it gets much added to it, I should probably mirror to as a markdown
file, and then link to that from the README
(https://help.github.com/articles/relative-links-in-readmes/).

Note it'll be a day or so until I commit the change to wire up M-a,
M-e, and M-k.

michae...@gmail.com

unread,
Feb 21, 2015, 6:58:16 AM2/21/15
to xi...@googlegroups.com

After trying to use xsh for a couple of days, this is my biggest gripe. Not only am i used to using Ctrl+a,e,d,k in emacs, and in a normal shell, but they are also built into MacOS X as default keys. They perform the same operations as emacs. 

Having to switch to alt/option for xiki is rough, when the ctrl keys work everywhere else just isn't working for me. 

It would be great if there was a config option that allowed you to switch the modifier key that xiki uses. 

I was messing with the code a little this morning, defining a key in startup.rb and then using it in key_shortcuts.rb, but it wasn't working as expected. Hopefully i'll get a chance to play more tonight after the kids go to bed. 

Eric Simard

unread,
Feb 21, 2015, 4:14:13 PM2/21/15
to xi...@googlegroups.com
Yea, I was starting to get used to switching with alt, but the config for keys is a must (at some point).
Now that C-e as become C-x, it made it worst, that kill all emacs command. I would rather see Xiki/xsh work along side emacs but it is taking it over.
But it is also it early stage of development and Craig must be full time on other more important issue then remap config option.
But personally I consider the move to C-x a bad one. I honestly still think your first way with C-RET to expand was the best.
If I was familiar with RUBY I would be of more help, but I have to come from pretty far.

Craig Muth

unread,
Feb 21, 2015, 7:20:13 PM2/21/15
to xi...@googlegroups.com
>> After trying to use xsh for a couple of days, this is my biggest gripe.
>> Not only am i used to using Ctrl+a,e,d,k in emacs, and in a normal shell,
>> but they are also built into MacOS X as default keys.

Add the following to set Ctrl+A, Ctrl+E, and Ctrl+K to the standard behavior.

~/xiki/misc/
- startup.rb
: module Xiki
: Keys.set("C-a"){ Move.hop_left_key }
: Keys.set("C-e"){ Move.hop_right_key }
: Keys.set("C-k"){ Clipboard.kill }
: end

> would rather see Xiki/xsh work along side emacs but it is taking it over.

The plan for getting xiki running inside of Emacs in a non-instrusive
way (which isn't the goal of xsh) is to define a xiki_prefix setting.
In xsh, xiki_prefix is ctrl, but (after I finish implementing this)
you'll be able to set it to alt, or alt+shift, or ctrl+alt, etc. That
way the xiki keys will be off in their own namespace, if you know what
I mean. For emacs users of xsh, I'll probably make that mappable in
xsh as well "emacs running xiki", so that all keys not using
xiki_prefix would default to their emacs functionality.

> your first way with C-RET to expand was the best.

That unfortunately doesn't work consistently (possibly at all?) in
terminals. I'd thought about using alt+x at one point, but that has
issues in some terminals as well. One upside of Ctrl+X is when you're
in bash, it's simply "Ctrl+X for Xiki", which is kind of awesome in a
way.

--Craig
Reply all
Reply to author
Forward
0 new messages