How to map Emacs Evil keys to Dired Plus - emacs

I want to bind my h and l keys to diredp-up-directory-reuse-dir-buffer and diredp-find-file-reuse-dir-buffer respectively. I have the following code in my .emacs file:
(require 'dired+)
(toggle-diredp-find-file-reuse-dir 1)
(eval-after-load 'dired
'(evil-define-key 'normal dired-mode-map
(kbd "h") 'diredp-up-directory-reuse-dir-buffer
(kbd "l") 'diredp-find-file-reuse-dir-buffer)
)
But this is not working for me. There is no error message when I launch emacs. Can someone help me? Thanks.

It was a silly mistake. The Evil definitions with evil-define-key were being done before the (evil-mode 1) line.

Related

ido-completion-map keys not working when ergoemacs is enable

When using ergo emacs, for some reason M-l and M-j (forward-char and backward-char respectively) don't work properly in the minibuffer (with ido mode).
I've tried setting the ido-completion-map with the following:
(add-hook 'ido-setup-hook
(lambda ()
(define-key ido-completion-map (kbd "M-k") 'ido-next-match)
(define-key ido-completion-map (kbd "M-i") 'ido-prev-match)
(define-key ido-completion-map (kbd "M-l") 'ido-next-match)
(define-key ido-completion-map (kbd "M-j") 'ido-prev-match)))
but these don't seem to stick.
I seem to be having a similar problem to this person: ido-mode binding masked by global-set-key but none of the solutions seems to work for me
Any help would be very appreciated
Kind regards
Nimai
Although the instructions at the outset of ido.el suggest using:
;; Customization
;; -------------
;;
;; Customize the Ido group to change the Ido functionality.
;;
;; To modify the keybindings, use the ido-setup-hook. For example:
;;(add-hook 'ido-setup-hook 'ido-my-keys)
;;
;;(defun ido-my-keys ()
;; "Add my keybindings for ido."
;; (define-key ido-completion-map " " 'ido-next-match)
;; )
I recently found that using the ido-common-completion-map had better luck when using a frame-switch function -- the original poster can substitute his / her own preferred keyboard shortcuts instead of m-tab and/or m-S-tab:
(add-hook 'ido-setup-hook 'ido-my-keys)
(defun ido-my-keys ()
"Add my keybindings for ido."
(define-key ido-common-completion-map (kbd "<M-tab>") 'ido-next-match)
(define-key ido-common-completion-map (kbd "<M-S-tab>") 'ido-prev-match) )
I have met the save problem, i'm using Emacs 24.4 with ergoemacs-mode-5.14.7.3 (i don't use the latest version of ergoemacs because it has the speed issue. See: github issue). After a lot of searching, i finally find this github commit, and get it work by adding below code to my emacs init file:
after enable ergoemacs-mode:
(when ido-mode
(global-set-key [remap ido-magic-forward-char] 'ido-next-match)
(global-set-key [remap ido-magic-backward-char] 'ido-prev-match))
Hope it helps, thanks!

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.

Rebind emacs "C-d" to delete word

I have tried several different ways of doing this, and none have been successful. I want to switch the M-d and C-d functionality (delete word, delete char) respectively while working in c++ files.
Can someone please lend me a hand?
(add-hook 'c-initialization-hook
(lambda ()
(define-key c++-mode-map "\C-d" 'kill-word)
(define-key c++-mode-map "\M-d" 'c-electric-delete-forward)))
From CC Hooks - CC Mode Manulal:
Variable: c-initialization-hook
Hook run only once per Emacs session, when CC Mode is initialized. This is a good place to change key bindings (or add new ones) in any of the CC Mode key maps. See Sample .emacs File.
(eval-after-load "cc-mode"
'(progn
(define-key c++-mode-map (kbd "C-d") 'kill-word)
(define-key c++-mode-map (kbd "M-d") 'delete-char)))

Setting shortcuts keys in specific modes in Emacs (e.g. ido)

I have two problems which are somewhat related I believe:
1) In IDO I'd like to change ido-restrict-to-matches to samething else than C-SPC or C-#. Unfortunately I do not know how to tell emacs that I want a different shortcut (say C-0).
2) I'd like to protect my C-; but whenever flyspell-mode is running it overtakes C-;. My definition is in .emacs as:
(global-set-key (kbd "C-;") 'mark-paragraph)
but apparently flyspell overwrites this... (although even then, if I look in the help M-h k C-; it does say mark-paragraph)
Could somebody please tell me how to bind/unbind keys in these conditions? It has to work without modifying ido.el and flyspell.el and re-building, right?
Thanks very much!
Flyspell provides a customization for the C-; binding, so you can either M-x customize RET flyspell-auto-correct-binding RET or put something like this in your ~/.emacs:
(setq flyspell-auto-correct-binding (kbd "C-~")) ; or a binding of your choice
As for ido, your question is slightly confusing, because it implies there are times when you're using ido outside the minibuffer...
The documentation in ido.el contains the following advice:
;; To modify the keybindings, use the ido-setup-hook. For example:
;;(add-hook 'ido-setup-hook 'ido-my-keys)
;;
;;(defun ido-my-keys ()
;; "Add my keybindings for ido."
;; (define-key ido-completion-map " " 'ido-next-match)
;; )
Using that knowledge, you can change the key bindings like this in your own "ido-my-keys" function:
(define-key ido-completion-map (kbd "C-SPC") nil)
(define-key ido-completion-map (kbd "C-#") nil)
(define-key ido-completion-map (kbd "C-0") 'ido-restrict-to-matches)
There's an additional ido hook specifically for the minibuffer, too, but it's not clear why you would need that: ido-minibuffer-setup-hook.

How can I make C-p an Emacs prefix key for Devel::PerlySense?

I just installed Devel::PerlySense 0.0180.
I have put the following in my .emacs file:
; PerlySense
(load "~/perly-sense")
(global-unset-key "\C-p")
(global-set-key (kbd "\C-p \C-d") 'perly-sense-smart-docs-at-point)
(global-set-key (kbd "\C-p \C-g") 'perly-sense-smart-go-to-at-point)
But, now whenever I try to load a Perl file in emacs, I get the following error prior to it getting loaded:
error "Key sequence C-p m f starts
with non-prefix key C-p"
How can I fixed this? I'm new to emacs, so would really appreciate any help in this regard.
Update:
The link submitted by ysth suggests, doing the following :
(use-local-map (make-sparse-keymap))
=> nil
(local-set-key "\C-p" ctl-x-map)
=> nil
(key-binding "\C-p\C-f")
=> find-file
(key-binding "\C-p6")
=> nil
Now, do i need to add this to my .emacs file to create the keymap?
When i add the above code to .emacs and start emacs the error i get is :
void-variable =>
What can be the problem here ?
The explicit answer to your question is this:
(define-prefix-command 'perly-sense-map)
(global-set-key (kbd "C-p") 'perly-sense-map)
(define-key perly-sense-map (kbd "C-d") 'perly-sense-smart-docs-at-point)
(define-key perly-sense-map (kbd "C-g") 'perly-sense-smart-go-to-at-point)
For more information as to what's being done, check out documentation for
define-prefix-command
keymaps
kbd
In the original post, you mixed using kbd and the older "\C-p" notation. You can read this large tutorial discussing keybindings, which has tons of information (more than what you probably need). I find the kbd usage to be the easiest, you just pass it the string that you'd see when you do help on a key (C-h k).
Emacs, by default, only allows certain keys to be prefixes (the start of multi-key commands). See http://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Keys.html
You need to create a keymap and bind it to C-p.