comparison lisp/term/mac-win.el @ 70870:e5af358ce93a

Set idle timer to clean up expired Apple events. (mac-ae-get-url): Redispatch Apple event on unknown scheme. (mac-dispatch-apple-event): Resume Apple event if it is suspended. Optionally set error message in reply.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Wed, 24 May 2006 08:06:27 +0000
parents e5e83c1c6fa5
children ed68e074ebb4
comparison
equal deleted inserted replaced
70869:7e291c130ae7 70870:e5af358ce93a
1647 (interactive "e") 1647 (interactive "e")
1648 (let* ((ae (mac-event-ae event)) 1648 (let* ((ae (mac-event-ae event))
1649 (parsed-url (url-generic-parse-url (mac-ae-text ae)))) 1649 (parsed-url (url-generic-parse-url (mac-ae-text ae))))
1650 (if (string= (url-type parsed-url) "mailto") 1650 (if (string= (url-type parsed-url) "mailto")
1651 (url-mailto parsed-url) 1651 (url-mailto parsed-url)
1652 (error "Unsupported URL scheme: %s" (url-type parsed-url))))) 1652 (mac-resume-apple-event ae t))))
1653 1653
1654 (setq mac-apple-event-map (make-sparse-keymap)) 1654 (setq mac-apple-event-map (make-sparse-keymap))
1655 1655
1656 ;; Received when Emacs is launched without associated documents. 1656 ;; Received when Emacs is launched without associated documents.
1657 ;; Accept it as an Apple event, but no Emacs event is generated so as 1657 ;; Accept it as an Apple event, but no Emacs event is generated so as
1798 1798
1799 (defun mac-dispatch-apple-event (event) 1799 (defun mac-dispatch-apple-event (event)
1800 "Dispatch EVENT according to the keymap `mac-apple-event-map'." 1800 "Dispatch EVENT according to the keymap `mac-apple-event-map'."
1801 (interactive "e") 1801 (interactive "e")
1802 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event))) 1802 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event)))
1803 (service-message 1803 (ae (mac-event-ae event))
1804 (and (keymapp binding) 1804 (service-message (and (keymapp binding)
1805 (cdr (mac-ae-parameter (mac-event-ae event) "svmg"))))) 1805 (cdr (mac-ae-parameter ae "svmg")))))
1806 (when service-message 1806 (when service-message
1807 (setq service-message 1807 (setq service-message
1808 (intern (decode-coding-string service-message 'utf-8))) 1808 (intern (decode-coding-string service-message 'utf-8)))
1809 (setq binding (lookup-key binding (vector service-message)))) 1809 (setq binding (lookup-key binding (vector service-message))))
1810 ;; Replace (cadr event) with a dummy position so that event-start 1810 ;; Replace (cadr event) with a dummy position so that event-start
1811 ;; returns it. 1811 ;; returns it.
1812 (setcar (cdr event) (list (selected-window) (point) '(0 . 0) 0)) 1812 (setcar (cdr event) (list (selected-window) (point) '(0 . 0) 0))
1813 (call-interactively binding))) 1813 (if (null (mac-ae-parameter ae 'emacs-suspension-id))
1814 (call-interactively binding)
1815 (condition-case err
1816 (progn
1817 (call-interactively binding)
1818 (mac-resume-apple-event ae))
1819 (error
1820 (mac-ae-set-reply-parameter ae "errs"
1821 (cons "TEXT" (error-message-string err)))
1822 (mac-resume-apple-event ae -10000)))))) ; errAEEventFailed
1814 1823
1815 (global-set-key [mac-apple-event] 'mac-dispatch-apple-event) 1824 (global-set-key [mac-apple-event] 'mac-dispatch-apple-event)
1816 1825
1817 ;; Processing of Apple events are deferred at the startup time. For 1826 ;; Processing of Apple events are deferred at the startup time. For
1818 ;; example, files dropped onto the Emacs application icon can only be 1827 ;; example, files dropped onto the Emacs application icon can only be
1819 ;; processed when the initial frame has been created: this is where 1828 ;; processed when the initial frame has been created: this is where
1820 ;; the files should be opened. 1829 ;; the files should be opened.
1821 (add-hook 'after-init-hook 'mac-process-deferred-apple-events) 1830 (add-hook 'after-init-hook 'mac-process-deferred-apple-events)
1831
1832 (run-with-idle-timer 5 t 'mac-cleanup-expired-apple-events)
1822 1833
1823 1834
1824 ;;;; Drag and drop 1835 ;;;; Drag and drop
1825 1836
1826 (defcustom mac-dnd-types-alist 1837 (defcustom mac-dnd-types-alist