Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure emacs drag and drop to open instead of append on osx

Tags:

emacs

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?

like image 293
hiheelhottie Avatar asked Sep 27 '10 16:09

hiheelhottie


3 Answers

You can try:

(global-set-key [ns-drag-file] 'ns-find-file)

It works for me on Emacs 23.2.1

like image 53
Tao Peng Avatar answered Oct 06 '22 00:10

Tao Peng


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

like image 39
Lindydancer Avatar answered Oct 06 '22 01:10

Lindydancer


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)))
like image 21
cabo Avatar answered Oct 05 '22 23:10

cabo