comparison lisp/term.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 2f877ed80fa6
children d8411455de48
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
656 (put 'term-input-filter-functions 'permanent-local t) 656 (put 'term-input-filter-functions 'permanent-local t)
657 (put 'term-scroll-to-bottom-on-output 'permanent-local t) 657 (put 'term-scroll-to-bottom-on-output 'permanent-local t)
658 (put 'term-scroll-show-maximum-output 'permanent-local t) 658 (put 'term-scroll-show-maximum-output 'permanent-local t)
659 (put 'term-ptyp 'permanent-local t) 659 (put 'term-ptyp 'permanent-local t)
660 660
661 ;; True if running under XEmacs (previously Lucid Emacs).
662 (defmacro term-is-xemacs () '(string-match "Lucid" emacs-version))
663 ;; Do FORM if running under XEmacs (previously Lucid Emacs). 661 ;; Do FORM if running under XEmacs (previously Lucid Emacs).
664 (defmacro term-if-xemacs (&rest forms) 662 (defmacro term-if-xemacs (&rest forms)
665 (if (term-is-xemacs) (cons 'progn forms))) 663 (if (featurep 'xemacs) (cons 'progn forms)))
666 ;; Do FORM if NOT running under XEmacs (previously Lucid Emacs). 664 ;; Do FORM if NOT running under XEmacs (previously Lucid Emacs).
667 (defmacro term-ifnot-xemacs (&rest forms) 665 (defmacro term-ifnot-xemacs (&rest forms)
668 (if (not (term-is-xemacs)) (cons 'progn forms))) 666 (if (not (featurep 'xemacs)) (cons 'progn forms)))
669 667
670 (defmacro term-in-char-mode () '(eq (current-local-map) term-raw-map)) 668 (defmacro term-in-char-mode () '(eq (current-local-map) term-raw-map))
671 (defmacro term-in-line-mode () '(not (term-in-char-mode))) 669 (defmacro term-in-line-mode () '(not (term-in-char-mode)))
672 ;; True if currently doing PAGER handling. 670 ;; True if currently doing PAGER handling.
673 (defmacro term-pager-enabled () 'term-pager-count) 671 (defmacro term-pager-enabled () 'term-pager-count)
919 (define-key term-raw-map [end] 'term-send-end) 917 (define-key term-raw-map [end] 'term-send-end)
920 (define-key term-raw-map [prior] 'term-send-prior) 918 (define-key term-raw-map [prior] 'term-send-prior)
921 (define-key term-raw-map [next] 'term-send-next))) 919 (define-key term-raw-map [next] 'term-send-next)))
922 920
923 (term-set-escape-char ?\C-c) 921 (term-set-escape-char ?\C-c)
922
923 (defun term-window-width ()
924 (if (featurep 'xemacs)
925 (1- (window-width))
926 (if window-system
927 (window-width)
928 (1- (window-width)))))
929
924 930
925 (put 'term-mode 'mode-class 'special) 931 (put 'term-mode 'mode-class 'special)
926 932
927 (defun term-mode () 933 (defun term-mode ()
928 "Major mode for interacting with an inferior interpreter. 934 "Major mode for interacting with an inferior interpreter.
976 (make-local-variable 'term-home-marker) 982 (make-local-variable 'term-home-marker)
977 (setq term-home-marker (copy-marker 0)) 983 (setq term-home-marker (copy-marker 0))
978 (make-local-variable 'term-saved-home-marker) 984 (make-local-variable 'term-saved-home-marker)
979 (make-local-variable 'term-height) 985 (make-local-variable 'term-height)
980 (make-local-variable 'term-width) 986 (make-local-variable 'term-width)
981 (setq term-width (1- (window-width))) 987 (setq term-width (term-window-width))
982 (setq term-height (1- (window-height))) 988 (setq term-height (1- (window-height)))
989 (term-ifnot-xemacs
990 (set (make-local-variable 'overflow-newline-into-fringe) nil))
983 (make-local-variable 'term-terminal-parameter) 991 (make-local-variable 'term-terminal-parameter)
984 (make-local-variable 'term-saved-cursor) 992 (make-local-variable 'term-saved-cursor)
985 (make-local-variable 'term-last-input-start) 993 (make-local-variable 'term-last-input-start)
986 (setq term-last-input-start (make-marker)) 994 (setq term-last-input-start (make-marker))
987 (make-local-variable 'term-last-input-end) 995 (make-local-variable 'term-last-input-end)
1112 (goto-char save-point))) 1120 (goto-char save-point)))
1113 found)) 1121 found))
1114 1122
1115 (defun term-check-size (process) 1123 (defun term-check-size (process)
1116 (if (or (/= term-height (1- (window-height))) 1124 (if (or (/= term-height (1- (window-height)))
1117 (/= term-width (1- (window-width)))) 1125 (/= term-width (term-window-width)))
1118 (progn 1126 (progn
1119 (term-reset-size (1- (window-height)) (1- (window-width))) 1127 (term-reset-size (1- (window-height)) (term-window-width))
1120 (set-process-window-size process term-height term-width)))) 1128 (set-process-window-size process term-height term-width))))
1121 1129
1122 (defun term-send-raw-string (chars) 1130 (defun term-send-raw-string (chars)
1123 (let ((proc (get-buffer-process (current-buffer)))) 1131 (let ((proc (get-buffer-process (current-buffer))))
1124 (if (not proc) 1132 (if (not proc)
1168 (error "No selection or cut buffer available")))) 1176 (error "No selection or cut buffer available"))))
1169 (term-ifnot-xemacs 1177 (term-ifnot-xemacs
1170 ;; Give temporary modes such as isearch a chance to turn off. 1178 ;; Give temporary modes such as isearch a chance to turn off.
1171 (run-hooks 'mouse-leave-buffer-hook) 1179 (run-hooks 'mouse-leave-buffer-hook)
1172 (setq this-command 'yank) 1180 (setq this-command 'yank)
1181 (mouse-set-point click)
1173 (term-send-raw-string (current-kill (cond 1182 (term-send-raw-string (current-kill (cond
1174 ((listp arg) 0) 1183 ((listp arg) 0)
1175 ((eq arg '-) -1) 1184 ((eq arg '-) -1)
1176 (t (1- arg))))))) 1185 (t (1- arg)))))))
1177 1186
1286 (setq term-ptyp process-connection-type) ; t if pty, nil if pipe. 1295 (setq term-ptyp process-connection-type) ; t if pty, nil if pipe.
1287 ;; Jump to the end, and set the process mark. 1296 ;; Jump to the end, and set the process mark.
1288 (goto-char (point-max)) 1297 (goto-char (point-max))
1289 (set-marker (process-mark proc) (point)) 1298 (set-marker (process-mark proc) (point))
1290 (set-process-filter proc 'term-emulate-terminal) 1299 (set-process-filter proc 'term-emulate-terminal)
1300 (set-process-sentinel proc 'term-sentinel)
1291 ;; Feed it the startfile. 1301 ;; Feed it the startfile.
1292 (cond (startfile 1302 (cond (startfile
1293 ;;This is guaranteed to wait long enough 1303 ;;This is guaranteed to wait long enough
1294 ;;but has bad results if the term does not prompt at all 1304 ;;but has bad results if the term does not prompt at all
1295 ;; (while (= size (buffer-size)) 1305 ;; (while (= size (buffer-size))
1301 (setq startfile (buffer-substring (point) (point-max))) 1311 (setq startfile (buffer-substring (point) (point-max)))
1302 (delete-region (point) (point-max)) 1312 (delete-region (point) (point-max))
1303 (term-send-string proc startfile))) 1313 (term-send-string proc startfile)))
1304 (run-hooks 'term-exec-hook) 1314 (run-hooks 'term-exec-hook)
1305 buffer))) 1315 buffer)))
1316
1317 (defun term-sentinel (proc msg)
1318 "Sentinel for term buffers.
1319 The main purpose is to get rid of the local keymap."
1320 (let ((buffer (process-buffer proc)))
1321 (if (memq (process-status proc) '(signal exit))
1322 (progn
1323 (if (null (buffer-name buffer))
1324 ;; buffer killed
1325 (set-process-buffer proc nil)
1326 (let ((obuf (current-buffer)))
1327 ;; save-excursion isn't the right thing if
1328 ;; process-buffer is current-buffer
1329 (unwind-protect
1330 (progn
1331 ;; Write something in the compilation buffer
1332 ;; and hack its mode line.
1333 (set-buffer buffer)
1334 ;; Get rid of local keymap.
1335 (use-local-map nil)
1336 (term-handle-exit (process-name proc)
1337 msg)
1338 ;; Since the buffer and mode line will show that the
1339 ;; process is dead, we can delete it now. Otherwise it
1340 ;; will stay around until M-x list-processes.
1341 (delete-process proc))
1342 (set-buffer obuf))))
1343 ))))
1344
1345 (defun term-handle-exit (process-name msg)
1346 "Write process exit (or other change) message MSG in the current buffer."
1347 (let ((buffer-read-only nil)
1348 (omax (point-max))
1349 (opoint (point)))
1350 ;; Record where we put the message, so we can ignore it
1351 ;; later on.
1352 (goto-char omax)
1353 (insert ?\n "Process " process-name " " msg)
1354 ;; Force mode line redisplay soon.
1355 (force-mode-line-update)
1356 (if (and opoint (< opoint omax))
1357 (goto-char opoint))))
1358
1306 1359
1307 ;;; Name to use for TERM. 1360 ;;; Name to use for TERM.
1308 ;;; Using "emacs" loses, because bash disables editing if TERM == emacs. 1361 ;;; Using "emacs" loses, because bash disables editing if TERM == emacs.
1309 (defvar term-term-name "eterm") 1362 (defvar term-term-name "eterm")
1310 ; Format string, usage: 1363 ; Format string, usage:
1343 (format "COLUMNS=%d" term-width)) 1396 (format "COLUMNS=%d" term-width))
1344 process-environment)) 1397 process-environment))
1345 (process-connection-type t) 1398 (process-connection-type t)
1346 ;; We should suppress conversion of end-of-line format. 1399 ;; We should suppress conversion of end-of-line format.
1347 (inhibit-eol-conversion t) 1400 (inhibit-eol-conversion t)
1401 ;; inhibit-eol-conversion doesn't seem to do the job, but this does.
1402 (coding-system-for-read 'unknown-unix)
1348 ) 1403 )
1349 (apply 'start-process name buffer 1404 (apply 'start-process name buffer
1350 "/bin/sh" "-c" 1405 "/bin/sh" "-c"
1351 (format "stty -nl echo rows %d columns %d sane 2>/dev/null;\ 1406 (format "stty -nl echo rows %d columns %d sane 2>/dev/null;\
1352 if [ $1 = .. ]; then shift; fi; exec \"$@\"" 1407 if [ $1 = .. ]; then shift; fi; exec \"$@\""
4016 ;;; You could use term-dynamic-simple-complete to do the bulk of the 4071 ;;; You could use term-dynamic-simple-complete to do the bulk of the
4017 ;;; completion job. 4072 ;;; completion job.
4018 4073
4019 (provide 'term) 4074 (provide 'term)
4020 4075
4076 ;;; arch-tag: eee16bc8-2cd7-4147-9534-a5694752f716
4021 ;;; term.el ends here 4077 ;;; term.el ends here