home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-30 | 4.1 KB | 120 lines | [TEXT/EMAC] |
- ;;;
- ;;; This file is part of a Macintosh port of GNU Emacs.
- ;;; Copyright (C) 1993 Marc Parmet. All rights reserved.
- ;;;
- ;;; This is the implementation of the Apple event required suite.
- ;;;
- ;;; This file cannot be included in a dump. The AEInstallEventHandler calls
- ;;; must be executed on each invokation.
- ;;;
-
- (AEInstallEventHandler kCoreEventClass kAEOpenApplication 'do-ae-open-appl 0 0)
-
- (defun do-ae-open-appl (event reply refCon)
- noErr)
-
- (AEInstallEventHandler kCoreEventClass kAEOpenDocuments 'do-ae-open-docs 0 0)
-
- (defun do-ae-open-docs (event reply refCon)
- (let* ((docList (make-string sizeof-AEDesc 0))
- have-docList
- (itemsInList (make-string 4 0))
- (result
- (catch 'bailout
- (catch-err (AEGetParamDesc event keyDirectObject typeAEList docList))
- (setq have-docList t)
- ;;; We get an error from this next line if Think C sends a position record.
- ;(catch-err (ae-have-required-parameters event))
- (catch-err (AECountItems docList itemsInList))
- (setq itemsInList (ae-extract typeLongInteger itemsInList 0))
- (catch-err (ae-open-list-items docList 1 itemsInList event))
- noErr)))
- (if have-docList (AEDisposeDesc docList))
- result))
-
- (defun ae-is-stationery (spec)
- (let* ((info (make-string sizeof-FInfo 0))
- (err (FSpGetFInfo spec info)))
- (if (zerop err)
- (let ((flags (extract-internal info 8 2 nil)))
- (not (zerop (logand 2048 flags))))
- nil)))
-
- (defun ae-open-list-items (docList i itemsInList event)
- (if (> i itemsInList)
- noErr
- (let* ((keywd (make-string 4 0))
- (returnedType (make-string 4 0))
- (spec (make-string sizeof-FSSpec 0))
- (actualSize (make-string 4 0))
- (err (AEGetNthPtr docList i typeFSS keywd returnedType spec
- sizeof-FSSpec actualSize)))
- (if (not (zerop err))
- err
- (let ((filename (FSSpec-to-unix-filename spec)))
- (if (ae-is-stationery spec)
- (let ((old-buffer (current-buffer))
- (new-buffer (generate-new-buffer "untitled")))
- (set-buffer new-buffer)
- (insert-file-contents filename)
- (if (eq (selected-window) (minibuffer-window))
- (set-buffer old-buffer)
- (switch-to-buffer new-buffer)))
- (if (eq (selected-window) (minibuffer-window))
- (progn
- (find-file-other-window filename)
- ;;; find-file-other-window will select the new window, probably
- ;;; not a good idea. If we use save-excursion, the
- ;;; newly created buffer will not be displayed immediately, also
- ;;; not a good idea. So we do this.
- (select-window (minibuffer-window)))
- (find-file filename)))
- (if (fboundp 'tc:parse-position-record)
- (tc:parse-position-record event)))))
- (ae-open-list-items docList (1+ i) itemsInList event)))
-
- (AEInstallEventHandler kCoreEventClass kAEPrintDocuments 'do-ae-print-docs 0 0)
-
- (defun do-ae-print-docs (event reply refCon)
- (let* ((docList (make-string sizeof-AEDesc 0))
- have-docList
- (itemsInList (make-string 4 0))
- err
- (result
- (catch 'bailout
- (catch-err (AEGetParamDesc event keyDirectObject typeAEList docList))
- (setq have-docList t)
- (catch-err (ae-have-required-parameters event))
- (catch-err (AECountItems docList itemsInList))
- (setq itemsInList (ae-extract typeLongInteger itemsInList 0))
- (catch-err (ae-print-list-items docList 1 itemsInList))
- noErr)))
- (if have-docList (AEDisposeDesc docList))
- result))
-
- (defun ae-print-list-items (docList i itemsInList)
- (if (> i itemsInList)
- noErr
- (let* ((keywd (make-string 4 0))
- (returnedType (make-string 4 0))
- (spec (make-string sizeof-FSSpec 0))
- (actualSize (make-string 4 0))
- (err (AEGetNthPtr docList i typeFSS keywd returnedType spec
- sizeof-FSSpec actualSize)))
- (if (not (zerop err))
- err
- (let ((filename (FSSpec-to-unix-filename spec)))
- (call-process "lpr" nil 0 nil filename))
- (ae-print-list-items docList (1+ i) itemsInList)))))
-
- (AEInstallEventHandler kCoreEventClass kAEQuitApplication 'do-ae-quit-appl 0 0)
-
- (defun do-ae-quit-appl (event reply refCon)
- ;;; This will save changed buffers as new files with hash marks around the name.
- ;;; A more interactive function would not be right here.
- (let ((err (ae-have-required-parameters event)))
- (if (not (zerop err))
- err
- (kill-emacs)
- noErr)))
-