Mercurial > emacs
comparison lisp/shell.el @ 6508:965beb0c97d2
(shell-strip-ctrl-m): New command.
(shell-mode): Doc fix.
(shell-dynamic-complete-as-command): Use comint-dynamic-simple-complete.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 24 Mar 1994 07:51:27 +0000 |
parents | 59a6684e8057 |
children | 3c007de39916 |
comparison
equal
deleted
inserted
replaced
6507:ff41e0e932b8 | 6508:965beb0c97d2 |
---|---|
91 ;;; m-? comint-dynamic-list-filename-completions List completions in help buffer | 91 ;;; m-? comint-dynamic-list-filename-completions List completions in help buffer |
92 ;;; m-c-f shell-forward-command Forward a shell command | 92 ;;; m-c-f shell-forward-command Forward a shell command |
93 ;;; m-c-b shell-backward-command Backward a shell command | 93 ;;; m-c-b shell-backward-command Backward a shell command |
94 ;;; dirs Resync the buffer's dir stack | 94 ;;; dirs Resync the buffer's dir stack |
95 ;;; dirtrack-toggle Turn dir tracking on/off | 95 ;;; dirtrack-toggle Turn dir tracking on/off |
96 ;;; shell-strip-ctrl-m Remove trailing ^Ms from output | |
96 ;;; | 97 ;;; |
97 ;;; The shell mode hook is shell-mode-hook | 98 ;;; The shell mode hook is shell-mode-hook |
98 ;;; comint-prompt-regexp is initialised to shell-prompt-pattern, for backwards | 99 ;;; comint-prompt-regexp is initialised to shell-prompt-pattern, for backwards |
99 ;;; compatibility. | 100 ;;; compatibility. |
100 | 101 |
284 Return after the end of the process' output sends the text from the | 285 Return after the end of the process' output sends the text from the |
285 end of process to the end of the current line. | 286 end of process to the end of the current line. |
286 Return before end of process output copies the current line (except | 287 Return before end of process output copies the current line (except |
287 for the prompt) to the end of the buffer and sends it. | 288 for the prompt) to the end of the buffer and sends it. |
288 M-x send-invisible reads a line of text without echoing it, and sends it to | 289 M-x send-invisible reads a line of text without echoing it, and sends it to |
289 the shell. This is useful for entering passwords. | 290 the shell. This is useful for entering passwords. Or, add the function |
291 `comint-watch-for-password-prompt' to `comint-output-filter-functions'. | |
290 | 292 |
291 If you accidentally suspend your process, use \\[comint-continue-subjob] | 293 If you accidentally suspend your process, use \\[comint-continue-subjob] |
292 to continue it. | 294 to continue it. |
293 | 295 |
294 cd, pushd and popd commands given to the shell are watched by Emacs to keep | 296 cd, pushd and popd commands given to the shell are watched by Emacs to keep |
679 | 681 |
680 | 682 |
681 (defun shell-dynamic-complete-as-command () | 683 (defun shell-dynamic-complete-as-command () |
682 "Dynamically complete at point as a command. | 684 "Dynamically complete at point as a command. |
683 See `shell-dynamic-complete-filename'. Returns t if successful." | 685 See `shell-dynamic-complete-filename'. Returns t if successful." |
684 (let* ((completion-ignore-case nil) | 686 (let* ((filename (or (comint-match-partial-filename) "")) |
685 (success t) | |
686 (filename (or (comint-match-partial-filename) "")) | |
687 (pathnondir (file-name-nondirectory filename)) | 687 (pathnondir (file-name-nondirectory filename)) |
688 (paths (cdr (reverse exec-path))) | 688 (paths (cdr (reverse exec-path))) |
689 (cwd (file-name-as-directory (expand-file-name default-directory))) | 689 (cwd (file-name-as-directory (expand-file-name default-directory))) |
690 (ignored-extensions | 690 (ignored-extensions |
691 (and comint-completion-fignore | 691 (and comint-completion-fignore |
709 (file-executable-p filepath))) | 709 (file-executable-p filepath))) |
710 (setq completions (cons file completions))) | 710 (setq completions (cons file completions))) |
711 (setq comps-in-path (cdr comps-in-path))) | 711 (setq comps-in-path (cdr comps-in-path))) |
712 (setq paths (cdr paths))) | 712 (setq paths (cdr paths))) |
713 ;; OK, we've got a list of completions. | 713 ;; OK, we've got a list of completions. |
714 (cond ((null completions) | 714 (let ((success (let ((comint-completion-addsuffix nil)) |
715 (message "No completions of %s" filename) | 715 (comint-dynamic-simple-complete pathnondir completions)))) |
716 (setq success nil)) | 716 (if (and (memq success '(sole shortest)) comint-completion-addsuffix |
717 ((= 1 (length completions)) ; Gotcha! | 717 (not (file-directory-p (comint-match-partial-filename)))) |
718 (let ((completion (car completions))) | 718 (insert " ")) |
719 (if (string-equal completion pathnondir) | 719 success))) |
720 (message "Sole completion") | |
721 (insert (substring (directory-file-name completion) | |
722 (length pathnondir))) | |
723 (message "Completed")) | |
724 (if comint-completion-addsuffix | |
725 (insert (if (file-directory-p completion) "/" " "))))) | |
726 (t ; There's no unique completion. | |
727 (let ((completion | |
728 (try-completion pathnondir (mapcar (function (lambda (x) | |
729 (list x))) | |
730 completions)))) | |
731 ;; Insert the longest substring. | |
732 (insert (substring (directory-file-name completion) | |
733 (length pathnondir))) | |
734 (cond ((and comint-completion-recexact comint-completion-addsuffix | |
735 (string-equal pathnondir completion) | |
736 (member completion completions)) | |
737 ;; It's not unique, but user wants shortest match. | |
738 (insert (if (file-directory-p completion) "/" " ")) | |
739 (message "Completed shortest")) | |
740 ((or comint-completion-autolist | |
741 (string-equal pathnondir completion)) | |
742 ;; It's not unique, list possible completions. | |
743 (comint-dynamic-list-completions completions)) | |
744 (t | |
745 (message "Partially completed")))))) | |
746 success)) | |
747 | 720 |
748 | 721 |
749 (defun shell-match-partial-variable () | 722 (defun shell-match-partial-variable () |
750 "Return the variable at point, or nil if non is found." | 723 "Return the variable at point, or nil if non is found." |
751 (save-excursion | 724 (save-excursion |
831 (t | 804 (t |
832 (replace-match (file-name-as-directory (nth index stack)) t t) | 805 (replace-match (file-name-as-directory (nth index stack)) t t) |
833 (message "Directory item: %d" index) | 806 (message "Directory item: %d" index) |
834 t)))))) | 807 t)))))) |
835 | 808 |
809 (defun shell-strip-ctrl-m (&optional string) | |
810 "Strip trailing `^M' characters from the current output group. | |
811 | |
812 This function could be in the list `comint-output-filter-functions' or bound to | |
813 a key." | |
814 (interactive) | |
815 (let ((pmark (process-mark (get-buffer-process (current-buffer)))) | |
816 (ctrl-m (concat (char-to-string 13) "$"))) | |
817 (save-excursion | |
818 (goto-char | |
819 (if (interactive-p) comint-last-input-end comint-last-output-start)) | |
820 (while (re-search-forward ctrl-m pmark t) | |
821 (replace-match "" t t))))) | |
822 | |
836 (provide 'shell) | 823 (provide 'shell) |
837 | 824 |
838 ;;; shell.el ends here | 825 ;;; shell.el ends here |