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?
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`.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With