;;; m-s comint-next-matching-input Next input that matches
;;; m-c-l comint-show-output Show last batch of process output
;;; return comint-send-input
-;;; c-a comint-bol Beginning of line; skip prompt
;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff
+;;; c-c c-a comint-bol Beginning of line; skip prompt
;;; c-c c-u comint-kill-input ^u
;;; c-c c-w backward-kill-word ^w
;;; c-c c-c comint-interrupt-subjob ^c
This variable is buffer-local.")
+(defvar comint-password-prompt-regexp "\\b[Pp]assword:\\s *\\'"
+ "*Regexp matching prompts for passwords in the inferior process.
+This is used by comint-watch-for-password-prompt.")
+
;;; Here are the per-interpreter hooks.
(defvar comint-get-old-input (function comint-get-old-input-default)
"Function that returns old text in comint mode.
(kill-all-local-variables)
(setq major-mode 'comint-mode)
(setq mode-name "Comint")
- (setq mode-line-process '(": %s"))
+ (setq mode-line-process '(":%s"))
(use-local-map comint-mode-map)
(make-local-variable 'comint-last-input-start)
(setq comint-last-input-start (make-marker))
+ (set-marker comint-last-input-start (point-min))
(make-local-variable 'comint-last-input-end)
(setq comint-last-input-end (make-marker))
+ (set-marker comint-last-input-end (point-min))
(make-local-variable 'comint-last-output-start)
(setq comint-last-output-start (make-marker))
(make-local-variable 'comint-prompt-regexp) ; Don't set; default
(define-key comint-mode-map "\e\C-l" 'comint-show-output)
(define-key comint-mode-map "\C-m" 'comint-send-input)
(define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
- (define-key comint-mode-map "\C-a" 'comint-bol)
+ (define-key comint-mode-map "\C-c\C-a" 'comint-bol)
(define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
(define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
(define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
(define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
(define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
(define-key comint-mode-map "\C-c\C-e" 'comint-show-maximum-output)
- (define-key comint-mode-map "\C-c\C-h" 'comint-dynamic-list-input-ring)
+ (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
(define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
(define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
(define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
(defun comint-exec-1 (name buffer command switches)
(let ((process-environment
- (nconc (list "EMACS=t" "TERM=emacs"
- (format "TERMCAP=emacs:co#%d:tc=unknown" (frame-width)))
- process-environment)))
+ (nconc
+ ;; If using termcap, we specify `emacs' as the terminal type
+ ;; because that lets us specify a width.
+ ;; If using terminfo, we specify `unknown' because that is
+ ;; a defined terminal type. `emacs' is not a defined terminal type
+ ;; and there is no way for us to define it here.
+ ;; Some programs that use terminfo get very confused
+ ;; if TERM is not a valid terminal type.
+ (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
+ (list "EMACS=t" "TERM=unknown"
+ (format "COLUMNS=%d" (frame-width)))
+ (list "EMACS=t" "TERM=emacs"
+ (format "TERMCAP=emacs:co#%d:tc=unknown" (frame-width))))
+ process-environment)))
(apply 'start-process name buffer command switches)))
\f
;;; Input history processing in a buffer
(message "Cannot read history file %s"
comint-input-ring-file-name)))
(t
- (let ((history-buf (get-file-buffer comint-input-ring-file-name))
+ (let ((history-buf (get-buffer-create " *temp*"))
+ (file comint-input-ring-file-name)
+ (count 0)
(ring (make-ring comint-input-ring-size)))
- (save-excursion
- (set-buffer (or history-buf
- (find-file-noselect comint-input-ring-file-name)))
- ;; Save restriction in case file is already visited...
- ;; Watch for those date stamps in history files!
- (save-excursion
- (save-restriction
+ (unwind-protect
+ (save-excursion
+ (set-buffer history-buf)
(widen)
- (goto-char (point-min))
- (while (re-search-forward "^\\s *\\([^#].*\\)\\s *$" nil t)
+ (erase-buffer)
+ (insert-file-contents file)
+ ;; Save restriction in case file is already visited...
+ ;; Watch for those date stamps in history files!
+ (goto-char (point-max))
+ (while (and (< count comint-input-ring-size)
+ (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
+ nil t))
(let ((history (buffer-substring (match-beginning 1)
(match-end 1))))
(if (or (null comint-input-ignoredups)
(ring-empty-p ring)
(not (string-equal (ring-ref ring 0) history)))
- (ring-insert ring history)))))
- ;; Kill buffer unless already visited.
- (if (null history-buf)
- (kill-buffer nil))))
+ (ring-insert-at-beginning ring history)))
+ (setq count (1+ count))))
+ (kill-buffer history-buf))
(setq comint-input-ring ring
comint-input-ring-index nil)))))
Returns t if successful."
(interactive)
(if (and comint-input-autoexpand
- (string-match "[!^]" (funcall comint-get-old-input)))
+ (string-match "[!^]" (funcall comint-get-old-input))
+ (save-excursion (beginning-of-line)
+ (looking-at comint-prompt-regexp)))
;; Looks like there might be history references in the command.
(let ((previous-modified-tick (buffer-modified-tick)))
(message "Expanding history references...")
- (comint-replace-by-expanded-history-before-point)
+ (comint-replace-by-expanded-history-before-point silent)
(/= previous-modified-tick (buffer-modified-tick)))))
-(defun comint-replace-by-expanded-history-before-point ()
+(defun comint-replace-by-expanded-history-before-point (silent)
"Expand directory stack reference before point.
See `comint-replace-by-expanded-history'. Returns t if successful."
(save-excursion
(comint-previous-matching-input-string-position
(concat pref (regexp-quote exp)) 1))))
(if (null pos)
- (or silent
- (progn (message "Not found")
- (goto-char (match-end 0))
- (ding)))
+ (progn
+ (goto-char (match-end 0))
+ (or silent
+ (progn (message "Not found")
+ (ding))))
(setq comint-input-ring-index pos)
(replace-match
(comint-args (ring-ref comint-input-ring pos)
(while functions
(funcall (car functions) (concat input "\n"))
(setq functions (cdr functions))))
- (funcall comint-input-sender proc input)
(setq comint-input-ring-index nil)
+ ;; Update the markers before we send the input
+ ;; in case we get output amidst sending the input.
(set-marker comint-last-input-start pmark)
(set-marker comint-last-input-end (point))
(set-marker (process-mark proc) (point))
- ;; A kludge to prevent the delay between insert and process output
- ;; affecting the display. A case for a comint-send-input-hook?
- (if (eq (process-filter proc) 'comint-output-filter)
- (let ((functions comint-output-filter-functions))
- (while functions
- (funcall (car functions) (concat input "\n"))
- (setq functions (cdr functions)))))))))
+ (funcall comint-input-sender proc input)
+ (comint-output-filter proc "")))))
;; The purpose of using this filter for comint processes
;; is to keep comint-last-input-end from moving forward
If prefix argument is given (\\[universal-argument]) the prompt is not skipped.
The prompt skip is done by skipping text matching the regular expression
-`comint-prompt-regexp', a buffer local variable.
-
-If you don't like this command, bind C-a to `beginning-of-line'
-in your hook, `comint-mode-hook'."
+`comint-prompt-regexp', a buffer local variable."
(interactive "P")
(beginning-of-line)
(if (null arg) (comint-skip-prompt)))
(defun comint-watch-for-password-prompt (string)
"Prompt in the minibuffer for password and send without echoing.
This function uses `send-invisible' to read and send a password to the buffer's
-process if STRING contains a password prompt (matches \"^[Pp]assword:\\\\s *\\\\'\").
+process if STRING contains a password prompt defined by
+`comint-password-prompt-regexp'.
This function could be in the list `comint-output-filter-functions'."
- (if (string-match "^[Pp]assword:\\s *\\'" string)
+ (if (string-match comint-password-prompt-regexp string)
(send-invisible nil)))
\f
;;; Low-level process communication
"Kill all output from interpreter since last input.
Does not delete the prompt."
(interactive)
- (let ((pmark (progn (goto-char
- (process-mark (get-buffer-process (current-buffer))))
- (beginning-of-line nil)
- (point-marker))))
- (kill-region comint-last-input-end pmark)
- (insert "*** output flushed ***\n")
- (comint-skip-prompt)
- (set-marker pmark (point))))
+ (let ((proc (get-buffer-process (current-buffer)))
+ (replacement nil))
+ (save-excursion
+ (let ((pmark (progn (goto-char (process-mark proc))
+ (beginning-of-line nil)
+ (point-marker))))
+ (delete-region comint-last-input-end pmark)
+ (comint-skip-prompt)
+ (setq replacement (concat "*** output flushed ***\n"
+ (buffer-substring pmark (point))))
+ (delete-region pmark (point))))
+ ;; Output message and put back prompt
+ (comint-output-filter proc replacement)))
(defun comint-show-output ()
"Display start of this batch of interpreter output at top of window.
Returns t if successful."
(interactive)
(if (comint-match-partial-filename)
- (prog2 (message "Completing file name...")
+ (prog2 (or (eq (selected-window) (minibuffer-window))
+ (message "Completing file name..."))
(comint-dynamic-complete-as-filename))))
(completion-ignored-extensions comint-completion-fignore)
(success t)
(filename (or (comint-match-partial-filename) ""))
- (pathdir (file-name-directory filename))
- (pathnondir (file-name-nondirectory filename))
- (directory (if pathdir (comint-directory pathdir) default-directory))
- (completion (file-name-completion pathnondir directory)))
+ (pathdir (file-name-directory filename))
+ (pathnondir (file-name-nondirectory filename))
+ (directory (if pathdir (comint-directory pathdir) default-directory))
+ (completion (file-name-completion pathnondir directory))
+ (mini-flag (eq (selected-window) (minibuffer-window))))
(cond ((null completion)
(message "No completions of %s" filename)
(setq success nil))
((eq completion t) ; Means already completed "file".
(if comint-completion-addsuffix (insert " "))
- (message "Sole completion"))
+ (or mini-flag (message "Sole completion")))
((string-equal completion "") ; Means completion on "directory/".
(comint-dynamic-list-filename-completions))
(t ; Completion string returned.
(let ((file (concat (file-name-as-directory directory) completion)))
- (goto-char (match-end 0))
(insert (substring (directory-file-name completion)
(length pathnondir)))
(cond ((symbolp (file-name-completion completion directory))
;; We inserted a unique completion.
(if comint-completion-addsuffix
(insert (if (file-directory-p file) "/" " ")))
- (message "Completed"))
+ (or mini-flag (message "Completed")))
((and comint-completion-recexact comint-completion-addsuffix
(string-equal pathnondir completion)
(file-exists-p file))
;; It's not unique, but user wants shortest match.
(insert (if (file-directory-p file) "/" " "))
- (message "Completed shortest"))
+ (or mini-flag (message "Completed shortest")))
((or comint-completion-autolist
(string-equal pathnondir completion))
;; It's not unique, list possible completions.
(comint-dynamic-list-filename-completions))
(t
- (message "Partially completed"))))))
+ (or mini-flag (message "Partially completed")))))))
success))
"List in help buffer sorted COMPLETIONS.
Typing SPC flushes the help buffer."
(let ((conf (current-window-configuration)))
- (with-output-to-temp-buffer " *Completions*"
+ (with-output-to-temp-buffer "*Completions*"
(display-completion-list (sort completions 'string-lessp)))
(message "Hit space to flush")
(let (key first)
(if (save-excursion
- (set-buffer (get-buffer " *Completions*"))
+ (set-buffer (get-buffer "*Completions*"))
(setq key (read-key-sequence nil)
first (aref key 0))
(and (consp first)
(eq (window-buffer (posn-window (event-start first)))
- (get-buffer " *Completions*"))
+ (get-buffer "*Completions*"))
(eq (key-binding key) 'mouse-choose-completion)))
;; If the user does mouse-choose-completion with the mouse,
;; execute the command, then delete the completion window.
(set-window-configuration conf))
(if (eq first ?\ )
(set-window-configuration conf)
- (setq unread-command-events (append key nil)))))))
+ (setq unread-command-events (listify-key-sequence key)))))))
\f
;;; Converting process modes to use comint mode
;;; ===========================================================================
;;;
;;; (defvar shell-mode-map '())
;;; (cond ((not shell-mode-map)
-;;; (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map))
+;;; (setq shell-mode-map (copy-keymap comint-mode-map))
;;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
;;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)