How to unbind "M-1" and "M-2" in Emacs ansi-term - emacs

I use tabbar in emacs, and bind following key.
(global-set-key (kbd "M-2") 'tabbar-forward-tab)
(global-set-key (kbd "M-1") 'tabbar-backward-tab)
But, those key-binds don't work in ansi-term mode. When I type 'M-1', it do not run tabbar-backward-tab, the key is captured by bash.
[xx#local ~]$
(arg: 1)
How to unbind "M-1" and "M-2" in Emacs ansi-term?

In term-char-mode M-<n> sequences are bound to term-send-raw (as are most sequences which a terminal would normally handle).
To unbind them, you can use:
(eval-after-load "term"
'(progn
(define-key term-raw-map (kbd "M-1") nil)
(define-key term-raw-map (kbd "M-2") nil)))
That will stop them from shadowing the global bindings.

Related

How to disable local key binding in octave-mode?

Here is my key binding.
I want to set C-h to delete-backward-char in all modes, but in octave mode, when I pressed C-h, it shows C-h (Type ? for further options)-. So I add the last 3 lines in my .emacs file, but it doesn't work. C-h still works as the help function.
(global-set-key (kbd "C-?") 'help-command)
(global-set-key (kbd "C-h") 'delete-backward-char)
(define-key octave-mode-map (kbd "C-h") nil)
(define-key octave-mode-map (kbd "C-h a") nil)
(define-key octave-mode-map (kbd "C-h d") nil)
octave.el appears to set those bindings in three different keymaps:
octave-mode-map
inferior-octave-mode-map
octave-help-mode-map
You might also refer to Globally override key binding in Emacs

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).

How can I unbind C-tab from jedi:complete?

With jedi-mode enabled, the C-tab is bound to jedi:complete.
How can I unbind it so that I can then bind it back to other-window?
I've tried:
(global-set-key (kbd "C-`") 'jedi:complete)
(global-set-key [C-tab] 'other-window)
(global-unset-key (kbd "<C-tab>"))
(defcustom jedi:key-complete (kbd "C-`")
"Keybind for command `jedi:complete'."
:group 'jedi)
None of them is getting me the desired results.
You can use:
(define-key jedi-mode-map (kbd "<C-tab>") nil)
None of the commands with global in them will work, since minor mode key bindings
have priority over global key bindings.

emacs -nw issues with cscope and terminals

Few issues with emacs in term windows. Any help is appreciated.
a. I start emacs over ssh with emacs -nw with cscope enabled. After I search for a symbol or a definition, on the cscope buffer when i press 'enter', emacs says - Buffer is read-only. Whereas the same functionality on emacs with xwindows (gtk or anything else) takes me to the file and line on edit buffer. How can I have the same functionality with 'emacs -nw'.
b. Also the arrow mark on edit/source buffer when i do next reference for symbol from cscope buffer stays on the edit buffer. How can I make it go?
c. My keys are mapped to cscope functions just like in xcscope.el. All the control keys expect Ctrl-F3 and Ctrl-F4 work. How can I enable this too.
Thanks much,
a. Add the following to your .emacs file:
(define-key global-map (kbd "\r") [return])
I got the answer from http://weenix.cs.brown.edu/mediawiki/index.php/Cscope
b. If you hit the space bar in the cscope buffer, you will get the arrow. It's just a display thing; the file has not changed. If you want to get rid of it, add the following to your .emacs file:
(setq cscope-allow-arrow-overlays nil)
terminal send different key sequences than emacs may be expecting. you need to provide translations for the terminal type in order to get emacs to work correctly. for example, i have this config to setup the terminal i use (the weird char is a literal "escape" char, which you can type in using "C-q <esc>":
(let ((map (if (boundp 'input-decode-map)
input-decode-map function-key-map)))
(define-key map (kbd "RET") [return])
(define-key map "[OA" (kbd "<C-up>"))
(define-key map "[OB" (kbd "<C-down>"))
(define-key map "[OC" (kbd "<C-right>"))
(define-key map "[OD" (kbd "<C-left>"))
(define-key map "[A" (kbd "<C-up>"))
(define-key map "[B" (kbd "<C-down>"))
(define-key map "[C" (kbd "<C-right>"))
(define-key map "[D" (kbd "<C-left>"))
(define-key map "OA" (kbd "<M-up>"))
(define-key map "OB" (kbd "<M-down>"))
(define-key map "OC" (kbd "<M-right>"))
(define-key map "OD" (kbd "<M-left>"))
(define-key map "[OA" (kbd "<M-C-up>"))
(define-key map "[OB" (kbd "<M-C-down>"))
(define-key map "[OC" (kbd "<M-C-right>"))
(define-key map "[OD" (kbd "<M-C-left>"))
(define-key map "[[17~" (kbd "<C-f6>"))
(define-key map "[[18~" (kbd "<C-f7>"))
(define-key map "[[19~" (kbd "<C-f8>"))
(define-key map "[[20~" (kbd "<C-f9>"))
(define-key map "[[21~" (kbd "<C-f10>"))
(define-key map "[[23~" (kbd "<C-f11>"))
(define-key map "[[24~" (kbd "<C-f12>"))
(define-key map "\e[1~" [home])
(define-key map "\e[4~" [end])
(define-key map "\e\e[1~" [M-home])
(define-key map "\e\e[4~" [M-end])
)
in some terminals, you can get the key code by typing "C-v" and then the desired keys. this should output the actual keycodes that the terminal sends for the keys you pressed after the "C-v".

Useful keyboard shortcuts and tips for ESS/R

I would like to ask regular ESS/R users what key bindings do they use frequently and tips on using ESS/R.
I have set several shortcuts in my .emacs file. The most useful are:
C-tab to switch between the R command line and the file (similar to josh answer, but much faster):
(global-set-key [C-tab] 'other-window)
Control and up/down arrow keys to search history with matching what you've already typed:
(define-key comint-mode-map [C-up] 'comint-previous-matching-input-from-input)
(define-key comint-mode-map [C-down] 'comint-next-matching-input-from-input)
Comment-uncomment a selected region with C-d or C-maj-d
(defun uncomment-region (beg end)
"Like `comment-region' invoked with a C-u prefix arg."
(interactive "r")
(comment-region beg end -1))
(define-key ess-mode-map (kbd "C-d") 'comment-region)
(define-key ess-mode-map (kbd "C-S-d") 'uncomment-region)
Also I've also enabled CUA mode (from options menu) and reconfigured quite a lot of shortcuts to require only two keystrokes (instead of four in standard mode):
;; Delete selection when pressing [delete] key
(delete-selection-mode t)
;; ESS Mode (.R file)
(define-key ess-mode-map "\C-l" 'ess-eval-line-and-step)
(define-key ess-mode-map "\C-p" 'ess-eval-function-or-paragraph-and-step)
(define-key ess-mode-map "\C-r" 'ess-eval-region)
;; iESS Mode (R console)
(define-key inferior-ess-mode-map "\C-u" 'comint-kill-input)
(define-key inferior-ess-mode-map "\C-w" 'backward-kill-word)
(define-key inferior-ess-mode-map "\C-a" 'comint-bol)
(define-key inferior-ess-mode-map [home] 'comint-bol)
;; Comint Mode (R console as well)
(define-key comint-mode-map "\C-e" 'comint-show-maximum-output)
(define-key comint-mode-map "\C-r" 'comint-show-output)
(define-key comint-mode-map "\C-o" 'comint-kill-output)
;; Search with C-f / C-F (control-maj-F for backware search)
(global-set-key "\C-f" 'isearch-forward)
(global-set-key (kbd "C-S-f") 'isearch-backward)
(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)
(define-key isearch-mode-map (kbd "C-S-f") 'isearch-repeat-backward)
;; Save with C-s / C-S
(global-set-key (kbd "C-s") 'save-buffer)
(global-set-key (kbd "C-S-s") 'write-file)
;; need to redefine them for isearch mode (don't know why)
(define-key isearch-mode-map (kbd "C-s") 'save-buffer)
(define-key isearch-mode-map (kbd "C-S-s") 'write-file)
;; Pause = dedicate window.
(defun toggle-current-window-dedication ()
(interactive)
(let* ((window (selected-window))
(dedicated (window-dedicated-p window)))
(set-window-dedicated-p window (not dedicated))
(message "Window %sdedicated to %s"
(if dedicated "no longer " "")
(buffer-name))))
(global-set-key [pause] 'toggle-current-window-dedication)
;; delete = delete
(global-set-key [delete] 'delete-char)
;; C-b = list buffers
(global-set-key (kbd "C-b") 'bs-show)
You will find many more useful shortcuts in ESS documentation.
C-c C-z ess-switch-to-end-of-ESS
is nice to jump from your source file that you are editing foo.R to the R console
I found this link to be extremely helpful. It provides elisp code to make Shift+Enter do many common tasks in a context dependent fashion.
http://kieranhealy.org/blog/archives/2009/10/12/make-shift-enter-do-a-lot-in-ess/
Great stuff, have been using it for ages. Unfortunately as of 15-11-2013 the uncomment key binding may not work due to EMACS changes (I think, at least it was working before I loaded the latest version). This is because the default uncomment function has 3 arguments but the one defined above has 2. The best way to fix this is to simply delete the uncomment function from the code and retain the keybinding, so it uses the default uncomment function. Or in other words just use this:
(define-key ess-mode-map (kbd "C-d") 'comment-region)
(define-key ess-mode-map (kbd "C-S-d") 'uncomment-region)
M-n and M-p in the ESS R console for next/previous command.