Can I bind action to a keypress in Emacs? - emacs

I have (kbd "C-c S-<down>") and (kbd "C-c S-<up>") bound to shrink-window and enlarge-window, respectively.
It works, but I also want Emacs to change window size during a keypress, while I am holding S-<down> or S-<up>.
Is it possible in Emacs?

(define-key global-map [S-up] 'enlarge-window)
(define-key global-map [S-down] 'shrink-window)

Related

Emacs/Evil mode - how can I set TAB to cycle buffers?

I would like to configure my Emacs/Evil so that when in normal mode (i.e. after hitting ESC and navigating inside the file) then the TAB key switches to the next buffer, and Shift-TAB switches to the previous one. I tried this in my .emacs ...
(define-key evil-normal-state-map (kbd "\t") 'evil-next-buffer)
(define-key evil-normal-state-map (kbd "S-\t") 'evil-prev-buffer)
...but it didn't work.
Since that motion is muscle-memoried in my fingers, I'd appreciate any help on making this work.
You need to use <tab> to set a tab binding. Try these commands instead.
(define-key evil-normal-state-map (kbd "<tab>") 'evil-next-buffer)
(define-key evil-normal-state-map (kbd "<backtab>") 'evil-prev-buffer)

How to customize Emacs keyboard shortcut for deleting current line

I want the current line to be deleted when Alt, and the letter d is pressed twice.
How can I achieve this inside my Emacs configuration file?
Currently all I have is this in my .emacs:
(global-set-key (kbd "M-9") 'prev-window)
(global-set-key (kbd "M-0") 'other-window)
You can use your own keymap:
(defvar somename-map (make-sparse-keymap) "Keymap for M-d")
(define-key somename-map (kbd "M-d") 'kill-line)
(define-key somename-map (kbd "M-w") 'kill-word)
(global-set-key (kbd "M-d") somename-map)

Use TAB for expand and C-i for indent-relative in emacs

how can i use TAB for dexpand and still have C-i for indent-relative?
Im trying:
(global-set-key (kbd "TAB") 'dabbrev-expand)
(global-set-key "\C-i" 'indent-relative)
but it wont work, because both TAB and C-i are used for dabbrex-expand.
If you never use emacs in terminal then you can do the following
First separate C-i and tab by doing
(define-key key-translation-map [tab] [?\t])
(define-key key-translation-map [?\C-\i] [(control i-key)])
(define-key function-key-map [tab] nil)
(define-key function-key-map [?\t] nil)
Then you can bind commands to the keys as usual
(global-set-key (kbd "TAB") 'dabbrev-expand)
(global-set-key (kbd "<C-i-key>") 'indent-relative)
Credits: I picked this up from this comment by Fuco.

How to keep traditional binding on M-x in emacs evil mode

I am trying to bind execute-extended-command to M-x in evil normal mode.
I currently have
;; evil mode
(require 'evil)
(evil-mode 1)
(define-key evil-normal-state-map "M-x" 'execute-extended-command)
in my .emacs file but the keybinding doesn't work. I tried replacing
"M-x"
with
"\M-x"
and
(kbd "M-x")
but neither works. I also tried adding it to evil.el and evil-maps.el.
I don't know what's wrong with your binding. You could use Emacs' own global-set-key for global stuff and if you plan something special for say, insert mode, you could override that later on, like this:
;; this works, just tested. My evil is 1.0-dev from github.
(global-set-key (kbd "M-x") 'smex)
(define-key evil-insert-state-map (kbd "M-x") 'execute-extended-command)
Use (kdb "") macro when you have modifier keys in your binding. But you can use the macro always, regardless of the content. These are for example usage. When in doubt, wrap the key in (kdb ).
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;;(global-set-key (kbd "M-x") 'execute-extended-command)
(define-key evil-normal-state-map ",d" 'volatile-kill-buffer)
(define-key evil-normal-state-map ",b" 'ido-switch-buffer)
(define-key evil-normal-state-map ",s" 'ispell-word)
(define-key evil-normal-state-map (kbd "C-x g") 'magit-status)
(define-key evil-insert-state-map (kbd "C-f") 'my-expand-file-name-at-point)
(define-key evil-insert-state-map (kbd "C-x C-l") 'my-expand-lines)
(define-key minibuffer-local-map (kbd "C-w") 'backward-kill-word)
(define-key evil-normal-state-map (kbd ",ff") 'ido-find-file)
After long research and with help from #emacs and #evil-mode channels on irc, it turned out that my emacs was broken. It was a snapshot from http://emacs.naquadah.org/ I tried all this on another emacs version (from debian jessies repos) and it worked ok.

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