Emacs: how to swap ctrl and alt using configure file? - emacs

Before posting this question, I've read this so thread and have a brief view on the emacs wiki.
However, all the guides above use a system-wide keymapping or some key binding software. As emacs can be configured, is there any way to swap the ctrl and alt key using the ~/.emacs configure file?

By default Alt key is not mapped to a emacs modifier. Each OS does it differently. So you will need an OS depended solution:
On Windows try use the key binding functions of EmacsW32.
On Mac OSX use the built-in ns-command-modifier, ns-control-modifier and ns-option-modifier.

In Emacs for OS X there is a settings group for this: M-x customize-group RET ns RET
see link
Unfortunately I was not able to find similar settings for the other OSes. But maybe you can hack your own based on the code for ns.

Related

How do you avoid key binding collisions between VS Code and vscodevim?

I have some shoulder pain that I am trying to get rid of by using vscodevim.
My biggest problem with vscodevim so far is that is sometimes collides with VS code shortcuts. For example I often save all my files with Ctrl+K S. But with vscodevim enables, instead that key combination does something else.
I feel tired about the prospect of having to build a configuration with my own key VS Code key bindings, that don't conflict with vsvim. I hope there is a better solution.
So I ask you, my better knowing colleagues, how do you solve this problem?
There is no easy way out for avoiding conflicts between vscode shortcut and vscodevim bindings. I suggest you to use vim keybindings instead of vscode shortcuts wherever possible. Vscodevim can prove to be a good gateway to vim provided you are open to relearning how you use vscode.
Instead of building your own configuration that doesn't collide with vscodevim you could redirect the effort in finding a way to do the same thing in vim. You can search web or use vim help.
Vim help is really comprehensive and easy to read. If you have vim installed you can use :help or :h followed by a specific subject, for example if you need to read about navigation type :h navigation.
Now you have two choices and I will try to use example you provided i.e. saving a file :
Use bindings available for saving file in vim.
Vim provides so many shortcuts just for saving and quitting files, in vim try :help write and :help quit to know more. Many of those shortcuts works in vscodevim too.
To save file :
:w to save a single file
:wa to write all buffers (in vscode all modified files).
Remove the bindings from vscodevim and use vscode shortcut.
You can delegate the key combination back to vscode. I suggest you do this only if there is any vscode shortcut that is absolutely necessary for you and it conflicts with vscodevim as doing this may result in some related vim bindings to not work. To know what Ctrl+k does in vim type :h ctrl-k in vim.
If you want to use Ctrl+K S for saving file do following:
Open vscode settings and search for vim handlekeys or directly open vscode's settings.json:
add following "vim.handleKeys": {"<C-k>": false}
I don't know if this a better solution but I was in your situation and tried different ways to solve it. Finally I found it was much easier to use vim keybindings than trying to coerce vscodevim.
I set up a "toggleVim" keybinding, like so: https://stackoverflow.com/a/61652769/1054322
When I want to use a hotkey that clashes with vim, I just turn off vim.
I installed "vscode neovim" instead of "vim".
Open the vscode setting, you can search "vscode-neovim: Use ctrl keys for insert Mode", disable it.
So you can use "ctrl k+ ctrl c" to add a line comment in insert mode. Also other vscode "ctrl" keys could be used in this mode.

M-x not working for 2 days in Emacs

I do use Emacs for years, and in particular the Cygwin Emacs version (under Windows 10) for months.
Since 2 days, M-x combo key is not working anymore, well ESC x but I don't want to be forced to use Emacs à la Vi ;-)
First, I thought that the keyboard of my laptop could have a trouble, but the same effect is observed with an external keyboard connected by USB.
Second, I though it could be due to some changes I did in my own Emacs init file, or changes inherited from MELPA. To test that, I came back into time with Git, but that wasn't it: problem still observed; to test for MELPA packages, I used a minimal Emacs (emacs -q) and, once again, the problem still persists.
(And ESC x displays that M-x, translated from <escape> x, runs the command
execute-extended-command -- which is expected.)
Finally, what's weird, is that the key x alone is working, and so does C-x. On the other hand, M (meta) is working: M-c, M-w do work like expected.
So, to sum up, only the particular combination M-x is not working, and I really have no idea why.
Any smart test I could do to debug this (on Win 10)?
To sum up the answer in the comments:
If your key combination does not do what you expect - use C-h k to find out if it's a wrong mapping inside emacs, or something is grabbing this combination before emacs has a chance. If C-h k doesn't do anything in response to Alt-X - then you can be certain emacs doesn't see it at all.
If you want to confirm a key combination has been hijacked try to use some other application with it. Alt-X isn't used by regular Windows applications, but if you happen to have anything else that can have customized key bindings then try to map Alt-X to anything inside it. Eclipse, IntelliJ, Visual Studio, gvim. But seeing what happens with C-h k is a sufficient proof.
To find out what is stealing your Alt-X check what was installed or reconfigured lately. Disable startup programs if you can't recall. Additionally, from my experience a couple of nasty offenders: Intel video driver, and Windows language bar. (Not with Alt-X, with other key combinations.) Windows language bar is especially annoying when it steals C-S-) which I use for slurp.
Last thing. If you are running in a VM, your key combination may be stolen at either host or guest level (or both, as I've seen with the language bar.) So you may need to look around in both places.
I encountered the same problem. But I found that the problem was come up with the conflict of hotkey. On my Win10 OS, M-w is conflicted with the Tencent QQ software. So when I closed the QQ or changed the QQ's hotkey, the Emacs worked well.
I don't know why, but the problem is with Growl for windows v2.0.8. Close it and emacs will run normally.
Anyways, any new program setup could create conflicts. Stop all new (since the bug) process and check it.
(I don't want to change the keys configuration)

Emacs in Mac OS Lion terminal - map right command key to meta

I just started using GNU Emacs on my Mac OS X Lion and I am trying to ease up my hand movement through various key bindings. Specifically, I want to be able to use the right command key for meta.
The following code in my .emacs file does the trick for the standalone application (Emacs.app)
;;; cmd key for meta
(setq mac-option-key-is-meta nil
mac-command-key-is-meta t
mac-command-modifier 'meta
mac-option-modifier 'none)
(Snippet taken from this Superuser answer)
but does not work with emacs run in terminal mode. The meta there is still the alt/option key which I set from the Terminal.app preferences. When I disable this option key, I lose the meta key capability all together.
Any ideas?
i'm not aware of terminal providing you with the ability to deal with the left/right command key mappings. iterm2 provides the means to accomplish what you're looking for there. albeit at a global basis for iterm2.
There appears to be keyremap4macbook that may save you some time if you must use emacs in terminal. I can take no credit for this, but this guy can

How do I get SLIME + Emacs set up?

According to this answer, Emacs + Slime already has much advanced functionality. So how can I get syntax coloring, auto-completion, and perhaps even version control management, set up and running in my copy of Lispbox?
If it's of any help, I have installed Lispbox on Mac OS Lion.
Syntax highlighting should already be working as soon as you load a lisp file in Emacs, regardless of whether you've got SLIME installed or not. If it's not, try doing M-x font-lock-mode and see if that turns it on.
Version control isn't provided by Emacs or SLIME, but Emacs can integrate with pretty much any version control system you care to use. I recommend Mercurial or Git. Emacs should start vc-mode automatically when you open a file that is in one of the supported version control systems. The manual includes extensive documentation, do M-: (info "(emacs)Version Control") to jump right to it.
Auto-completion is more complicated. There is more than one way to skin this cat, but for Lisp SLIME's default method should be good enough. Use M-TAB to complete the symbol at point.

Option or Command key as Meta key for LispBox on Macintosh

I'm new to emacs and have just downloaded LispBox (from the Practical Common Lisp page) with SBCL to my Macintosh. I do know enough to realize I want either the option or Command key to be the meta key.
The emacs version delivered with LispBox doesn't pay attention to .emacs in my home directory.
Emacs as delivered with LispBox fires up into a REPL. I can't figure out what I should type to set up a command key as Meta, nor where or how to configure it permanently.
Edit: I'm not really interested in loading up another version of emacs. I already have emacs running from the Terminal with my option key mapped as meta. Being able to closely follow the "Practical Common Lisp" tutorial, which assumes LispInABox, is what I'm interested in here.
TIA.
Navigate to /Applications/Lispbox/Emacs.app/Contents/MacOS and edit lispbox.sh, removing the --no-init-file parameter. Then, inside ~/.emacs, add (setq mac-command-modifier 'meta)
As an alternative check out Ready Lisp for Mac OS X. It uses Aquamacs for Emacs.
Aquamacs is a specially for Mac OS X enhanced GNU Emacs.
If you run Emacs in a Mac OS X terminal, you can set the Option key to be the Meta key using the 'Preferences' dialog.