
(defvar cmd-history-max 50)

(setq cmd-specials (quote (("man" . cmd-man) ("vi" . cmd-no-go) ("su" . cmd-su) ("kinit" lambda (arg) (cmd-su arg "kinit")) ("more" . cmd-more) ("cd" . cmd-cd) ("pushd" lambda (arg) (cmd-dir-changing-command "pushd" arg)) ("popd" lambda (arg) (cmd-dir-changing-command "popd" arg)) ("cwd" . cmd-set-cwd))))

(defvar cmd-shell-name "/afs/athena.mit.edu/contrib/watchmaker/rc")

(defvar cmd-shell-args (list "-l"))

(defvar cmd-run-commands (if (file-exists-p "~/.cmdrc") (concat "source " (getenv "HOME") "/.cmdrc") nil))

(defvar cmd-rs6000-mode nil)

(defvar newline "
")

(defvar cmd-cd-function nil)

(setq cmd-cd-function (function (lambda (newdir) (message newdir))))

(defvar cmd-working-directory-regexp "[^/~]*\\([^ :%]+\\);")

(defvar cmd-remember-working-directory t)

(setq cmd-pre-completion-configuration nil)

(progn (or (boundp (quote cmd-mode-map)) (setq cmd-mode-map (make-sparse-keymap))) (define-key cmd-mode-map "" (quote cmd-delete-backward-char)) (define-key cmd-mode-map "" (quote cmd-beginning-of-line)) (define-key cmd-mode-map "" (quote cmd-backward-kill-word)) (define-key cmd-mode-map "" (quote cmd-copy-output-as-kill)) (define-key cmd-mode-map "p" (quote cmd-previous-history)) (define-key cmd-mode-map "n" (quote cmd-next-history)) (define-key cmd-mode-map "" (quote cmd-recenter)) (define-key cmd-mode-map "" (quote cmd-stop-process)) (define-key cmd-mode-map "" (quote cmd-interrupt-process)) (define-key cmd-mode-map "p" (quote cmd-read-password)) (define-key cmd-mode-map "s" (quote cmd-send-shell)) (define-key cmd-mode-map "" (quote cmd-delete-char)) (define-key cmd-mode-map "" (quote cmd-find-file)) (define-key cmd-mode-map "" (quote cmd-find-file-read-only)) (define-key cmd-mode-map "	" (quote cmd-completion)) (define-key cmd-mode-map "" (quote cmd-execute)))

(defun cmd (arg) (interactive "P") (byte-code "? Ă1 !!	!!	\"/ 	!!O!@0 )!" [arg b nil cmd-goto 1 buffer-name generate-new-buffer "*cmd*" message sit-for string-match "<\\([0-9]*\\)>" read-from-string match-beginning match-end] 12))

(defun cmd-goto (arg) (interactive "p") (byte-code "ÈU Ƃ \"!	=\" d`T=\" db	=?0 
!=?5  " [arg major-mode cmd-shell nil switch-to-buffer 1 "*cmd*" format "*cmd*<%d>" cmd-mode process-status run] 5))

(defun cmd-start (&optional num) (byte-code "	 	\" ! !q ))" [buffer-name num format "*cmd*<%d>" "*cmd*" get-buffer generate-new-buffer cmd-mode] 5))

(defun cmd-rs6000 nil (interactive) (byte-code "!!" [cmd-rs6000-mode t nil cmd-send-shell "stty -nl" message "RS 6000 compatibility enabled"] 3))

(defun cmd-mode nil "\
Sorry, I don't believe in documentation, but here's the map:
\\{cmd-mode-map}" (byte-code " \"   ĉĉ҉ĉĉ!	
!։׉ !" [cmd-top-m cmd-prompt-m cmd-cmd-m cmd-history nil cmd-history-pointern cmd-history-count cmd-history-end cmd-redirection cmd-working-directory cmd-mode-map mode-name major-mode kill-all-local-variables mapcar make-local-variable (cmd-top-m cmd-prompt-m cmd-cmd-m cmd-shell cmd-redirection cmd-just-started cmd-working-directory cmd-history cmd-history-end cmd-history-count cmd-history-pointer) make-marker 0 getenv "HOME" use-local-map "Cmd" cmd-mode cmd-start-shell run-hooks cmd-mode-hook] 10))

(defun cmd-start-shell nil (byte-code " c BpC
C$\")ŉ	\"" [process-environment cmd-shell cmd-shell-name cmd-shell-args cmd-just-started t end-of-buffer "
*** Starting cmd process
" cmd-prompt "TERM=emacs" apply start-process append ("cmd") set-process-filter cmd-filter] 9))

(defun cmd-add-history (command) (byte-code "	BB @\" \") T3 @A\")" [new command nil cmd-history cmd-history-end cmd-history-count cmd-history-max rplacd /=] 5))

(defun cmd-set-history (hist command) (byte-code "@	\"" [hist command rplaca] 3))

(defun cmd-goto-history (hist) (byte-code "	d\"
P\"	d\"	b@@c!" [cmd-history-pointer cmd-cmd-m newline hist cmd-set-history buffer-substring delete-region delete-backward-char 1] 5))

(defun cmd-prompt nil (byte-code "`\"	`\"c
`\" @@\"\" !" [cmd-top-m cmd-prompt-m cmd-cmd-m cmd-history newline cmd-history-pointer set-marker ">" equal cmd-add-history] 7))

(defun cmd-execute nil (interactive) (byte-code " !! !
\"biVdbc`\"\"OF 	\"!O

G=b 

GSH\"l 
P
\"? GW H= HITy )\"  A
\" ! !-)" [cmd-pre-completion-configuration nil cmd-prompt-m cmd-cmd-m was-prompt command wsp first special cmd-specials arg newline n cmd-history set-window-configuration get-buffer "*Completions*" kill-buffer delete-region 0 "
" buffer-substring string-match "[ 	
]+" assoc match-end /= 10 equal cmd-set-history cmd-prompt funcall cmd-send-shell] 16))

(defun cmd-redirect (arg) (interactive "P") (byte-code " 	 	!! !U 	( !U p!P!	!\"!	!ed\"! d\"!" [arg cmd-redirection nil cmd-prompt-m switch-to-buffer-other-window other-window 1 message "Redirection is off" "Redirection turned off" get-buffer-create ">>" buffer-name format "Redirecting to buffer %s" delete-region make-local-variable make-marker set-marker] 16))

(defun cmd-send-shell (string) (interactive "sSend shell: ") (byte-code "È	\"
 	!" [cmd-shell string cmd-redirection nil process-send-string cmd-fake-output] 3))

(defun cmd-filter (process string) (byte-code "!q	 	q
bc
`\" ?2 \"2 !!OI ǉI 	P!)" [process cmd-redirection cmd-prompt-m string cmd-remember-working-directory cmd-working-directory cmd-just-started nil cmd-run-commands newline process-buffer set-marker string-match "current-directory-is \\([^
]*\\)" match-beginning 1 match-end cmd-send-shell] 8))

(defun cmd-cd (arg) (byte-code "O	 ÉR! Q!( \"Ç" [arg cmd-remember-working-directory cmd-working-directory nil newline cmd-cd-function 0 -1 cmd-send-shell "cd " "; echo current-directory-is `pwd" funcall] 5))

(defun cmd-dir-changing-command (cmd arg) (byte-code "O	 
%!ŉ\" 
R!Ň" [arg cmd-remember-working-directory cmd newline cmd-working-directory nil 0 -1 cmd-send-shell concat " " "; echo current-directory-is $cwd"] 7))

(defun cmd-get-cwd nil (byte-code " 
P9 db !!? !) !!8 !!\"P)" [cmd-remember-working-directory default-directory cmd-working-directory cmd-working-directory-regexp "/" beginning-of-line looking-at regexp-quote ">" forward-line -1 buffer-substring match-beginning 1 match-end] 11))

(defun cmd-in-input nil (byte-code "`Y" [cmd-cmd-m] 2))

(defun narrow nil (byte-code " 	 d\"" [cmd-cmd-m cmd-in-input narrow-to-region] 4))

(defun cmd-delete-char (arg) (interactive "p") (byte-code "`U	 l ! 	!" [cmd-cmd-m arg nil cmd-send-shell "" delete-char] 3))

(defun cmd-delete-backward-char (arg) (interactive "p") (byte-code " Î!)" [arg nil narrow ((byte-code " " [widen] 2)) backward-delete-char-untabify] 3))

(defun cmd-beginning-of-line (arg) (interactive "p") (byte-code "U
  Ď!)" [arg nil 1 narrow ((byte-code " " [widen] 2)) beginning-of-line] 3))

(defun cmd-backward-kill-word (arg) (interactive "p") (byte-code " Î!)" [arg nil narrow ((byte-code " " [widen] 2)) backward-kill-word] 3))

(defun cmd-copy-output-as-kill nil (interactive) (byte-code "  	\"  " [cmd-top-m cmd-prompt-m nil cmd-in-input copy-region-as-kill append-next-kill] 4))

(defun cmd-previous-history (arg) (interactive "p") (byte-code "È=
   
A	 	!) !" [arg prev cmd-history-pointer nil 1 cmd-in-input cmd-goto-history previous-line] 4))

(defun cmd-next-history (arg) (interactive "p") (byte-code "È=
   
@A	 	!) !" [arg next cmd-history-pointer nil 1 cmd-in-input cmd-goto-history next-line] 4))

(defun cmd-recenter (arg) (interactive "P") (byte-code "	  ? !2  !Z!	2 	!  !Z!!" [arg cmd-redirection nil cmd-in-input recenter window-height selected-window 2 switch-to-buffer-other-window end-of-buffer other-window 1] 12))

(defun cmd-stop-process nil (interactive) (byte-code "  !  " [nil cmd-in-input cmd-send-shell "" suspend-emacs] 4))

(defun cmd-interrupt-process nil (interactive) (byte-code " 	! !" [cmd-rs6000-mode cmd-shell nil interrupt-process cmd-send-shell ""] 3))

(defun cmd-find-file nil (interactive) (byte-code " !" [nil cmd-get-cwd call-interactively find-file] 3))

(defun cmd-find-file-read-only nil (interactive) (byte-code " !" [nil cmd-get-cwd call-interactively find-file-read-only] 3))

(defun cmd-completion nil (interactive) (byte-code "͈ `  #' `Tb`\"`	b	#A `Tb)`\"
	P!!\"O	OR!	O\"
? !b 
A? 
@  	
\"\" ?  !q   !!! c
 
@c
A
 !
@cc
A !!qb`\"c." [p word comps filespec wordstart wordpoint replacement wind cmd-cmd-m temp default-directory t cmd-pre-completion-configuration nil cmd-get-cwd make-marker widen re-search-backward "[> 	]" 1000 buffer-substring search-backward "/" foo set-marker expand-file-name substitute-in-file-name string-match "[^/]*$" message "Completing " " in directory " 0 file-name-all-completions "No completions." selected-window try-completion mapcar list one-window-p get-buffer-create "*Completions*" current-window-configuration split-window other-window 1 switch-to-buffer erase-buffer "Possible completions are:
" indent-to-column 40 "
" select-window marker-buffer delete-region] 30))

(defun cmd-fake-output (str) (byte-code "	\"" [cmd-shell str cmd-filter] 3))

(defun cmd-compose-mode (send-func) (byte-code "! \"DF \"DF \"DF	E& E\"# BFF#) #" [sendit send-func nil message "Press C-d at the end to send the message..." list (delete-region cmd-prompt-m cmd-cmd-m) define-key (current-local-map) "
" quote lookup-key current-local-map (current-local-map) "" (current-local-map) "" (insert "
") (goto-char (point-max)) cmd-cmd-m (point) append lambda (interactive) (arg) (interactive "p") if (= (point) (point-max)) progn (delete-char arg) newline] 22))

(defun cmd-man (arg) (byte-code "!	O!" [newline arg nil cmd-send-shell man 0 -1] 5))

(defun cmd-no-go (arg) (byte-code "!" [t cmd-fake-output "You really, really don't want to do that.
"] 2))

(defun cmd-set-cwd (arg) (byte-code " A@q	)P!)" [wd default-directory t nil buffer-list cmd-send-shell "cd "] 4))

(defun cmd-emacs (arg) (byte-code "!" [arg cmd-no-go] 2))

(defun cmd-more (arg) (byte-code " !	O	GV+ 	H=?# 
	P	!ĉŇ" [newline arg default-directory buffer-read-only t nil cmd-get-cwd cmd-send-shell 0 -1 47 find-file-other-window] 5))

(defun cmd-read-password nil (interactive) (byte-code "	?Z !r= ĉU =3 GV0 OU V< WJ \"PU ĉ) e P!*" [password done nil key t unread-command-char newline "" message "Enter password: " 13 127 0 -1 32 make-string 1 cmd-send-shell] 6))

(defun cmd-su (arg &optional program) (byte-code " 	Q! ÉÇ" [program arg cmd-just-started t cmd-send-shell "su" " " cmd-read-password] 4))

(defun setenv (var value) (byte-code "	P!	Q
 
@\"?3 
A
* 
\"/ B +" [prefix var env process-environment entry value regexp-quote "=" string-match rplaca] 6))
