1

How to set it?

I tried

(add-hook 'ido-setup-hook
          (lambda ()
            (local-set-key (kbd "C-<RET>") 'ido-select-text)))

and

(define-key ido-common-completion-map (kbd "C-<RET>") 'ido-select-text)

Nothing worked.

EDIT:

I tried

(define-key ido-file-dir-completion-map (kbd "<C-return>") 'ido-select-text)

and

(define-key ido-common-completion-map (kbd "<C-return>") 'ido-select-text)

Not works again.

EDIT2:

Ultimatelly strange, even this not works.

(global-set-key  (kbd "<C-return>") 'ido-select-text) 

What's going on??? Actually, cua-select-rectangle is invoked regardles of my binding.

My emacs version GNU Emacs 24.5.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.18.9)\n of 2016-04-11 on buildvm-25.phx2.fedoraproject.org Using in GUI mode and CUA mode.

C-h k C-<return>

Returns (in standard buffer and IDO buffer)

<C-return> runs the command cua-set-rectangle-mark, which is an
interactive autoloaded compiled Lisp function in `cua-rect.el'.

It is bound to <C-return>.

(cua-set-rectangle-mark &optional REOPEN)

Set mark and start in CUA rectangle mode.
With prefix argument, activate previous rectangle if possible.
dev1223
  • 241
  • 1
  • 10
  • Your last expression works for me. – npostavs Dec 02 '17 at 01:44
  • what emacs version you have ? I have 24.5 and last expression definitelly not works for me. – dev1223 Dec 02 '17 at 13:45
  • I was using 26, but I tried again now in 24.5 and it works there too. – npostavs Dec 02 '17 at 14:57
  • 2
    I still don't have 50rep needed to comment on the thread for Seraph's problems. I've played around with this, and I noticed C-return in a terminal does not work whereas it does in a gui. 1. Please respond with the output of "M-x emacs-version", and whether you are running in a terminal or as a gui. 2. Please run "C-h k C-return" to check whether the key combination works in your setup. 3. Please enter an ido-mode context and run "C-h k C-return" – Realraptor Dec 02 '17 at 17:07
  • Thank you raptor. Im using emacs 24.5 in gui mode. Currently, Im not around my machine, so I will answer in more details tomorrow. – dev1223 Dec 02 '17 at 22:07
  • Realraptor, I updated question with answers which you requested. – dev1223 Dec 03 '17 at 15:20
  • 2
    In my experiments, the cua-global-map setting overrides the ido-common-completion-map setting. Removing the cua-global-map setting with (define-key cua-global-keymap (kbd "") nil) works for me. – Realraptor Dec 03 '17 at 16:53
  • Realraptor thats really interesting, gotta try that – dev1223 Dec 03 '17 at 17:14
  • Yes, it works, you are my hero, raptor :) – dev1223 Dec 03 '17 at 18:52

2 Answers2

1

Not familiar with ido, but define-key appears to be something close to what you want. The following worked as a proof-of-concept for me:

(define-key ido-common-completion-map (kbd "C-j") (lambda() 
    (interactive) (message "C-j called")))

If this isn't exactly right, change the keymap to another value listed at https://github.com/emacs-mirror/emacs/blob/1ed8ff2aa9e1aaee54a6cad38f4c9a595d6c19ed/lisp/ido.el#L206

Realraptor
  • 1,253
  • 6
  • 17
  • Actually, IDO is part of emacs, so I can not simply take its sources and modify it to make it work exactly as I want (I did this with paredit), what can I do with this? – dev1223 Dec 01 '17 at 22:51
  • Emacs lisp is generally dynamically scoped. This means that you can put my define expression into your init files (typically, your .emacs file) and change the behaviour of your emacs on startup. – Realraptor Dec 02 '17 at 17:00
  • 1
    That's not what is usually meant by ["dynamically scoped"](https://www.gnu.org/software/emacs/manual/html_node/elisp/Variable-Scoping.html). I think you mean somthing like [ImageBasedLanguage](http://wiki.c2.com/?ImageBasedLanguage) – npostavs Dec 03 '17 at 13:21
1

Solution for this problem is following, first null CUA map bind because it overrides everything and then bind <C-return> normally to IDO map.

(define-key cua-global-keymap (kbd "<C-return>") nil)  
(define-key ido-file-dir-completion-map (kbd "<C-return>") 'ido-select-text) 

Again, thank you Realraptor for this solution.

EDIT: Previous solution works only one time after set, so its not usable, this solution works well:

(defvar custom-ido-map
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "<C-return>") 'ido-select-text)
      ;; (define-key map (kbd "<M-return>") 'ido-magic-forward-char)
      map))
  (with-eval-after-load 'ido
    (define-key ido-common-completion-map (kbd "<C-return>") 'ido-select-text)
    ;; (define-key ido-common-completion-map (kbd "<M-return>") 'ido-magic-forward-char)
    )
  (add-to-ordered-list 'emulation-mode-map-alists
                       `((cua-mode . ,custom-ido-map))
                       0)

For more info how and why it works, visit linked answer in comment thread.

dev1223
  • 241
  • 1
  • 10
  • Just linking the followup question by @Realraptor here for posterity: https://emacs.stackexchange.com/q/37277/15748 – Basil Dec 03 '17 at 19:31