home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-18.59-bin.lha / lib / emacs / 18.59 / lisp / amiga-init.el < prev    next >
Lisp/Scheme  |  1993-06-05  |  6KB  |  207 lines

  1. (global-set-key "\C-z" 'amiga-iconify)
  2. (setq amiga-map (make-keymap))
  3. (global-set-key "\C-x\C-^" amiga-map)
  4.  
  5. (load "amiga-mouse")
  6. (load "amiga-menu")
  7.  
  8. (define-key amiga-map "A" 'previous-line)
  9. (define-key amiga-map "B" 'next-line)
  10. (define-key amiga-map "D" 'backward-char)
  11. (define-key amiga-map "C" 'forward-char)
  12. (define-key amiga-map "?~" 'info)
  13. (define-key amiga-map "T" 'scroll-down)
  14. (define-key amiga-map "S" 'scroll-up)
  15. (define-key amiga-map " @" 'forward-word)
  16. (define-key amiga-map " A" 'backward-word)
  17. (define-key amiga-map "\M-A" 'beginning-of-buffer)
  18. (define-key amiga-map "\M-B" 'end-of-buffer)
  19. (define-key amiga-map "\M-D" 'beginning-of-line)
  20. (define-key amiga-map "\M-C" 'end-of-line)
  21. (define-key amiga-map "\M- \M-@" 'forward-sexp)
  22. (define-key amiga-map "\M- \M-A" 'backward-sexp)
  23. (define-key amiga-map "\M-T" 'scroll-down-1)
  24. (define-key amiga-map "\M-S" 'scroll-up-1)
  25. ; Keypad sequences are handled like normal ones
  26. (define-key amiga-map "K" 'do-nothing)
  27.  
  28. (defun do-nothing () (interactive))
  29.  
  30. (defun scroll-down-1 ()
  31.   "Move up one line on screen"
  32.   (interactive)
  33.   (scroll-down 1))
  34.  
  35. (defun scroll-up-1 ()
  36.   "Move down one line on screen"
  37.   (interactive)
  38.   (scroll-up 1))
  39.  
  40. ;; ARexx stuff
  41.  
  42. ;;; This function needs to be re-written to handle rexx returned results.
  43. ;;;
  44. (setq amiga-arexx-processing nil)
  45. (setq amiga-arexx-errors nil)
  46.  
  47. (defvar amiga-arexx-failat 5
  48.   "Return level from which arexx commands returns cause errors")
  49.  
  50. ;;
  51. ;; process incoming rexx messages
  52. ;;
  53. (defun amiga-arexx-process ()
  54.   (interactive)
  55.   (if (not amiga-arexx-processing)
  56.       (progn
  57.     (setq amiga-arexx-processing t)
  58.     (condition-case nil ; Avoid blocking of processing in case of bugs
  59.         (let (arexxcmd)
  60.           (while (setq arexxcmd (amiga-arexx-get-next-msg))
  61.         (let ((rc 0) result)
  62.           (condition-case err ; detect errors in arexx command
  63.               (let ((expr (car (read-from-string arexxcmd))))
  64.             (setq result (prin1-to-string (eval expr))))
  65.             (error (progn
  66.                  (setq rc 20)
  67.                  (setq result (prin1-to-string err)))))
  68.           (amiga-arexx-reply rc result))))
  69.       (error nil))
  70.     (setq amiga-arexx-processing nil))))
  71.  
  72. (defun amiga-arexx-wait-command (id)
  73.   "Waits for a pending ARexx commands (MSGID) to complete.
  74. Also processes any pending ARexx requests during this interval.
  75. returns the result list associated with this id, which takes the
  76. form: (msgid result-code error-or-string)
  77. ``error-or-string'' depends on ``result-code''.
  78. if ``result-code'' is 0 the command finished successfully and
  79. ``error-or-string'' will be a string or nil, otherwise the command
  80. returned with an error and ``error-or-string'' will be an interger
  81. that is the secondary error code of the arexx command."
  82.   (amiga-arexx-process)
  83.   (while (not (amiga-arexx-check-command id))
  84.     (amiga-arexx-wait)
  85.     (amiga-arexx-process))
  86.   (amiga-arexx-get-msg-results id))
  87.  
  88. (defconst amiga-arexx-error-messages
  89. ["No cause"
  90. "Program not found"
  91. "Execution halted"
  92. "Insufficient memory"
  93. "Invalid character"
  94. "Unmatched quote"
  95. "Unterminated comment"
  96. "Clause too long"
  97. "Invalid token"
  98. "Symbol or string too long"
  99. "Invalid message packet"
  100. "Command string error"
  101. "Error return from function"
  102. "Host environment not found"
  103. "Requested library not found"
  104. "Function not found"
  105. "Function did not return value"
  106. "Wrong number of arguments"
  107. "Invalid argument to function"
  108. "Invalid PROCEDURE"
  109. "Unexpected THEN or WHEN"
  110. "Unexpected ELSE or OTHERWISE"
  111. "Unexpected BREAK, LEAVE or ITERATE"
  112. "Invalid statement in SELECT"
  113. "Missing or multiple THEN"
  114. "Missing OTHERWISE"
  115. "Missing or unexpected END"
  116. "Symbol mismatch"
  117. "Invalid DO syntax"
  118. "Incomplete IF or SELECT"
  119. "Label not found"
  120. "Symbol expected"
  121. "Symbol or string expected"
  122. "Invalid keyword"
  123. "Required keyword missing"
  124. "Extraneous characters"
  125. "Keyword conflict"
  126. "Invalid template"
  127. "Invalid TRACE request"
  128. "Unitialized variable"
  129. "Invalid variable name"
  130. "Invalid expression"
  131. "Unbalanced parentheses"
  132. "Nesting limit exceeded"
  133. "Invalid expression result"
  134. "Expression required"
  135. "Boolean value not 0 or 1"
  136. "Arithmetic conversion error"
  137. "Invalid operand"
  138. ]
  139. "The arexx error messages, sorted by number")
  140.  
  141. (defun amiga-arexx-do-command (str as-file)
  142.   "Sends ARexx command STR (like amiga-arexx-send-command).
  143. If AS-FILE is true, STR is an arexx command, otherwise it is a file name.
  144. Waits for the command to return.  If the arexx command fails an error will
  145. be caused.
  146.  
  147. If you would like to get result strings and errors (ie. not cause
  148. a lisp error) use: (amiga-arexx-do-command-with-results)"
  149.   (interactive "sARexx command:
  150. P")
  151.   (let ((id (amiga-arexx-send-command str as-file)))
  152.     (if (not id)
  153.     (error "Failed to send arexx command.")
  154.       (let ((reslist (amiga-arexx-wait-command id)))
  155.     (let ((rc (nth 1 reslist)) (second (nth 2 reslist)))
  156.       (if (> rc 0)
  157.           (progn            ; error
  158.         (let ((error-message
  159.                (if (< second (length amiga-arexx-error-messages))
  160.              (aref amiga-arexx-error-messages second)
  161.              (format nil "Unknown error %d" second))))
  162.           (error "Arexx command failed, level %d, cause %s" rc error-message))
  163.         reslist)
  164.       second))))))
  165.  
  166. (defun amiga-arexx-do-command-with-results (str as-file)
  167.   "Sends ARexx command STR (like amiga-arexx-do-command).
  168. If AS-FILE is true, STR is an arexx command, otherwise it is a file name.
  169. Waits for the command to return.
  170.  
  171. The return value is one of three things:
  172.  - the command executed succesfully: nil or a result string.
  173.  - the command failed: a list of the form (RC ERROR-CODE)
  174.    where RC is the severity and ERROR-CODE is the secondary error."
  175.   (interactive "sARexx command:
  176. P")
  177.   (let ((id (amiga-arexx-send-command str as-file)))
  178.     (if (not id)
  179.     (error "Failed to send arexx command.")
  180.       (let ((reslist (amiga-arexx-wait-command id)))
  181.     (let ((rc (nth 1 reslist)) (second (nth 2 reslist)))
  182.       (if (and rc (> rc 0))
  183.           (list rc second)
  184.         second))))))
  185.  
  186. (define-key amiga-map "X" 'amiga-arexx-process)
  187. (setq amiga-arexx-initialized t) ;; ARexx commands can now be processed.
  188.  
  189. (defun amiga-wb-process ()
  190.   "Process all pending workbench events, ie load all files requested"
  191.   (interactive)
  192.   (let (file)
  193.     (condition-case nil
  194.     (while (setq file (amiga-get-wb-event t))
  195.       (condition-case nil
  196.           (find-file file)
  197.         (error nil)))
  198.       (error nil))))
  199.  
  200. (define-key amiga-map "W" 'amiga-wb-process)
  201. (setq amiga-wb-initialized t) ;; WB events can now be processed.
  202.  
  203. (setq completion-ignore-case t)
  204. ;; Default is no numbered versions on Amiga, because directory searches are too
  205. ;; slow.
  206. (setq version-control 'never)
  207.