How to change the meta key in Emacs? - emacs

I've just started to put in the time to get to learn emacs. By default my meta key is bound to Esc, and I'm finding that really inconvenient. I read somewhere however that it's not a good idea to change the binding to Alt. Is that true? If not, how could I go about doing that?

It's bound to Alt by default for me, and I have no problems with that. Are you on a Mac perhaps? There it is bound to one of the other keys like option.
If you are on a mac, the way to change the key will probably vary based on which version of Emacs you're using--e.g., I think changing it in the terminal would be different than changing it on one of the windowed varieties.
Another thing to try: http://www.jwz.org/xkeycaps/
Look through the keyboard layout with this and see if any key is assigned to Meta. If not, try assigning it; otherwise try changing it. I haven't actually tried this, but it looks promising.

If you are using a Mac, you can follow the directions from here:
"If you do not want to use the Esc key, you can specify a key to use as Meta. To specify a Meta key, select the Emulation tab of the Editor Preferences dialog."
You can then select to use Alt or Command as your Meta key.

I'm guessing that you're on Mac, because I had the same problem. This is how I fixed it:
Open Terminal
Open up the preferences
Open up the "Profiles" tab and choose the "Keyboard" tab with your current profile selected
Below the long scroll box are a couple check boxes. Check "Use Option as Meta key."
I'm using OS X 10.11.5, so I don't know about older versions of Terminal. I imagine that it would be similar.

For me, on my mac, it was bound to Alt by default, but I found it anoying because Alt is used for some special characters on Mac.
I added these lines on my .emacs
(setq mac-function-modifier 'meta)
(setq mac-option-modifier nil)
Thus in your case, you would have to add this in your .emacs (I tried this solution, and it worked for me)
(setq mac-option-modifier 'meta) ; set alt-key to meta
(setq mac-escape-modifier nil) ; set esc-key to nil

I had to do this for emacs while remotely connected to my raspberry pi.
Go to terminal.
type:
xmodmap -e "keysym Alt_L = Meta_L Alt_L"
This was suggested in xmodmap's manual
man xmodmap
Hope that helps :) I'm pretty new to this though so someone else may want to comment.

Related

Remove auto-completion with Enter key in Kate text editor

In Kate text editor, one can auto complete using either the Tab or the Enter key.
I find auto-completion with the Enter key disruptive, because often you really do mean what you say, and want to go to a new line. Who knew.
How can I disable only the Enter key auto-completion without removing the Tab auto-completion?
You CAN'T do that.
From https://bugs.kde.org/show_bug.cgi?id=316413:
Sorry, but auto-complete really works ok the way it is. If we alter that behavior, we will get many more reports about that than with the current way.
And then:
You can deactivate the auto completion in the settings. Then you can invoke it manually. If that doesn't help, then yes, Kate is perhaps not the best choice, sorry.
So it seems, from the developers' own mouth, that Enter can't be turned off. You can turn off autocomplete as a whole, or if you don't like that, you can find another text editor. Or you can edit the source code yourself, after all it's Open Source.
The developers like it as it is, and have no intention of making the behavior configurable.
I've seen a workaround in this article that works for me:
go to: Settings->Configure Keyboard Shortcuts. Then change the Action:
"Insert Smart Newline to Enter instead of Shift+Enter.

set-mark-command not working emacs with C-SPC

I am not able to set the mark at the current point by C-SPC (both when emacs loads the init file and when it doesn't). However, when I do M-x set-mark-command, the mark is well set and I am able to select the region by moving the cursor. When I do M-x apropos set-mark-command, it shows two bindings C-# and C-SPC, but only the first one works. Any suggestions will be appreciated.
I am running emacs 24.3 on a GUI on Kubuntu 14.04.
Ubuntu 14.04 has an open bug affecting some desktop environments (at least KDE, LXDE and i3, but not Unity).
The default IBus key binding for "next input method" is Ctrl+Space, which prevents this key combination from reaching Emacs (or any other userspace program). To resolve the issue, run ibus-setup and change the key binding for "next input method" to something else (or delete it entirely by clicking the "..." button and then the "Delete" button).
Note that running ibus-setup from Unity, where C-SPC works already, shows a preferences window that does not include the key binding option that needs to be changed.
The "next input method" command cycles through your configured inputs, e.g. perhaps from English to French.
So I tracked down a similar issue to this on macOS. It seems that at some point C-SPC became bound to "Select the previous input source":
I just had the same issue today which I never had before. I am on Windows 7. As it turns out the Ctrl+SPC is bound to the OS's language switch. So the keystrokes are not sent to emacs at all.
But one thing that is even more weird is that I have never installed new languages/keyboards, yet the 'CH PRC' shows up in my language bar as a language/keyboard today. It turns out to be a Windows 7 bug and all I had to do to fix was:
Add 'CH PRC' in the language bar then Save.
Remove the language then Save again.
I know you are not on Windows, so the fix may not be the same as mine, but it is very likely Ctrl+SPC is bound to your OS's language switch as well.

How do you find out which mode changed a keybinding in emacs?

I found out when I use gud-gdb, it overrides one of my keybindings. I would like to check which mode changed the keybinding (I know it's probably gud-gdb, but I would still like to know how to check this). I know about C-h k, but is it possible to check which mode set a keybinding?
I use C-h+m, which runs describe-mode. That lists all the keybinds associated with each mode that is currently active. The keybinding that is getting clobbered will likely be there.
In general, when assigning keys (either as a user or as a mode author) it's best to follow the Emacs key binding conventions.

Some standard Emacs keybindings don't work on my Linux box

On my macbook everything worked nicely, but on my Archlinux box, with dwm as a window manager, the following keybindings don't work:
M-m
M-<
M->
It is kind of a pain to work without these bindings. I should note that many other Meta key bindings work fine.
Does anyone know how to fix this?
They're probably being intercepted by your window manager. I don't know dwm, but I'd try googling "dwm resetting keyboard shortcuts".
(A quick read of the results suggests dwm may need to be recompiled to do this, see http://dwm.suckless.org/)

Mac OS X Emacs Does Not Highlight Comments Correctly

I'm pretty old school sometimes and I like working with Emacs in my terminal. (I work with IDEs all the time. But sometimes, when in the privacy of my own home, I just like a text editor a terminal and a beer)
However, the default Emacs that comes with OS X does not seem to highlight the comments in font-lock-mode. I've seen this behavior in both Python and C mode.
I've already searched some forums and I found one post where the person was having the same problem as me:
http://forums.macosxhints.com/showthread.php?p=512361
Is is there any way to fix this problem?
I had this exact same problem. The solution is to change the color used for the comment face as follows:
(set-face-foreground 'font-lock-comment-face "red")
Or, if you only want to do this for certain modes:
;;; Only do this for the common C mode (C, C++, Objective-C)
(add-hook 'c-mode-common-hook #'(lambda () (set-face-foreground 'font-lock-comment-face "red")))
For more information on faces, see http://www.gnu.org/software/emacs/manual/html_node/emacs/Faces.html.
I'm not sure exactly how to fix it, but I'm fairly certain there's something you can put in the .emacs file. In fact, I think I've done that before. I'll look for my file and let you know what I can find.
I'll try and get you my .emacs file when I get home from work tonight.
[edit] I've looked and looked, and can't find a .emacs file on either system that I use, and on my OS X install (Leopard default), it looks like it does it correctly by default. I did some research here, and it looks like the default installations no longer use .emacs files, because there's folks like me that mess around with them and break things, and they got tired of having to help us fix it. But, there is a set of menus that will let you tweak things. Start by typing "M-x customize RET", where M is the meta character (on my OSX install, this is the esc key. Don't hold it down, just type it like a regular character. That'll get you into a menu of stuff you can change. I didn't poke around too much, so I'm not sure where in the menu you'll find what you're looking for. Sorry I couldn't be more help.
In my experience this is usually related to a unpaired quote (single-, double-, or otherwise) somewhere in an existing comment.
Hunt those occurences down and eradicate them in your source code (or if you are more ambitious, see if you can update the fontlock code in your major modes' emacs source code)
When I have encountered this in editting Perl in emacs, I often switch major modes to cperl-mode as it typically handles parsing the perl better than the default perl-mode.