Bind File -> Open File with GUI dialog to C-o as global-set-key
Asked Answered
P

2

5

I want to bind GUI dialog File -> Open File to Ctrl + o

I can (global-set-key (kbd "C-o") 'find-file) but I want it exactly with gui.

How can I do it?

Prudenceprudent answered 21/10, 2014 at 9:59 Comment(5)
After a bit of looking around, this seems to be a duplicate of #391102 [-]Lovegrass
@MrBones it's still being not clear how to invoke it there...Prudenceprudent
See the answer - I've put the two things together for you.Lovegrass
@MrBones so far I'm still on command line :(Prudenceprudent
I would strongly suggest using GUI emacs instead of running it in a console. Also, I doubt console emacs will open dialogues in X (or whatever) for you. Otherwise, learn dired-mode - C-x d.Lovegrass
L
6

File -> Open File is just a GUI binding to find-file.

By binding it to "C-o", you can then open a file using "C-o". However, this will only bring up the standard find-file interface, which uses the echo area.

In order to also get a GUI dialogue box, you need to get emacs to think that find-file has been clicked, rather than invoked by keyboard. The solution to that can be found in Emacs M-x commands for invoking "GUI-style" menus.

Putting the two together (i.e. put them in your .emacs file and evaluate them):

(global-set-key (kbd "C-o") 'find-file)

(defadvice find-file-read-args (around find-file-read-args-always-use-dialog-box act)
  "Simulate invoking menu item as if by the mouse; see `use-dialog-box'."
  (let ((last-nonmenu-event nil))
     ad-do-it))

Note, C-o is already bound to open-line - which will 'insert a newline and leave point before it`.

Lovegrass answered 21/10, 2014 at 10:14 Comment(1)
They're not used in emacs. Not by default anyway - modal dialogues are not how emacs does things. You may want to take a look at dired (C-x d) which may get you what you want.Lovegrass
S
1

Following the comment by @squidy, here is the complete answer to what the OP asks (tested on emacs 24.3.1):

(global-set-key (kbd "C-o") 'menu-find-file-existing)
(defadvice find-file-read-args (around find-file-read-args-always-use-dialog-box act)
  "Simulate invoking menu item as if by the mouse; see `use-dialog-box'."
 (let ((last-nonmenu-event nil))
       ad-do-it))
Sombrero answered 4/5, 2017 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.