Key Bindings Not Working? How to Configure - emacs

I'm using Emacs 24. and Octave 3.6.3 on Linux Mint Maya
I have set-up my init file, and all works fine. M-x run-octave gives me inferior octave, and .m files open automatically in octave mode.
But I can't seem to get key bindings to work? When I'm in octave mode, I press
'Ctrl' and 'c' together, then I press 'i', and emacs tells me that C-c i is undefined?
Could someone please help? I just want to send lines easily

It is better to look in the source file. Here is how shortcuts are defined for the octave mode:
(defvar octave-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "`" 'octave-abbrev-start)
(define-key map "\e\n" 'octave-indent-new-comment-line)
(define-key map "\M-\C-q" 'octave-indent-defun)
(define-key map "\C-c\C-b" 'octave-submit-bug-report)
(define-key map "\C-c\C-p" 'octave-previous-code-line)
(define-key map "\C-c\C-n" 'octave-next-code-line)
(define-key map "\C-c\C-a" 'octave-beginning-of-line)
(define-key map "\C-c\C-e" 'octave-end-of-line)
(define-key map [remap down-list] 'smie-down-list)
(define-key map "\C-c\M-\C-h" 'octave-mark-block)
(define-key map "\C-c]" 'smie-close-block)
(define-key map "\C-c/" 'smie-close-block)
(define-key map "\C-c\C-f" 'octave-insert-defun)
;; FIXME: free C-h so it can do the describe-prefix-bindings.
(define-key map "\C-c\C-h" 'info-lookup-symbol)
(define-key map "\C-c\C-il" 'octave-send-line)
(define-key map "\C-c\C-ib" 'octave-send-block)
(define-key map "\C-c\C-if" 'octave-send-defun)
(define-key map "\C-c\C-ir" 'octave-send-region)
(define-key map "\C-c\C-is" 'octave-show-process-buffer)
(define-key map "\C-c\C-ih" 'octave-hide-process-buffer)
(define-key map "\C-c\C-ik" 'octave-kill-process)
(define-key map "\C-c\C-i\C-l" 'octave-send-line)
(define-key map "\C-c\C-i\C-b" 'octave-send-block)
(define-key map "\C-c\C-i\C-f" 'octave-send-defun)
(define-key map "\C-c\C-i\C-r" 'octave-send-region)
(define-key map "\C-c\C-i\C-s" 'octave-show-process-buffer)
;; FIXME: free C-h so it can do the describe-prefix-bindings.
(define-key map "\C-c\C-i\C-h" 'octave-hide-process-buffer)
(define-key map "\C-c\C-i\C-k" 'octave-kill-process)
map)
"Keymap used in Octave mode.")
As you can see, you have to use C-c C-i l to send a line

I think the documentation you read for octave-mode is outdated. You probably need to use C-c C-i as a prefix instead of C-c i. To have a full command you need to type another character, for example r or C-r to send the region.
This change was most likely done to conform with emacs specifications. Emacs reserves the keys in C-c <char> where <char> is any one character for the user. Therefore octave-mode should not have use such a key in the first place.

disable some minor mode,maybe has some code defined likes(define-key xx-map "\C-c i" nill) and effected by mode-hook

Related

Emacs evil: general window movement remap

This is the question I should have asked instead of this:
Emacs evil: space as a prefix key in motion state
I want to define a bunch of commands for moving, moving between, opening and closing windows and buffers that works in all states except insert mode, and are all of the form "SPC ". It would be nice to be able to set this once and be fine everywhere (except when there are conflicts, though overriding would be fine), but if that isn't easy, I would also like to know how to override keybindings in new states that I run across where my keybindings don't work. Hopefully knowing that would also help me edit keybindings in arbitrary states.
What I currently have is this:
(define-key evil-normal-state-map (kbd "SPC") nil)
(define-key evil-motion-state-map (kbd "SPC") nil)
(define-key evil-motion-state-map (kbd "SPC h") 'evil-window-left)
(define-key evil-motion-state-map (kbd "SPC j") 'evil-window-down)
(define-key evil-motion-state-map (kbd "SPC k") 'evil-window-up)
(define-key evil-motion-state-map (kbd "SPC l") 'evil-window-right)
(define-key evil-normal-state-map (kbd "SPC h") 'evil-window-left)
(define-key evil-normal-state-map (kbd "SPC j") 'evil-window-down)
(define-key evil-normal-state-map (kbd "SPC k") 'evil-window-up)
(define-key evil-normal-state-map (kbd "SPC l") 'evil-window-right)
and "SPC H" and so on for moving windows. It doesn't work in list-buffers or Dired. Evil leader only seems to work for normal mode.
We meet again.
Perhaps it'd be simpler to define a prefix keymap and bind to it. For example:
(define-prefix-command 'my-window-map)
(let ((map my-window-map))
(define-key map "h" 'evil-window-left)
(define-key map "j" 'evil-window-down)
(define-key map "k" 'evil-window-up)
(define-key map "l" 'evil-window-right)
(define-key map "H" 'evil-window-move-far-left)
(define-key map "J" 'evil-window-move-very-bottom)
(define-key map "K" 'evil-window-move-very-top)
(define-key map "L" 'evil-window-move-far-right)
;; And presumably, for opening/closing
(define-key map "v" 'evil-window-vsplit)
(define-key map "s" 'evil-window-split)
(define-key map "c" 'evil-window-delete))
Then you can map the prefix keymap to SPC in various modes:
;; Do this for each state you want these bindings available
(define-key evil-motion-state-map " " 'my-window-map)
(define-key evil-visual-state-map " " 'my-window-map)
;; You don't need to unbind/rebind evil-normal-state-map --
;; there is no default mapping for " ". Also: unbound keys in normal
;; mode will fall through to motion bindings.
;; For particular modes (like dired and list-buffer window)
(define-key dired-mode-map " " 'my-window-map)
(define-key Buffer-menu-mode-map " " 'my-window-map)
Alternatively, you can have dired and list-buffer start in normal mode. This will likely interfere with their default mappings.
(evil-set-initial-state 'dired-mode 'normal)
(evil-set-initial-state 'Buffer-menu-mode 'normal)
If you find your mapping overridden by another mode (which shouldn't be common for that key), you can try adding my-window-map to evil-overriding-maps: (add-to-list 'evil-overriding-maps '(my-window-map)). This supposedly gives those maps precedence.
Disclaimer: I haven't tested this. I find it simpler to undefine keys in conflicting plugins.
On a side note, all these commands are already available in evil-window-map. It may be simpler for you to map SPC to that:
(define-key evil-motion-state-map " " 'evil-window-map)
(define-key evil-visual-state-map " " 'evil-window-map)
...

How do I scroll through the autocomplete options in emacs-jedi (besides arrow keys)

Up and down arrow keys work but I was wondering if there was another option on the home row. If not, how do I set it to something else? (emacs noob)
emacs-jedi uses auto-complete under the hood
These are also supported (besides the default arrows):
M-n Next item
M-p Previous item
If you wanted to change them you could do something like this:
(define-key ac-completing-map (kbd "C-c j") 'ac-next)
(define-key ac-completing-map (kbd "C-c k") 'ac-previous)

Emacs keys to move in pop ups of auto-complete

I am setting my Emacs for cpp development.
I have set up auto-complete and yasnippets and it is great.
But every time one of pop up comes, i have to reach the mouse to click the lowest or middle one..
It must be possible with keys too but i struggled to find one.
I found this article keys-for-pop-up but i think he is speaking about auto-completing without asking the user or showing no pops.
For anyone reading this, to move up or down in the auto-complete popup:
Move down: M-n
Move up: M-p
Here's the complete mode map from auto-complete.el
(define-key map "\t" 'ac-expand)
(define-key map [tab] 'ac-expand)
(define-key map "\r" 'ac-complete)
(define-key map [return] 'ac-complete)
(define-key map (kbd "M-TAB") 'auto-complete)
(define-key map "\M-n" 'ac-next)
(define-key map "\M-p" 'ac-previous)
(define-key map [down] 'ac-next)
(define-key map [up] 'ac-previous)
(define-key map [f1] 'ac-help)
(define-key map [M-f1] 'ac-persist-help)
(define-key map (kbd "C-?") 'ac-help)
(define-key map (kbd "C-M-?") 'ac-persist-help)
(define-key map [C-down] 'ac-quick-help-scroll-down)
(define-key map [C-up] 'ac-quick-help-scroll-up)
(define-key map "\C-\M-n" 'ac-quick-help-scroll-down)
(define-key map "\C-\M-p" 'ac-quick-help-scroll-up)

Emacs multi keyboard shortcut

I'm trying to create a combination keybinding.
Here's an example:
(define-key my-minor-mode-map (kbd "x f") "\C-x\C-f")
(edit: Thanks you Stefan for pointing out the space between \C-x and \C-f.)
This however takes me to a random file and describe-key says this:
Macro: C-x C-f
Keyboard macro.
So I'm not really sure what that means.
It seems that trying to bind s to C-s doesn't work either (As well as other interactive commands like C-r and M-x).
This does work:
(define-key my-minor-mode-map (kbd "x f") "\M-f")
So basically I want to be able to run C-x C-f (find-file) without having to type 'find-file as a function itself.
In other words; I don't want this:
(define-key my-minor-mode-map (kbd "x f") 'find-file)
I hope someone could help me out with this. My emacs knowledge is very limited.
Thanks in advance.
Complete code:
(defvar my-minor-mode-map (make-keymap) "my-minor-mode keymap")
(define-key my-minor-mode-map (kbd "x f") "\C-x\C-f")
(define-minor-mode my-minor-mode
"My minor-mode"
t "My minor mode" 'my-minor-mode-map)
(defun my-minibuffer-setup-hook ()
(my-minor-mode 0))
"My minor-mode"
Edit:
What would even be better is if I could do this:
(define-key my-minor-mode-map (kbd "x") "\C-x")
(define-key my-minor-mode-map (kbd "f") "\C-f")
And then if I would type "x f" that it would exectue "\C-x C-f" aka find file.
That way I wouldn't have to write out every possible key combination.
"\C-x \C-f" has 3 elements: C-x, SPC, and C-f. You probably did not mean for that space to be there.
I'm not entirely certain what you believe should be happening here, but I suspect what you actually want is:
(define-key my-minor-mode-map (kbd "x f") (key-binding (kbd "C-x C-f")))
which is the same thing as the code you said you didn't want to use:
(define-key my-minor-mode-map (kbd "x f") 'find-file)
except that it obtains the function dynamically, based on the key binding.
p.s. It's also slightly odd that you're using a mixture of kbd and non-kbd syntax in the same form.

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