home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc072.zip / ckugnu.msg < prev    next >
Internet Message Format  |  1988-08-16  |  7KB

  1. Date: 21 Mar 88 21:12:04 GMT
  2. From: jeff@colgate.CSNET (Jeff Norden)
  3. Subject: Using Kermit from shell mode
  4.  
  5. I'm not sure, but I think somebody asked about running kermit under shell
  6. mode a while ago.  Anyway, here is some code that I find useful.  The result
  7. is that I can log onto machines with primitive operating systems (VMS and
  8. ATT system V :-), and still have the features of shell-mode available for
  9. command history, etc.  It's also handy to be able to run a file transfer in
  10. an emacs window.  The transfer is in the "background", but you can also
  11. monitor or stop it easily.
  12.  
  13. The ^\ key is bound to a function for sending escape sequences to kermit,
  14. and ^C^Q can be used to send any control characters needed thru to the
  15. system you connect to.  A more serious problem is that some systems will not
  16. recognize a ^J as an end-of-line character.  So LFD is bound to a new
  17. function which acts just like CR usually does in shell-mode, but a ^M is
  18. sent as an end-of-line.  Funcions are also provied to swap the bindings of
  19. CR and LFD.  I've also included a filter which will clean out any ^M's or
  20. ^@'s that get typed at you, but I don't really recommend it.  There doesn't
  21. seem to be an acceptably fast way to do this via emacs-lisp.  Invoking
  22. kermit by the command " kermit | tr -d '\015' " seems to work better (on my
  23. system anyway).
  24.  
  25. Put the code below in a file named  wherever/kermit-shell.el, and add
  26.  
  27.  (autoload 'kermit "wherever/kermit-shell.el" "" t) 
  28.  
  29. to your .emacs file.  Then use M-x kermit when you want to load in the new
  30. functions and bindings.  ("kermit" is just a dummy function which causes the
  31. file to be loaded.)
  32.  
  33. Here's how I've been using this setup.  We have several machines connected
  34. thru a terminal switch.  If I want to connect to a unix system, then I use the
  35. LFD key to talk to the switch, and ignore any ^M's in the buffer, and do a
  36. "stty -echo nl" after I log in.  Then the only real difference from being in
  37. local shell-mode is that it is you need to to type ^C^Q^C to send an
  38. interrupt, and ^C^Q^Z for a stop signal, etc. (since ^C^C just generates a
  39. local stop signal, which kermit ignores).  To connect to a VMS system, I use
  40. a shell script to invoke kermit thru the tr filter, do "M-X cr-key", and
  41. then tell VMS that I'm on a half-duplex terminal.
  42.  
  43. Please let me know if any bugs turn up.  Also, shell-send-input-cr is hacked
  44. directly from the gnu source, so the GNU copyright and license apply.
  45.  
  46.                 -Jeff Norden
  47.                 jeff@colgate.csnet
  48.             Dept of Mathematics, Colgate University
  49.             Hamilton, NY  13346.
  50.  
  51. --- cut here ----- do not fold, bend, or spindle ----- cut here -----------
  52. ;;Additions to shell mode for use with kermit, etc.
  53. ;;Feb 1988, Jeff Norden - jeff@colgate.csnet
  54. ;;This file is part of GNU Emacs, copying restrictions apply.
  55. ;;Please see the GNU Emacs General Public License for details.
  56. ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  57.  
  58. (require 'shell)
  59.  
  60. (defvar kermit-esc-char "\C-\\" "*Kermit's escape char")
  61.  
  62. (defun kermit-esc ()
  63. "For sending escape sequences to a kermit running in shell mode."
  64.  (interactive)
  65.  (process-send-string 
  66.    (get-buffer-process (current-buffer))
  67.    (concat kermit-esc-char (char-to-string (read-char)))))
  68.  
  69. (defun send-char ()
  70. "Send an arbitrary character to a program in shell mode."
  71.  (interactive)
  72.  (process-send-string 
  73.    (get-buffer-process (current-buffer))
  74.    (char-to-string (read-char))))
  75.  
  76. (define-key shell-mode-map "\C-\\" 'kermit-esc)
  77. (define-key shell-mode-map "\C-cq" 'send-char)
  78. ;; extra bindings for folks suffering form ^S/^Q braindamage:
  79. (define-key shell-mode-map "\C-c\\" 'kermit-esc)
  80. (define-key shell-mode-map "\C-c\C-q" 'send-char)
  81.  
  82. (defun shell-send-input-cr ()
  83.   "Same as shell-send-input, but a return (^M) is sent at the end 
  84.  instead of a newline (^J)."
  85.   (interactive)
  86.   (end-of-line)
  87.     (if (eobp)
  88.     (progn
  89.       (move-marker last-input-start
  90.            (process-mark (get-buffer-process (current-buffer))))
  91.       (insert ?\n)
  92.       (move-marker last-input-end (point)))
  93.     (beginning-of-line)
  94.     (re-search-forward shell-prompt-pattern nil t)
  95.     (let ((copy (buffer-substring (point)
  96.                   (progn (forward-line 1) (point)))))
  97.       (goto-char (point-max))
  98.       (move-marker last-input-start (point))
  99.       (insert copy)
  100.       (move-marker last-input-end (point))))
  101.     (condition-case ()
  102.     (save-excursion
  103.       (goto-char last-input-start)
  104.       (shell-set-directory))
  105.       (error (funcall shell-set-directory-error-hook)))
  106.   (let ((process (get-buffer-process (current-buffer))))
  107.     (process-send-region process last-input-start (- last-input-end 1))
  108.     (process-send-string process "\r")
  109.     (set-marker (process-mark process) (point))))
  110.  
  111. ;; This is backwards of what makes sense, but ...
  112. (define-key shell-mode-map "\n" 'shell-send-input-cr)
  113.  
  114. (defun cr-key ()
  115. "For shell mode - set the return key to actually send a return and
  116. the line feed key actually send a newline."
  117.  (interactive)
  118.  (define-key shell-mode-map "\r" 'shell-send-input-cr)
  119.  (define-key shell-mode-map "\n" 'shell-send-input))
  120.  
  121. (defun nl-key () "The opposite of cr-key."
  122.  (interactive)
  123.  (define-key shell-mode-map "\n" 'shell-send-input-cr)
  124.  (define-key shell-mode-map "\r" 'shell-send-input))
  125.  
  126. ;; This filter works, but I don't especially recommend it.
  127. (defun clean-filter (process string)
  128. "A process filter which kills off ^M's and ^@'s."
  129.  (set-buffer (process-buffer process))
  130.  (let 
  131.      ((firstpos (string-match "[^\C-@\r]+" string))
  132.       (buffermark (process-mark process))
  133.       (oldpt (point))
  134.       (newstring '"")
  135.       goback)
  136.    (while firstpos
  137.      (setq newstring 
  138.        (concat newstring (substring string firstpos (match-end 0))))
  139.      (setq firstpos (string-match "[^\C-@\r]+" string (match-end 0))))
  140.    (goto-char (marker-position buffermark))
  141.    (setq goback (< oldpt (point)))
  142.    (insert newstring)
  143.    (set-marker buffermark (point))
  144.    (if goback (goto-char oldpt))))
  145.  
  146. (defun clean-shell-on ()
  147. "Add a filter to the process running in the current buffer so that
  148.  null's and ^M's will not appear.
  149. A better alternative is to pipe the program you want to run thru
  150.  tr -d '\\015' "
  151.  (interactive)
  152.  (set-process-filter (get-buffer-process (current-buffer)) 'clean-filter))
  153.  
  154. (defun clean-shell-off ()
  155. "Cancel a previous clean-shell-on command"
  156.  (interactive)
  157.  (set-process-filter (get-buffer-process (current-buffer)) nil))
  158.  
  159. (define-key shell-mode-map "\C-cC" 'clean-shell-on)
  160. (define-key shell-mode-map "\C-cc" 'clean-shell-off)
  161.  
  162. (defun kermit () "Extensions to shell mode for using kermit"
  163.  (interactive) (message "Kermit shell extensions have been loaded"))
  164.  
  165. ------------------------------
  166.  
  167.