How to disable Meta-Cursor Shortcuds in markdown-mode? - emacs

I switch windows with M-left and M-right. Also Tab, S-Tab and C-Tab are hardwired into my spine. Since I use markdown-mode my workspeed has halved.
How do I disable that markdown-mode re-assigns those keys on loading. The keys I describe are carefully handcrafted shortcuts from my .emacs file, set via global-set-key.
(global-set-key [S-iso-lefttab] 'dabbrev-expand)
(global-set-key [C-tab] 'ispell-word)
(global-set-key [M-up] 'windmove-up)
(global-set-key [M-down] 'windmove-down)
(global-set-key [M-left] 'windmove-left)
(global-set-key [M-right] 'windmove-right)

Set those keys also in markdown-mode, in its keymap (probably markdown-mode-map). For example:
(define-key markdown-mode-map [C-tab] 'ispell-word)
The problem you saw comes from the fact that a local binding overrides a global one. See the Elisp manual, node Active Keymaps.

Related

Bind C-z in evil mode to escape to shell

In Emacs evil mode, the key combo C-z is to toggle evil mode. I would like to rebind it to escape to shell instead. How would I do this ?
I have read about eshell, it seems to be great, but for now I would like to work with my zsh shell first.
Multi term seems to designed for this job, but I think escaping to shell is fine for me, since I'm used to this flow in Vim.
Thanks for reading.
Perhaps what you need is C-x C-z.
Just have the same requirement, and here's my configurations:
(add-to-list 'load-path "~/.emacs.d/evil")
(add-to-list 'load-path "~/.emacs.d/evil/lib")
(setq evil-toggle-key ""); remove default evil-toggle-key C-z, manually setup later
(require 'evil)
(evil-mode 1)
;; remove all keybindings from insert-state keymap, use emacs-state when editing
(setcdr evil-insert-state-map nil)
;; ESC to switch back normal-state
(define-key evil-insert-state-map [escape] 'evil-normal-state)
Ref:
1. https://gist.github.com/kidd/1828878
2. https://askubuntu.com/questions/99160/how-to-remap-emacs-evil-mode-toggle-key-from-ctrl-z
C-x C-z will suspend the frame and return you to the shell.
C-z as you mention toggles evil mode on/off.
I swap their behavior in evil like so:
(define-key evil-motion-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-emacs-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-motion-state-map (kbd "C-x C-z") 'evil-emacs-state)
(define-key evil-emacs-state-map (kbd "C-x C-z") 'evil-exit-emacs-state)
See this commit for an example (where I also make C-z emulate vim-behavior in insert/replace mode).

emacs, flyspell, deactivate "C-." key binding

I have this little problem, I have some key bindings like so C-. C-x or C-. C-m. After I activate the flyspell-mode, I cannot use these commands. In my .emacs file I have the next 2 lines before
(global-unset-key (kbd "C-."))
(define-key (current-global-map) (kbd "C-.") nil)
(global-set-key (kbd "C-. C-l") 'global-linum-mode)
Then, my C-. C-l works, but it does not when the flyspell-mode is activated. The command bound to C-. is flyspell-auto-correct-word. I tried to deactivate it as follows:
;; first try
(defun flyspell-auto-correct-word-disable() (define-key (current-local-map) (kbd "C-.") nil))
(add-hook 'flyspell-mode-hook 'flyspell-auto-correct-word-disable)
;; second try
(define-key (current-global-map) [remap flyspell-auto-correct-word] nil)
None of the tries work, what can I do? I tried in Emacs 23 and 24 and I have the same issue.
What about:
(eval-after-load "flyspell"
'(define-key flyspell-mode-map (kbd "C-.") nil))
Your first solution is almost correct, but you have to remember that the current local map is set up by the major mode, not minor modes. The best option you have it to directly access flyspell-mode-map and modify it (another option would be to find it in minor-mode-map-alist but I think it would be needlessly complicated).
Also, I prefer putting such mode-specific settings within eval-after-load (which means they will be evaluated once) rather than in a hook (in which case the settings are evaluated multiple times: each time one buffer activates flyspell-mode). But this is a matter of preference and either way is fine.

Disable Mail in emacs 23

I am wondering if its possible to disable mail in emacs 23. Basically, I occasionally press C-xm and it annoys me that it will create a Mail folder in my home directory. (I also want to remap this to 'execute-extended command).
I have tried
(global-unset-key "\C-x m")
(global-set-key (kbd "C-c m") 'execute-extended-command)
but it doesn't seem to affect anything.
This will set the binding of C-xm to the execute-extended-command function:
(global-set-key "\C-xm" 'execute-extended-command)
or
(global-set-key [?\C-x ?m] 'execute-extended-command)
or
(global-set-key (kbd "C-x m") 'execute-extended-command)

Emacs: why does keybinding with M-S-[letter] set mark?

I'm experimenting with new bindings for basic movement in Emacs. Borrowing from this page and ErgoEmacs, this remapping works as expected:
(global-set-key (kbd "M-i") 'previous-line)
(global-set-key (kbd "M-k") 'next-line)
(global-set-key (kbd "M-j") 'backward-char)
(global-set-key (kbd "M-l") 'forward-char)
But defining a Shift-Alt combination gives an unwanted side-effect.
(global-set-key (kbd "M-I") 'cua-scroll-down)
(global-set-key (kbd "M-K") 'cua-scroll-up)
(global-set-key (kbd "M-J") 'backward-word)
(global-set-key (kbd "M-L") 'forward-word)
Running describe-key (C-h k) shows that the bindings were successful. And these bindings move point as they should, but for some reason it sets the mark at my original position, and gives me a highlighted region as I move the point.
How do I correct this?
EDIT:
This has something to do with cua-mode. When I disable cua-mode, the problem disappears. Unfortunately, disabling cua-mode is not a desirable solution.
EDIT:
This is a bug in Emacs. It's tracked as bug#11221, title 'cua-mode activates the mark for shifted bindings'. From the discussion on the mailing list, it sounds like there will be a fix to cua-base.el.
It's indeed likely triggered by shift-select-mode, but it looks like a bug: shift-select-mode should pay attention to the fact that the command is bound to a shifted key. Try to reproduce the problem without using CUA and then please report it with M-x report-emacs-bug.
That's because of the shift selection. You can disable it by setting shift-select-mode to nil.

Binding M-<up> / M-<down> in Emacs 23.1.1

I'm trying to put in a feature that I miss from Eclipse, where Alt+[Up/Down] transposes the lines up or down, but can not for the life of me figure out how to assign to these keys properly. I am using it in -nw mode (so just in a shell window), and typically run in a screen session.
Using a global key binding, I can get it to work with letter combinations, like (kbd "M-m"), but every combination I have tried for the arrow keys just gives me a message that doesn't make sense, I always get:
"ESC <up> is undefined"
What I have tried:
(global-set-key (kbd "M-<up>") 'transpose-line-up)
(global-set-key (kbd "<escape>-<up>") 'transpose-line-up)
(global-set-key [M-up] 'transpose-line-up)
(global-set-key [\e \M-O A] 'transpose-line-up)
And C-h c just returns:
ESC <up> (translated from ESC M-O A) is undefined
None of these work, either using ESC or Alt.
Any idea how I can make this work? I would prefer to have these as Alt+[Up/Down] just because that is what I am used to.
Edit
From the comments:
C-q Up prints ^[OA.
C-q M-Up prints ^[ and moves the cursor up a line.
C-h k (Alt+Up) prints ESC <up> (translated from ESC M-O A) is undefined.
Thanks for the suggestions, but they all turned out the same.
Emacs has a complex mechanism to handle the vicissitudes of function key and modifier encodings on various terminal types. It doesn't work out of the box in all cases. The following settings should work on your terminal:
(define-key input-decode-map "\e\eOA" [(meta up)])
(define-key input-decode-map "\e\eOB" [(meta down)])
(global-set-key [(meta up)] 'transpose-line-up)
(global-set-key [(meta down)] 'transpose-line-down)
You should be able to use (kbd "<M-up>") and (kbd "<M-down>") in place of [(meta up)] and [(meta down)], as long as you've done the step of telling Emacs (via input-decode-map) about the escape sequences that your terminal uses to encode these key combinations.
I always use C-h k (key) (i.e. describe-key) to find out how Emacs refers to (key), and then use (kbd) with that same string to utilise it.
In this case, describe-key returns <M-up>, so I would use (global-set-key (kbd "<M-up>") 'transpose-line-up) (exactly as J.F. Sebastian has done).
Edit:
Running emacs -nw (but not through screen), describe-key reports ESC <up> (translated from ESC M-[ A), and (kbd "ESC <up>") is successful for binding it.
Running screen emacs -nw, describe-key reports ESC <up> (translated from ESC M-O A), which seems to match what you see, and the binding for (kbd "ESC <up>") still works for me.
(n.b. Tested under Cygwin with screen 4.00.03, and Emacs 23.2.1.)
(global-set-key [M-up] 'beginning-of-buffer)
(global-set-key [M-down] 'end-of-buffer)
In my OSX, I have this definition to perform Alt-up/down to jump to top/bottom of buffer.
ugly workaround:
I've typed C-q <M-up> it produced ^[[1;3A on the terminal inside screen inside emacs.
(global-set-key (kbd "<M-up>") 'transpose-line-up)
(global-set-key (kbd "^[[1;3A") 'transpose-line-up)
I've got Lisp error: (void-function transpose-line-up) so the key bindings work.
Note: C-q runs the command quoted-insert.
The following lines work for me on macOS 10.11.6 and GNU Emacs 25.2.1:
(global-set-key (kbd "ESC <down>") 'end-of-buffer)
(global-set-key (kbd "ESC <up>") 'beginning-of-buffer)
Assuming you have the functions transpose-line-up and transpose-line-down already defined (as it seems to be from the example code in your original question):
(global-set-key [(meta up)] 'transpose-line-up)
(global-set-key [(meta down)] 'transpose-line-down)
works on OSX Terminal:
(global-set-key (kbd "ESC <up>") 'transpose-line-up)
(global-set-key (kbd "ESC <down>") 'transpose-line-down)