emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] enhanced mac drag-n-drop


From: Sean O'Rourke
Subject: [patch] enhanced mac drag-n-drop
Date: Tue, 05 Apr 2005 17:53:00 -0700
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (darwin)

The included patch to src/macterm.c extends Carbon Emacs' drag-n-drop
to handle directories, URLs, and text.  To use it, the included Lisp
code also needs to be added to the appropriate Lisp file, probably
lisp/term/mac-win.el.  This is my first foray into Emacs C-hackery, so
although it's been working for me for the last few days, I would
appreciate some Mac users' trying it out.

Thanks for your time,
/s

ps -- please Cc me on replies, as I'm not subscribed to emacs-devel.

(defun mac-primary-dnd-function (event)
  "Perform the most common action for each type of item dropped
onto Emacs on Mac OS X.  Currently, this means:
    * File or directory -- call `find-file'.
    * URL -- call `browse-url-browser-function'.
    * Text -- insert text at point."
  (interactive "e")
  ;; Make sure the drop target has positive co-ords before setting the
  ;; selected frame - otherwise it won't work.  <address@hidden>
  (let* ((window (posn-window (event-start event)))
         (coords (posn-x-y (event-start event)))
         (x (car coords))
         (y (cdr coords)))
    (if (and (> x 0) (> y 0))
        (set-frame-selected-window nil window))
    (mapcar
     (lambda (name)
       (case (car name)
         (text (insert (cdr name)))
         (url (funcall browse-url-browser-function (cdr name)))
         (file
          (setq name (cdr name))
          (if (and (file-exists-p name)
                   (not (string-match (image-file-name-regexp) name)))
              (find-file name)
              (insert name)))))
     (cadd event)))
  (raise-frame)
  (recenter))

(defun mac-secondary-dnd-function (event)
  "Perform a less common action for each type of item dropped
onto Emacs on Mac OS X.  Currently, this means:
    * File or directory -- insert pathname at point.
    * URL -- insert URL text at point.
    * Text -- if it is a file or directory name, edit that file;
      otherwise, insert text at point."
  (interactive "e")
  ;; Make sure the drop target has positive co-ords before setting the
  ;; selected frame - otherwise it won't work.  <address@hidden>
  (let* ((window (posn-window (event-start event)))
         (coords (posn-x-y (event-start event)))
         (x (car coords))
         (y (cdr coords)))
    (if (and (> x 0) (> y 0))
        (set-frame-selected-window nil window))
    (mapcar
     (lambda (name)
       (case (car name)
         (text (setq name (cdr name))
               (if (and (file-exists-p name)
                        (not (string-match (image-file-name-regexp) name)))
                   (find-file name)
                   (insert name)))
         ((url file) (insert (cdr name)))))
     (caddr event)))
    (raise-frame)
    (recenter))

(global-set-key [drag-n-drop] 'mac-primary-dnd-function)
(global-set-key [shift drag-n-drop] 'mac-secondary-dnd-function)

Attachment: txtKV2qNVZfzl.txt
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]