;;; term.el --- general command interpreter in a window stuff
;; Copyright (C) 1988, 1990, 1992, 1994, 1995, 2001, 2002, 2003,
-;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
;; Author: Per Bothner <per@bothner.com>
;; Maintainer: Dan Nicolaescu <dann@ics.uci.edu>, Per Bothner <per@bothner.com>
(defvar term-pager-old-filter) ;; Saved process-filter while paging.
(defcustom explicit-shell-file-name nil
- "*If non-nil, is file name to use for explicitly requested inferior shell."
+ "If non-nil, is file name to use for explicitly requested inferior shell."
:type '(choice (const nil) file)
:group 'term)
This is a good thing to set in mode hooks.")
(defcustom term-input-autoexpand nil
- "*If non-nil, expand input command history references on completion.
+ "If non-nil, expand input command history references on completion.
This mirrors the optional behavior of tcsh (its autoexpand and histlit).
If the value is `input', then the expansion is seen on input.
:group 'term)
(defcustom term-input-ignoredups nil
- "*If non-nil, don't add input matching the last on the input ring.
+ "If non-nil, don't add input matching the last on the input ring.
This mirrors the optional behavior of bash.
This variable is buffer-local."
:group 'term)
(defcustom term-input-ring-file-name nil
- "*If non-nil, name of the file to read/write input history.
+ "If non-nil, name of the file to read/write input history.
See also `term-read-input-ring' and `term-write-input-ring'.
This variable is buffer-local, and is a good thing to set in mode hooks."
:group 'term)
(defcustom term-scroll-to-bottom-on-output nil
- "*Controls whether interpreter output causes window to scroll.
+ "Controls whether interpreter output causes window to scroll.
If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
If `this', scroll only the selected window.
If `others', scroll only those that are not the selected window.
:group 'term)
(defcustom term-scroll-show-maximum-output nil
- "*Controls how interpreter output causes window to scroll.
+ "Controls how interpreter output causes window to scroll.
If non-nil, then show the maximum output when the window is scrolled.
See variable `term-scroll-to-bottom-on-output'.
the string plus a newline.")
(defcustom term-eol-on-send t
- "*Non-nil means go to the end of the line before sending input.
+ "Non-nil means go to the end of the line before sending input.
See `term-send-input'."
:type 'boolean
:group 'term)
:type 'hook
:group 'term)
-(defvar term-mode-map
+(defvar term-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\ep" 'term-previous-input)
(define-key map "\en" 'term-next-input)
without any interpretation."
(interactive)
;; Convert `return' to C-m, etc.
- (when (and (symbolp last-input-char)
- (get last-input-char 'ascii-character))
- (setq last-input-char (get last-input-char 'ascii-character)))
- (term-send-raw-string (make-string 1 last-input-char)))
+ (when (and (symbolp last-input-event)
+ (get last-input-event 'ascii-character))
+ (setq last-input-event (get last-input-event 'ascii-character)))
+ (term-send-raw-string (make-string 1 last-input-event)))
(defun term-send-raw-meta ()
(interactive)
- (let ((char last-input-char))
- (when (symbolp last-input-char)
+ (let ((char last-input-event))
+ (when (symbolp last-input-event)
;; Convert `return' to C-m, etc.
(let ((tmp (get char 'event-symbol-elements)))
(when tmp
(when (string-match regexp (ring-ref term-input-ring n))
n)))
-(defun term-previous-matching-input (regexp arg)
+(defun term-previous-matching-input (regexp n)
"Search backwards through input history for match for REGEXP.
\(Previous history elements are earlier commands.)
With prefix argument N, search for Nth previous match.
If N is negative, find the next or Nth next match."
(interactive (term-regexp-arg "Previous input matching (regexp): "))
- (setq arg (term-search-arg arg))
- (let ((pos (term-previous-matching-input-string-position regexp arg)))
+ (setq n (term-search-arg n))
+ (let ((pos (term-previous-matching-input-string-position regexp n)))
;; Has a match been found?
(if (null pos)
(error "Not found")
(process-mark (get-buffer-process (current-buffer))) (point))
(insert (ring-ref term-input-ring pos)))))
-(defun term-next-matching-input (regexp arg)
+(defun term-next-matching-input (regexp n)
"Search forwards through input history for match for REGEXP.
\(Later history elements are more recent commands.)
With prefix argument N, search for Nth following match.
If N is negative, find the previous or Nth previous match."
(interactive (term-regexp-arg "Next input matching (regexp): "))
- (term-previous-matching-input regexp (- arg)))
+ (term-previous-matching-input regexp (- n)))
-(defun term-previous-matching-input-from-input (arg)
+(defun term-previous-matching-input-from-input (n)
"Search backwards through input history for match for current input.
\(Previous history elements are earlier commands.)
With prefix argument N, search for Nth previous match.
term-input-ring-index nil))
(term-previous-matching-input
(concat "^" (regexp-quote term-matching-input-from-input-string))
- arg))
+ n))
-(defun term-next-matching-input-from-input (arg)
+(defun term-next-matching-input-from-input (n)
"Search forwards through input history for match for current input.
\(Following history elements are more recent commands.)
With prefix argument N, search for Nth following match.
If N is negative, search backwards for the -Nth previous match."
(interactive "p")
- (term-previous-matching-input-from-input (- arg)))
+ (term-previous-matching-input-from-input (- n)))
(defun term-replace-by-expanded-history (&optional silent)
(interactive)
(process-send-eof))
-(defun term-backward-matching-input (regexp arg)
+(defun term-backward-matching-input (regexp n)
"Search backward through buffer for match for REGEXP.
Matches are searched for on lines that match `term-prompt-regexp'.
With prefix argument N, search for Nth previous match.
If N is negative, find the next or Nth next match."
(interactive (term-regexp-arg "Backward input matching (regexp): "))
(let* ((re (concat term-prompt-regexp ".*" regexp))
- (pos (save-excursion (end-of-line (if (> arg 0) 0 1))
- (when (re-search-backward re nil t arg)
+ (pos (save-excursion (end-of-line (if (> n 0) 0 1))
+ (when (re-search-backward re nil t n)
(point)))))
(if (null pos)
(progn (message "Not found")
(goto-char pos)
(term-bol nil))))
-(defun term-forward-matching-input (regexp arg)
+(defun term-forward-matching-input (regexp n)
"Search forward through buffer for match for REGEXP.
Matches are searched for on lines that match `term-prompt-regexp'.
With prefix argument N, search for Nth following match.
If N is negative, find the previous or Nth previous match."
(interactive (term-regexp-arg "Forward input matching (regexp): "))
- (term-backward-matching-input regexp (- arg)))
+ (term-backward-matching-input regexp (- n)))
(defun term-next-prompt (n)
(defun term-emulate-terminal (proc str)
(with-current-buffer (process-buffer proc)
- (let* ((i 0) char funny count save-point save-marker old-point temp win
+ (let* ((i 0) char funny
+ count ; number of decoded chars in substring
+ count-bytes ; number of bytes
+ decoded-substring
+ save-point save-marker old-point temp win
(buffer-undo-list t)
(selected (selected-window))
last-win
str i))
(when (not funny) (setq funny str-length))
(cond ((> funny i)
+ ;; Decode the string before counting
+ ;; characters, to avoid garbling of certain
+ ;; multibyte characters (bug#1006).
+ (setq decoded-substring
+ (decode-coding-string
+ (substring str i funny)
+ locale-coding-system))
(cond ((eq term-terminal-state 1)
;; We are in state 1, we need to wrap
;; around. Go to the beginning of
(term-down 1 t)
(term-move-columns (- (term-current-column)))
(setq term-terminal-state 0)))
- (setq count (- funny i))
+ (setq count (length decoded-substring))
(setq temp (- (+ (term-horizontal-column) count)
term-width))
(cond ((<= temp 0)) ;; All count chars fit in line.
((> count temp) ;; Some chars fit.
;; This iteration, handle only what fits.
(setq count (- count temp))
+ (setq count-bytes
+ (length
+ (encode-coding-string
+ (substring decoded-substring 0 count)
+ 'binary)))
(setq temp 0)
- (setq funny (+ count i)))
+ (setq funny (+ count-bytes i)))
((or (not (or term-pager-count
term-scroll-with-delete))
(> (term-handle-scroll 1) 0))
(term-adjust-current-row-cache 1)
(setq count (min count term-width))
- (setq funny (+ count i))
+ (setq count-bytes
+ (length
+ (encode-coding-string
+ (substring decoded-substring 0 count)
+ 'binary)))
+ (setq funny (+ count-bytes i))
(setq term-start-line-column
term-current-column))
(t ;; Doing PAGER processing.