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?

5
  • After a bit of looking around, this seems to be a duplicate of stackoverflow.com/questions/390602/… [-]
    – Squidly
    Oct 21, 2014 at 10:22
  • @MrBones it's still being not clear how to invoke it there...
    – cnd
    Oct 21, 2014 at 10:27
  • 1
    See the answer - I've put the two things together for you.
    – Squidly
    Oct 21, 2014 at 10:54
  • @MrBones so far I'm still on command line :(
    – cnd
    Oct 21, 2014 at 11:01
  • 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.
    – Squidly
    Oct 21, 2014 at 11:19

2 Answers 2

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

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.
    – Squidly
    Oct 21, 2014 at 10:22
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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.