How to configure emacs 23.1.1 on osx so that file drag and drop on the emacs window opens the file in a new buffer instead of appending it to the current buffer?
You can try:
(global-set-key [ns-drag-file] 'ns-find-file)
It works for me on Emacs 23.2.1
I use:
(if (fboundp 'ns-find-file)
(global-set-key [ns-drag-file] 'ns-find-file))
This (which basically is the same as given in other answers) ensures that a new buffer is created. The if
part ensures that the code will work even in a non-Mac environment.
(setq ns-pop-up-frames nil)
This ensures that the new buffer is displayed in an existing window, so that a new Emacs frame isn't opened. (I noticed in a comment that you had trouble with this.)
I use in my .emacs:
; Upon drag-and-drop: Find the file, w/shift insert filename; w/meta insert file contents
; note that the emacs window must be selected (CMD-TAB) for the modifiers to register
(define-key global-map [M-ns-drag-file] 'ns-insert-file)
(define-key global-map [S-ns-drag-file] 'ns-insert-filename)
(define-key global-map [ns-drag-file] 'ns-find-file-in-frame)
(defun ns-insert-filename ()
"Insert contents of first element of `ns-input-file' at point."
(interactive)
(let ((f (pop ns-input-file)))
(insert f))
(if ns-input-file ; any more? Separate by " "
(insert " ")))
(defun ns-find-file-in-frame ()
"Do a `find-file' with the `ns-input-file' as argument; staying in frame."
(interactive)
(let ((ns-pop-up-frames nil))
(ns-find-file)))
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