Spacemacs evil-insert at start of line? (Emacs Evil Mode) - emacs

I finally got this to work, but wanted to know if there was an easier way.
I want to bind a key "U" to put spacemacs into insert-mode, but at the start of the text of the line.
(define-key evil-normal-state-map "u" 'evil-insert)
(define-key evil-normal-state-map "U" (lambda ()
(interactive)
(beginning-of-line-text)
(execute-kbd-macro "u")))
Is there an 'evil command to insert mode at start of line? Or a more elegant way to fire 'evil-insert or run multiple commands?

In evil-mode i executes evil-insert and I executes evil-insert-line.
So the simplest rebinding would be:
(define-key evil-normal-state-map "u" 'evil-insert)
(define-key evil-normal-state-map "U" 'evil-insert-line)
Whenever you want to know which keys run which functions just press C-h k and then the keybinding of choice.

Related

how to make emacs ido not rotate the whole list of options?

In emacs ido options, the currently selected option is always shown first in the list. When we change e.g. by arrow keys, or C-s / C-r : the whole list is rotated instead of currently selected option moving anywhere. This is very disconcerting for me. To illustrate , assume A, B, C and D are buffers are we are running ido-switch-buffer
Current behaviour
*A* B C D
Press C-s
*B* C D A
Again press C-s
*C* D A B
What I want is
*A* B C D
Press C-s
A *B* C D
Again press C-s
A B *C* D
I tried setting both "ido-rotate" , and "ido-rotate-file-list-default" to nil as well as t, one by one, but nothing changes in this regard. I don't see any other option in customize-group for ido either. How can I make the selected option move instead of the whole list rotating ?
This is for emacs 26.1, built-in ido.
Edit :
With the regular ido mode, I could override the next, previous key-bindings in the following manner :
(define-key ido-buffer-completion-map (kbd "M-)") 'ido-next-match)
With ido-grid-mode, all my attempts to do so are failing. It seems to insist on the hard-coded sets of keys to find next option / previous option.
This is also not working :
(define-key ido-completion-map (kbd "M-)") 'ido-next-match)
Any hints I could make ido-grid-mode let me override keys ?
Ok, found the answer. The package ido-grid-mode is indeed what i need, thanks #jpkotta. There is a trick to getting my keybinding work with it.
(defun ido-my-keys ()
"Add my keybindings for Ido."
(define-key ido-completion-map (kbd "M-)") 'ido-next-match)
(define-key ido-completion-map (kbd "M-)") 'ido-prev-match)
)
(ido-grid-mode t)
(add-hook 'ido-setup-hook 'ido-my-keys)
That is to say - ido-grid-mode has to be started before setup hook is added for key bindings. I was doing it after, or completely outside the setup hook, which was not working.
EDIT : Forgot to mention, there is another trick. Hack the ido-grid-mode itself. Make the following change in ido-grid-mode.el :
;; ('C-s (define-key ido-completion-map (kbd "C-s") #'ido-grid-mode-next))
;; ('C-r (define-key ido-completion-map (kbd "C-r") #'ido-grid-mode-previous))
('C-s (define-key ido-completion-map (kbd "M-)") #'ido-grid-mode-next))
('C-r (define-key ido-completion-map (kbd "M-(") #'ido-grid-mode-previous))

Cannot use cscope key-binding on Emacs due to syntactic analysis

I have a problem with using cscope on Emacs.
When I pressed "C-c C-s {g,s,..}" to use cscope, the key binding is blocked by syntactic analysis from CC mode.
The message printed out like(When I press C-c C-s) :
Syntactic analysis: ((topmost-intro 6123))
I want to use original cscope keybindings... is there any solutions for this issue?
; using cscope
(define-key global-map "\C-\\" nil)
(define-key global-map "\C-\\s" 'cscope-find-this-symbol)
(define-key global-map "\C-\\g" 'cscope-find-global-definition)
(define-key global-map "\C-\\a" 'cscope-index-file)
I tried to find out the solution to disable syntactic analysis shortcuts(C-c C-s) from CC mode, I couldn't find it. Instead, by using other keybindings, I could solve the problem.

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

Key Bindings Not Working? How to Configure

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

Shift arrow selection in emacs

I'm using GNU Emacs 23.2.1
my init.el
(cua-mode 1)
(transient-mark-mode 1)
(setq shift-select-mode t)
(global-linum-mode 1)
(show-paren-mode 1)
(desktop-save-mode 1)
So, instead of selection I get 2C on Shift =>, 2D on Shift <=, etc.
How to solve this?
P.S.
cat -v for Shift <=
^[[1;2D
cat -v for Shift =>
^[[1;2C
How I can map properly those keys to shift-left, shift-right corresponding?
P.P.S.
Sorry. I've forgot. I'm also using screen.
den#playground:~/.emacs.den$ echo $TERM
screen
Solution:
(define-key input-decode-map "\e[1;2D" [S-left])
(define-key input-decode-map "\e[1;2C" [S-right])
(define-key input-decode-map "\e[1;2B" [S-down])
(define-key input-decode-map "\e[1;2A" [S-up])
(define-key input-decode-map "\e[1;2F" [S-end])
(define-key input-decode-map "\e[1;2H" [S-home])
This means emacs and your terminal do not agree on what the various key codes mean. there are more advanced ways to configure terminals (terminal specific files), but to get you started, try adding something like this to your emacs init file:
(define-key input-decode-map "\e[1;2D" [S-left])
(define-key input-decode-map "\e[1;2C" [S-right])
This usually happens when you run emacs in a console. Try running emacs as a graphical program and this should not be an issue.