[gnu.emacs.bug] telnet C-c C-y doesn't work

hrp@snoid.cray.com (Hal Peterson) (12/13/88)

With 18.52 and earlier versions of GNU Emacs, C-c C-y, which should
yank the last input line, does not work in telnet mode.

The problem is that it is using the shell-mode function to handle
this, but telnet (unlike shell) deletes the text from the buffer
when transmitting to the process.  The following diffs change telnet
mode to use its own function for C-c C-y and to save away the previous
input in a variable.

While I was at it, I made a small change to the keymap initialization
so that it conforms to the way other modes do it:  now the keymap is
only initialized the first time you load telnet.

An obvious next step is to take both telnet mode and shell mode and
make their C-c C-y functions smarter:  make the history variable work
like the mark-ring.  I'll do that the next time I feel like running
around getting copyright disclaimers from vice presidents.  Don't be
surprised if you get tired of waiting and do it yourself.

--
Hal Peterson / Cray Research / 1440 Northland Dr. / Mendota Hts, MN  55120
hrp@cray.com			uunet!cray!hrp		    (612) 681-3145

============================================================
*** /usr/earth4/gnu/src/emacs/lisp/telnet.el	Sun Apr 10 01:55:18 1988
--- ntelnet.el	Mon Dec 12 14:46:42 1988
***************
*** 31,36 ****
--- 31,37 ----
  (defvar telnet-count 0)
  (defvar telnet-replace-c-g nil)
  (defvar telnet-remote-echoes nil)
+ (defvar telnet-previous-input "")
  
  (defun telnet-interrupt-subjob ()
    (interactive)
***************
*** 49,57 ****
  		  (prog1 (read-char)
  		    (setq quit-flag nil))))))
  
! (setq telnet-mode-map (make-sparse-keymap))
! 
! (progn
    (define-key telnet-mode-map "\C-m" 'telnet-send-input)
    (define-key telnet-mode-map "\C-j" 'telnet-send-input)
    (define-key telnet-mode-map "\C-c\C-d" 'shell-send-eof)
--- 50,60 ----
  		  (prog1 (read-char)
  		    (setq quit-flag nil))))))
  
! ; initialization on first load.
! (if telnet-mode-map
!     nil
!   (make-variable-buffer-local 'telnet-previous-input)
!   (setq telnet-mode-map (make-sparse-keymap))
    (define-key telnet-mode-map "\C-m" 'telnet-send-input)
    (define-key telnet-mode-map "\C-j" 'telnet-send-input)
    (define-key telnet-mode-map "\C-c\C-d" 'shell-send-eof)
***************
*** 62,68 ****
    (define-key telnet-mode-map "\C-c\C-w" 'backward-kill-word)
    (define-key telnet-mode-map "\C-c\C-o" 'kill-output-from-shell)
    (define-key telnet-mode-map "\C-c\C-r" 'show-output-from-shell)
!   (define-key telnet-mode-map "\C-c\C-y" 'copy-last-shell-input))
  
  ;;maybe should have a flag for when have found type
  (defun telnet-check-software-type-initialize (string)
--- 65,71 ----
    (define-key telnet-mode-map "\C-c\C-w" 'backward-kill-word)
    (define-key telnet-mode-map "\C-c\C-o" 'kill-output-from-shell)
    (define-key telnet-mode-map "\C-c\C-r" 'show-output-from-shell)
!   (define-key telnet-mode-map "\C-c\C-y" 'telnet-copy-last-input))
  
  ;;maybe should have a flag for when have found type
  (defun telnet-check-software-type-initialize (string)
***************
*** 126,132 ****
  as input to the telnet, including a telnet-new-line inserted at the end.
  Not at end, copies current line to the end of the buffer and sends it,
  after first attempting to discard any prompt at the beginning of the line
! by matching the regexp that is the value of telnet-prompt-pattern if possible."
   (interactive)
   (let (copied)
    (end-of-line)
--- 129,136 ----
  as input to the telnet, including a telnet-new-line inserted at the end.
  Not at end, copies current line to the end of the buffer and sends it,
  after first attempting to discard any prompt at the beginning of the line
! by matching the regexp that is the value of telnet-prompt-pattern if possible.
! In any case, save the sent string in telnet-previous-input."
   (interactive)
   (let (copied)
    (end-of-line)
***************
*** 145,154 ****
        (move-marker last-input-end (point))))
    (save-excursion
      (goto-char last-input-start)
!     (let ((process (get-buffer-process (current-buffer))))
!       (send-region process last-input-start last-input-end)
        (if (not copied) (send-string process telnet-new-line))
!       (set-marker (process-mark process) (point))))))
  
  (defun telnet (arg)
    "Open a network login connection to host named HOST (a string).
--- 149,169 ----
        (move-marker last-input-end (point))))
    (save-excursion
      (goto-char last-input-start)
!     (let ((process (get-buffer-process (current-buffer)))
! 	  (input (buffer-substring last-input-start last-input-end)))
!       (send-string process input)
        (if (not copied) (send-string process telnet-new-line))
!       (set-marker (process-mark process) (point))
!       (setq telnet-previous-input input)))))
! 
! (defun telnet-copy-last-input ()
!   "Copy previous telnet input, sans newline, and insert before point."
!   (interactive)
!   (insert telnet-previous-input)
!   (if (eq (aref telnet-previous-input
! 		(length telnet-previous-input))
! 	  '?\n)
!       (delete-char -1)))
  
  (defun telnet (arg)
    "Open a network login connection to host named HOST (a string).

Compilation exited abnormally with code 1 at Mon Dec 12 14:47:35