comparison lisp/term.el @ 77169:8905fec7d280

(term-buffer-maximum-size, term-exec, term-escape-char, term-set-escape-char, term-termcap-format, term-get-old-input-default, term-skip-prompt, term-send-string, term-send-region, term-pager-page, term-pager-help): Fix typos in docstrings.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 13 Apr 2007 09:00:41 +0000
parents e3694f1cb928
children 9355f9b7bbff e6fdae9180d4
comparison
equal deleted inserted replaced
77168:ca9024ba3582 77169:8905fec7d280
625 (defvar term-mode-map nil) 625 (defvar term-mode-map nil)
626 (defvar term-raw-map nil 626 (defvar term-raw-map nil
627 "Keyboard map for sending characters directly to the inferior process.") 627 "Keyboard map for sending characters directly to the inferior process.")
628 (defvar term-escape-char nil 628 (defvar term-escape-char nil
629 "Escape character for char sub-mode of term mode. 629 "Escape character for char sub-mode of term mode.
630 Do not change it directly; use `term-set-escape-char' instead.") 630 Do not change it directly; use `term-set-escape-char' instead.")
631 (defvar term-raw-escape-map nil) 631 (defvar term-raw-escape-map nil)
632 632
633 (defvar term-pager-break-map nil) 633 (defvar term-pager-break-map nil)
634 634
635 (defvar term-ptyp t 635 (defvar term-ptyp t
712 712
713 ;;; Inspiration came from comint.el -mm 713 ;;; Inspiration came from comint.el -mm
714 (defvar term-buffer-maximum-size 2048 714 (defvar term-buffer-maximum-size 2048
715 "*The maximum size in lines for term buffers. 715 "*The maximum size in lines for term buffers.
716 Term buffers are truncated from the top to be no greater than this number. 716 Term buffers are truncated from the top to be no greater than this number.
717 Notice that a setting of 0 means 'don't truncate anything'. This variable 717 Notice that a setting of 0 means \"don't truncate anything\". This variable
718 is buffer-local.") 718 is buffer-local.")
719 ;;; 719 ;;;
720 720
721 (when (featurep 'xemacs) 721 (when (featurep 'xemacs)
722 (defvar term-terminal-menu 722 (defvar term-terminal-menu
854 )) 854 ))
855 855
856 ;; Set up term-raw-map, etc. 856 ;; Set up term-raw-map, etc.
857 857
858 (defun term-set-escape-char (c) 858 (defun term-set-escape-char (c)
859 "Change term-escape-char and keymaps that depend on it." 859 "Change `term-escape-char' and keymaps that depend on it."
860 (when term-escape-char 860 (when term-escape-char
861 (define-key term-raw-map term-escape-char 'term-send-raw)) 861 (define-key term-raw-map term-escape-char 'term-send-raw))
862 (setq c (make-string 1 c)) 862 (setq c (make-string 1 c))
863 (define-key term-raw-map c term-raw-escape-map) 863 (define-key term-raw-map c term-raw-escape-map)
864 ;; Define standard bindings in term-raw-escape-map 864 ;; Define standard bindings in term-raw-escape-map
1098 (make-local-variable 'term-pending-delete-marker) 1098 (make-local-variable 'term-pending-delete-marker)
1099 (setq term-pending-delete-marker (make-marker)) 1099 (setq term-pending-delete-marker (make-marker))
1100 (make-local-variable 'term-current-face) 1100 (make-local-variable 'term-current-face)
1101 (make-local-variable 'term-pending-frame) 1101 (make-local-variable 'term-pending-frame)
1102 (setq term-pending-frame nil) 1102 (setq term-pending-frame nil)
1103 ;; Cua-mode's keybindings interfere with the term keybindings, disable it. 1103 ;; Cua-mode's keybindings interfere with the term keybindings, disable it.
1104 (set (make-local-variable 'cua-mode) nil) 1104 (set (make-local-variable 'cua-mode) nil)
1105 (run-mode-hooks 'term-mode-hook) 1105 (run-mode-hooks 'term-mode-hook)
1106 (when (featurep 'xemacs) 1106 (when (featurep 'xemacs)
1107 (set-buffer-menubar 1107 (set-buffer-menubar
1108 (append current-menubar (list term-terminal-menu)))) 1108 (append current-menubar (list term-terminal-menu))))
1194 1194
1195 (defun term-mouse-paste (click arg) 1195 (defun term-mouse-paste (click arg)
1196 "Insert the last stretch of killed text at the position clicked on." 1196 "Insert the last stretch of killed text at the position clicked on."
1197 (interactive "e\nP") 1197 (interactive "e\nP")
1198 (if (featurep 'xemacs) 1198 (if (featurep 'xemacs)
1199 (term-send-raw-string 1199 (term-send-raw-string
1200 (or (condition-case () (x-get-selection) (error ())) 1200 (or (condition-case () (x-get-selection) (error ()))
1201 (x-get-cutbuffer) 1201 (x-get-cutbuffer)
1202 (error "No selection or cut buffer available"))) 1202 (error "No selection or cut buffer available")))
1203 ;; Give temporary modes such as isearch a chance to turn off. 1203 ;; Give temporary modes such as isearch a chance to turn off.
1204 (run-hooks 'mouse-leave-buffer-hook) 1204 (run-hooks 'mouse-leave-buffer-hook)
1312 1312
1313 (defun term-exec (buffer name command startfile switches) 1313 (defun term-exec (buffer name command startfile switches)
1314 "Start up a process in buffer for term modes. 1314 "Start up a process in buffer for term modes.
1315 Blasts any old process running in the buffer. Doesn't set the buffer mode. 1315 Blasts any old process running in the buffer. Doesn't set the buffer mode.
1316 You can use this to cheaply run a series of processes in the same term 1316 You can use this to cheaply run a series of processes in the same term
1317 buffer. The hook term-exec-hook is run after each exec." 1317 buffer. The hook `term-exec-hook' is run after each exec."
1318 (save-excursion 1318 (save-excursion
1319 (set-buffer buffer) 1319 (set-buffer buffer)
1320 (let ((proc (get-buffer-process buffer))) ; Blast any old process. 1320 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
1321 (when proc (delete-process proc))) 1321 (when proc (delete-process proc)))
1322 ;; Crank up a new process 1322 ;; Crank up a new process
1342 (delete-region (point) (point-max)) 1342 (delete-region (point) (point-max))
1343 (term-send-string proc startfile))) 1343 (term-send-string proc startfile)))
1344 (run-hooks 'term-exec-hook) 1344 (run-hooks 'term-exec-hook)
1345 buffer))) 1345 buffer)))
1346 1346
1347 (defun term-sentinel (proc msg) 1347 (defun term-sentinel (proc msg)
1348 "Sentinel for term buffers. 1348 "Sentinel for term buffers.
1349 The main purpose is to get rid of the local keymap." 1349 The main purpose is to get rid of the local keymap."
1350 (let ((buffer (process-buffer proc))) 1350 (let ((buffer (process-buffer proc)))
1351 (when (memq (process-status proc) '(signal exit)) 1351 (when (memq (process-status proc) '(signal exit))
1352 (if (null (buffer-name buffer)) 1352 (if (null (buffer-name buffer))
1402 :mk=\\E[8m:cb=\\E[1K:op=\\E[39;49m:Co#8:pa#64:AB=\\E[4%%dm:AF=\\E[3%%dm:cr=^M\ 1402 :mk=\\E[8m:cb=\\E[1K:op=\\E[39;49m:Co#8:pa#64:AB=\\E[4%%dm:AF=\\E[3%%dm:cr=^M\
1403 :bl=^G:do=^J:le=^H:ta=^I:se=\\E[27m:ue=\\E24m\ 1403 :bl=^G:do=^J:le=^H:ta=^I:se=\\E[27m:ue=\\E24m\
1404 :kb=^?:kD=^[[3~:sc=\\E7:rc=\\E8:r1=\\Ec:" 1404 :kb=^?:kD=^[[3~:sc=\\E7:rc=\\E8:r1=\\Ec:"
1405 ;;; : -undefine ic 1405 ;;; : -undefine ic
1406 ;;; don't define :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\ 1406 ;;; don't define :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\
1407 "termcap capabilities supported") 1407 "Termcap capabilities supported.")
1408 1408
1409 ;;; This auxiliary function cranks up the process for term-exec in 1409 ;;; This auxiliary function cranks up the process for term-exec in
1410 ;;; the appropriate environment. 1410 ;;; the appropriate environment.
1411 1411
1412 (defun term-exec-1 (name buffer command switches) 1412 (defun term-exec-1 (name buffer command switches)
2044 (set-marker (process-mark proc) (point))) 2044 (set-marker (process-mark proc) (point)))
2045 (goto-char pmark) 2045 (goto-char pmark)
2046 (funcall term-input-sender proc input))))) 2046 (funcall term-input-sender proc input)))))
2047 2047
2048 (defun term-get-old-input-default () 2048 (defun term-get-old-input-default ()
2049 "Default for term-get-old-input. 2049 "Default for `term-get-old-input'.
2050 Take the current line, and discard any initial text matching 2050 Take the current line, and discard any initial text matching
2051 term-prompt-regexp." 2051 `term-prompt-regexp'."
2052 (save-excursion 2052 (save-excursion
2053 (beginning-of-line) 2053 (beginning-of-line)
2054 (term-skip-prompt) 2054 (term-skip-prompt)
2055 (let ((beg (point))) 2055 (let ((beg (point)))
2056 (end-of-line) 2056 (end-of-line)
2066 (error "Current buffer has no process") 2066 (error "Current buffer has no process")
2067 (goto-char (process-mark process)) 2067 (goto-char (process-mark process))
2068 (insert input)))) 2068 (insert input))))
2069 2069
2070 (defun term-skip-prompt () 2070 (defun term-skip-prompt ()
2071 "Skip past the text matching regexp term-prompt-regexp. 2071 "Skip past the text matching regexp `term-prompt-regexp'.
2072 If this takes us past the end of the current line, don't skip at all." 2072 If this takes us past the end of the current line, don't skip at all."
2073 (let ((eol (save-excursion (end-of-line) (point)))) 2073 (let ((eol (save-excursion (end-of-line) (point))))
2074 (when (and (looking-at term-prompt-regexp) 2074 (when (and (looking-at term-prompt-regexp)
2075 (<= (match-end 0) eol)) 2075 (<= (match-end 0) eol))
2076 (goto-char (match-end 0))))) 2076 (goto-char (match-end 0)))))
2097 "Goes to the beginning of line, then skips past the prompt, if any. 2097 "Goes to the beginning of line, then skips past the prompt, if any.
2098 If a prefix argument is given (\\[universal-argument]), then no prompt skip 2098 If a prefix argument is given (\\[universal-argument]), then no prompt skip
2099 -- go straight to column 0. 2099 -- go straight to column 0.
2100 2100
2101 The prompt skip is done by skipping text matching the regular expression 2101 The prompt skip is done by skipping text matching the regular expression
2102 term-prompt-regexp, a buffer local variable." 2102 `term-prompt-regexp', a buffer local variable."
2103 (interactive "P") 2103 (interactive "P")
2104 (beginning-of-line) 2104 (beginning-of-line)
2105 (when (null arg) (term-skip-prompt))) 2105 (when (null arg) (term-skip-prompt)))
2106 2106
2107 ;;; These two functions are for entering text you don't want echoed or 2107 ;;; These two functions are for entering text you don't want echoed or
2180 "*Long inputs send to term processes are broken up into chunks of this size. 2180 "*Long inputs send to term processes are broken up into chunks of this size.
2181 If your process is choking on big inputs, try lowering the value.") 2181 If your process is choking on big inputs, try lowering the value.")
2182 2182
2183 (defun term-send-string (proc str) 2183 (defun term-send-string (proc str)
2184 "Send to PROC the contents of STR as input. 2184 "Send to PROC the contents of STR as input.
2185 This is equivalent to process-send-string, except that long input strings 2185 This is equivalent to `process-send-string', except that long input strings
2186 are broken up into chunks of size term-input-chunk-size. Processes 2186 are broken up into chunks of size `term-input-chunk-size'. Processes
2187 are given a chance to output between chunks. This can help prevent processes 2187 are given a chance to output between chunks. This can help prevent processes
2188 from hanging when you send them long inputs on some OS's." 2188 from hanging when you send them long inputs on some OS's."
2189 (let* ((len (length str)) 2189 (let* ((len (length str))
2190 (i (min len term-input-chunk-size))) 2190 (i (min len term-input-chunk-size)))
2191 (process-send-string proc (substring str 0 i)) 2191 (process-send-string proc (substring str 0 i))
2195 (process-send-string proc (substring str i (min len next-i))) 2195 (process-send-string proc (substring str i (min len next-i)))
2196 (setq i next-i))))) 2196 (setq i next-i)))))
2197 2197
2198 (defun term-send-region (proc start end) 2198 (defun term-send-region (proc start end)
2199 "Send to PROC the region delimited by START and END. 2199 "Send to PROC the region delimited by START and END.
2200 This is a replacement for process-send-region that tries to keep 2200 This is a replacement for `process-send-region' that tries to keep
2201 your process from hanging on long inputs. See `term-send-string'." 2201 your process from hanging on long inputs. See `term-send-string'."
2202 (term-send-string proc (buffer-substring start end))) 2202 (term-send-string proc (buffer-substring start end)))
2203 2203
2204 2204
2205 ;;; Random input hackage 2205 ;;; Random input hackage
2874 ;; (term-down 1) 2874 ;; (term-down 1)
2875 ;; (term-goto term-current-row 0) 2875 ;; (term-goto term-current-row 0)
2876 ;; (setq term-terminal-state 0)) 2876 ;; (setq term-terminal-state 0))
2877 ((eq char ?M) ;; scroll reversed (terminfo: ri) 2877 ((eq char ?M) ;; scroll reversed (terminfo: ri)
2878 (if (or (< (term-current-row) term-scroll-start) 2878 (if (or (< (term-current-row) term-scroll-start)
2879 (>= (1- (term-current-row)) 2879 (>= (1- (term-current-row))
2880 term-scroll-start)) 2880 term-scroll-start))
2881 ;; Scrolling up will not move outside 2881 ;; Scrolling up will not move outside
2882 ;; the scroll region. 2882 ;; the scroll region.
2883 (term-down -1) 2883 (term-down -1)
2884 ;; Scrolling the scroll region is needed. 2884 ;; Scrolling the scroll region is needed.
2900 (setq term-terminal-state 0)) 2900 (setq term-terminal-state 0))
2901 ((eq char ?8) ;; Restore cursor (terminfo: rc) 2901 ((eq char ?8) ;; Restore cursor (terminfo: rc)
2902 (when term-saved-cursor 2902 (when term-saved-cursor
2903 (term-goto (nth 0 term-saved-cursor) 2903 (term-goto (nth 0 term-saved-cursor)
2904 (nth 1 term-saved-cursor)) 2904 (nth 1 term-saved-cursor))
2905 (setq term-ansi-current-bg-color 2905 (setq term-ansi-current-bg-color
2906 (nth 2 term-saved-cursor) 2906 (nth 2 term-saved-cursor)
2907 term-ansi-current-bold 2907 term-ansi-current-bold
2908 (nth 3 term-saved-cursor) 2908 (nth 3 term-saved-cursor)
2909 term-ansi-current-color 2909 term-ansi-current-color
2910 (nth 4 term-saved-cursor) 2910 (nth 4 term-saved-cursor)
3188 (setq term-current-face 3188 (setq term-current-face
3189 (append '(:weight bold) term-current-face))) 3189 (append '(:weight bold) term-current-face)))
3190 (when term-ansi-current-underline 3190 (when term-ansi-current-underline
3191 (setq term-current-face 3191 (setq term-current-face
3192 (append '(:underline t) term-current-face)))))) 3192 (append '(:underline t) term-current-face))))))
3193 3193
3194 ;;; (message "Debug %S" term-current-face) 3194 ;;; (message "Debug %S" term-current-face)
3195 (setq term-ansi-face-already-done nil)) 3195 (setq term-ansi-face-already-done nil))
3196 3196
3197 3197
3198 ;;; Handle a character assuming (eq terminal-state 2) - 3198 ;;; Handle a character assuming (eq terminal-state 2) -
3217 (1- term-terminal-parameter))) 3217 (1- term-terminal-parameter)))
3218 ;; \E[A - cursor up (terminfo: cuu, cuu1) 3218 ;; \E[A - cursor up (terminfo: cuu, cuu1)
3219 ((eq char ?A) 3219 ((eq char ?A)
3220 (term-handle-deferred-scroll) 3220 (term-handle-deferred-scroll)
3221 (let ((tcr (term-current-row))) 3221 (let ((tcr (term-current-row)))
3222 (term-down 3222 (term-down
3223 (if (< (- tcr term-terminal-parameter) term-scroll-start) 3223 (if (< (- tcr term-terminal-parameter) term-scroll-start)
3224 ;; If the amount to move is before scroll start, move 3224 ;; If the amount to move is before scroll start, move
3225 ;; to scroll start. 3225 ;; to scroll start.
3226 (- term-scroll-start tcr) 3226 (- term-scroll-start tcr)
3227 (if (>= term-terminal-parameter tcr) 3227 (if (>= term-terminal-parameter tcr)
3229 (- (max 1 term-terminal-parameter)))) t))) 3229 (- (max 1 term-terminal-parameter)))) t)))
3230 ;; \E[B - cursor down (terminfo: cud) 3230 ;; \E[B - cursor down (terminfo: cud)
3231 ((eq char ?B) 3231 ((eq char ?B)
3232 (let ((tcr (term-current-row))) 3232 (let ((tcr (term-current-row)))
3233 (unless (= tcr (1- term-scroll-end)) 3233 (unless (= tcr (1- term-scroll-end))
3234 (term-down 3234 (term-down
3235 (if (> (+ tcr term-terminal-parameter) term-scroll-end) 3235 (if (> (+ tcr term-terminal-parameter) term-scroll-end)
3236 (- term-scroll-end 1 tcr) 3236 (- term-scroll-end 1 tcr)
3237 (max 1 term-terminal-parameter)) t)))) 3237 (max 1 term-terminal-parameter)) t))))
3238 ;; \E[C - cursor right (terminfo: cuf, cuf1) 3238 ;; \E[C - cursor right (terminfo: cuf, cuf1)
3239 ((eq char ?C) 3239 ((eq char ?C)
3493 (cond ((<= deficit 0) ;; OK, had enough in the buffer for request. 3493 (cond ((<= deficit 0) ;; OK, had enough in the buffer for request.
3494 (recenter (1- term-height))) 3494 (recenter (1- term-height)))
3495 ((term-pager-continue deficit))))) 3495 ((term-pager-continue deficit)))))
3496 3496
3497 (defun term-pager-page (arg) 3497 (defun term-pager-page (arg)
3498 "Proceed past the **MORE** break, allowing the next page of output to appear" 3498 "Proceed past the **MORE** break, allowing the next page of output to appear."
3499 (interactive "p") 3499 (interactive "p")
3500 (term-pager-line (* arg term-height))) 3500 (term-pager-line (* arg term-height)))
3501 3501
3502 ; Pager mode command to go to beginning of buffer 3502 ; Pager mode command to go to beginning of buffer
3503 (defun term-pager-bob () 3503 (defun term-pager-bob ()
3562 (put 'term-line-mode 'menu-enable '(term-in-char-mode)) 3562 (put 'term-line-mode 'menu-enable '(term-in-char-mode))
3563 (put 'term-fake-pager-enable 'menu-enable '(not term-pager-count)) 3563 (put 'term-fake-pager-enable 'menu-enable '(not term-pager-count))
3564 (put 'term-fake-pager-disable 'menu-enable 'term-pager-count)) 3564 (put 'term-fake-pager-disable 'menu-enable 'term-pager-count))
3565 3565
3566 (defun term-pager-help () 3566 (defun term-pager-help ()
3567 "Provide help on commands available in a terminal-emulator **MORE** break" 3567 "Provide help on commands available in a terminal-emulator **MORE** break."
3568 (interactive) 3568 (interactive)
3569 (message "Terminal-emulator pager break help...") 3569 (message "Terminal-emulator pager break help...")
3570 (sit-for 0) 3570 (sit-for 0)
3571 (with-electric-help 3571 (with-electric-help
3572 (function (lambda () 3572 (function (lambda ()
3604 ;; Make sure there are DOWN blank lines below the current one. 3604 ;; Make sure there are DOWN blank lines below the current one.
3605 ;; Return 0 if we're unable (because of PAGER handling), else return DOWN. 3605 ;; Return 0 if we're unable (because of PAGER handling), else return DOWN.
3606 3606
3607 (defun term-handle-scroll (down) 3607 (defun term-handle-scroll (down)
3608 (let ((scroll-needed 3608 (let ((scroll-needed
3609 (- (+ (term-current-row) down) 3609 (- (+ (term-current-row) down)
3610 (if (< down 0) term-scroll-start term-scroll-end)))) 3610 (if (< down 0) term-scroll-start term-scroll-end))))
3611 (when (or (and (< down 0) (< scroll-needed 0)) 3611 (when (or (and (< down 0) (< scroll-needed 0))
3612 (and (> down 0) (> scroll-needed 0))) 3612 (and (> down 0) (> scroll-needed 0)))
3613 (let ((save-point (copy-marker (point))) (save-top)) 3613 (let ((save-point (copy-marker (point))) (save-top))
3614 (goto-char term-home-marker) 3614 (goto-char term-home-marker)
3615 (cond (term-scroll-with-delete 3615 (cond (term-scroll-with-delete
3616 (if (< down 0) 3616 (if (< down 0)
3704 ;; the previous screen line rather then the beginning of the 3704 ;; the previous screen line rather then the beginning of the
3705 ;; current one. To avoid that, we make sure that current line 3705 ;; current one. To avoid that, we make sure that current line
3706 ;; contain a space, to force the previous line to continue to wrap. 3706 ;; contain a space, to force the previous line to continue to wrap.
3707 ;; We could do this always, but it seems preferable to not add the 3707 ;; We could do this always, but it seems preferable to not add the
3708 ;; extra space when wrapped is false. 3708 ;; extra space when wrapped is false.
3709 (when wrapped 3709 (when wrapped
3710 (insert ? )) 3710 (insert ? ))
3711 (insert ?\n) 3711 (insert ?\n)
3712 (put-text-property saved-point (point) 'face 'default) 3712 (put-text-property saved-point (point) 'face 'default)
3713 (goto-char saved-point)))) 3713 (goto-char saved-point))))
3714 3714
3795 ;; Inserting lines should take into account the scroll region. 3795 ;; Inserting lines should take into account the scroll region.
3796 ;; The `term-scroll-end' line is part of the scrolling region, so 3796 ;; The `term-scroll-end' line is part of the scrolling region, so
3797 ;; we need to go one line past it in order to ensure correct 3797 ;; we need to go one line past it in order to ensure correct
3798 ;; scrolling. 3798 ;; scrolling.
3799 (if (< save-current-row term-scroll-start) 3799 (if (< save-current-row term-scroll-start)
3800 ;; If point is before scroll start, 3800 ;; If point is before scroll start,
3801 (progn 3801 (progn
3802 (setq lines (- lines (- term-scroll-start save-current-row))) 3802 (setq lines (- lines (- term-scroll-start save-current-row)))
3803 (term-down (- term-scroll-start save-current-row)) 3803 (term-down (- term-scroll-start save-current-row))
3804 (setq start (point))) 3804 (setq start (point)))
3805 ;; The number of inserted lines shouldn't exceed the scroll region end. 3805 ;; The number of inserted lines shouldn't exceed the scroll region end.
3806 (when (> (+ save-current-row lines) (1+ term-scroll-end)) 3806 (when (> (+ save-current-row lines) (1+ term-scroll-end))