comparison lisp/comint.el @ 53399:9a9d11c249b9

(comint-arguments): Set COUNT after ARGS is complete. (comint-dynamic-complete-as-filename): Rename local vars. (comint-dynamic-list-filename-completions): Likewise. (comint-dynamic-list-completions-config): New var. (comint-dynamic-list-completions): Handle both SPC and TAB right. (comint-file-name-chars): Add []. (comint-word): Use skip-chars-backward, not search.
author Richard M. Stallman <rms@gnu.org>
date Mon, 29 Dec 2003 19:10:24 +0000
parents ab9195f48a6f
children 4763dd572f96
comparison
equal deleted inserted replaced
53398:8aa355a609cd 53399:9a9d11c249b9
1342 ;; It's a new separate arg. 1342 ;; It's a new separate arg.
1343 (if beg 1343 (if beg
1344 ;; Put the previous arg, if there was one, onto ARGS. 1344 ;; Put the previous arg, if there was one, onto ARGS.
1345 (setq str (substring string beg pos) 1345 (setq str (substring string beg pos)
1346 args (if quotes (cons str args) 1346 args (if quotes (cons str args)
1347 (nconc (comint-delim-arg str) args)) 1347 (nconc (comint-delim-arg str) args))))
1348 count (1+ count))) 1348 (setq count (length args))
1349 (setq quotes (match-beginning 1)) 1349 (setq quotes (match-beginning 1))
1350 (setq beg (match-beginning 0)) 1350 (setq beg (match-beginning 0))
1351 (setq pos (match-end 0)))) 1351 (setq pos (match-end 0))))
1352 (if beg 1352 (if beg
1353 (setq str (substring string beg pos) 1353 (setq str (substring string beg pos)
1354 args (if quotes (cons str args) 1354 args (if quotes (cons str args)
1355 (nconc (comint-delim-arg str) args)) 1355 (nconc (comint-delim-arg str) args))))
1356 count (1+ count))) 1356 (setq count (length args))
1357 (let ((n (or nth (1- count))) 1357 (let ((n (or nth (1- count)))
1358 (m (if mth (1- (- count mth)) 0))) 1358 (m (if mth (1- (- count mth)) 0)))
1359 (mapconcat 1359 (mapconcat
1360 (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " ")))) 1360 (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " "))))
1361 1361
2080 between the process-mark and point." 2080 between the process-mark and point."
2081 (interactive) 2081 (interactive)
2082 (comint-skip-input) 2082 (comint-skip-input)
2083 (interrupt-process nil comint-ptyp) 2083 (interrupt-process nil comint-ptyp)
2084 ;; (process-send-string nil "\n") 2084 ;; (process-send-string nil "\n")
2085 ) 2085 )
2086 2086
2087 (defun comint-kill-subjob () 2087 (defun comint-kill-subjob ()
2088 "Send kill signal to the current subjob. 2088 "Send kill signal to the current subjob.
2089 This command also kills the pending input 2089 This command also kills the pending input
2090 between the process-mark and point." 2090 between the process-mark and point."
2549 directory tracking functions.") 2549 directory tracking functions.")
2550 2550
2551 (defvar comint-file-name-chars 2551 (defvar comint-file-name-chars
2552 (if (memq system-type '(ms-dos windows-nt cygwin)) 2552 (if (memq system-type '(ms-dos windows-nt cygwin))
2553 "~/A-Za-z0-9_^$!#%&{}@`'.,:()-" 2553 "~/A-Za-z0-9_^$!#%&{}@`'.,:()-"
2554 "~/A-Za-z0-9+@:_.$#%,={}-") 2554 "[]~/A-Za-z0-9+@:_.$#%,={}-")
2555 "String of characters valid in a file name. 2555 "String of characters valid in a file name.
2556 Note that all non-ASCII characters are considered valid in a file name 2556 Note that all non-ASCII characters are considered valid in a file name
2557 regardless of what this variable says. 2557 regardless of what this variable says.
2558 2558
2559 This is a good thing to set in mode hooks.") 2559 This is a good thing to set in mode hooks.")
2575 "Return the word of WORD-CHARS at point, or nil if non is found. 2575 "Return the word of WORD-CHARS at point, or nil if non is found.
2576 Word constituents are considered to be those in WORD-CHARS, which is like the 2576 Word constituents are considered to be those in WORD-CHARS, which is like the
2577 inside of a \"[...]\" (see `skip-chars-forward'), 2577 inside of a \"[...]\" (see `skip-chars-forward'),
2578 plus all non-ASCII characters." 2578 plus all non-ASCII characters."
2579 (save-excursion 2579 (save-excursion
2580 (let ((non-word-chars (concat "[^\\\\" word-chars "]")) (here (point))) 2580 (let ((here (point))
2581 (while (and (re-search-backward non-word-chars nil 'move) 2581 giveup)
2582 ;;(memq (char-after (point)) shell-file-name-quote-list) 2582 (while (not giveup)
2583 (or (>= (following-char) 128) 2583 (let ((startpoint (point)))
2584 (eq (preceding-char) ?\\))) 2584 (skip-chars-backward (concat "\\\\" word-chars))
2585 (backward-char 1)) 2585 (if (and (> (- (point) 2) (point-min))
2586 ;; Don't go forward over a word-char (this can happen if we're at bob). 2586 (= (char-after (- (point) 2)) ?\\))
2587 (when (or (not (bobp)) (looking-at non-word-chars)) 2587 (forward-char -2))
2588 (forward-char 1)) 2588 (if (and (> (- (point) 1) (point-min))
2589 (>= (char-after (- (point) 1)) 128))
2590 (forward-char -1))
2591 (if (= (point) startpoint)
2592 (setq giveup t))))
2589 ;; Set match-data to match the entire string. 2593 ;; Set match-data to match the entire string.
2590 (when (< (point) here) 2594 (when (< (point) here)
2591 (set-match-data (list (point) here)) 2595 (set-match-data (list (point) here))
2592 (match-string 0))))) 2596 (match-string 0)))))
2593 2597
2695 ((not (consp comint-completion-addsuffix)) 2699 ((not (consp comint-completion-addsuffix))
2696 " ") 2700 " ")
2697 (t 2701 (t
2698 (cdr comint-completion-addsuffix)))) 2702 (cdr comint-completion-addsuffix))))
2699 (filename (or (comint-match-partial-filename) "")) 2703 (filename (or (comint-match-partial-filename) ""))
2700 (pathdir (file-name-directory filename)) 2704 (filedir (file-name-directory filename))
2701 (pathnondir (file-name-nondirectory filename)) 2705 (filenondir (file-name-nondirectory filename))
2702 (directory (if pathdir (comint-directory pathdir) default-directory)) 2706 (directory (if filedir (comint-directory filedir) default-directory))
2703 (completion (file-name-completion pathnondir directory))) 2707 (completion (file-name-completion filenondir directory)))
2704 (cond ((null completion) 2708 (cond ((null completion)
2705 (message "No completions of %s" filename) 2709 (message "No completions of %s" filename)
2706 (setq success nil)) 2710 (setq success nil))
2707 ((eq completion t) ; Means already completed "file". 2711 ((eq completion t) ; Means already completed "file".
2708 (insert filesuffix) 2712 (insert filesuffix)
2712 (comint-dynamic-list-filename-completions)) 2716 (comint-dynamic-list-filename-completions))
2713 (t ; Completion string returned. 2717 (t ; Completion string returned.
2714 (let ((file (concat (file-name-as-directory directory) completion))) 2718 (let ((file (concat (file-name-as-directory directory) completion)))
2715 (insert (comint-quote-filename 2719 (insert (comint-quote-filename
2716 (substring (directory-file-name completion) 2720 (substring (directory-file-name completion)
2717 (length pathnondir)))) 2721 (length filenondir))))
2718 (cond ((symbolp (file-name-completion completion directory)) 2722 (cond ((symbolp (file-name-completion completion directory))
2719 ;; We inserted a unique completion. 2723 ;; We inserted a unique completion.
2720 (insert (if (file-directory-p file) dirsuffix filesuffix)) 2724 (insert (if (file-directory-p file) dirsuffix filesuffix))
2721 (unless minibuffer-p 2725 (unless minibuffer-p
2722 (message "Completed"))) 2726 (message "Completed")))
2723 ((and comint-completion-recexact comint-completion-addsuffix 2727 ((and comint-completion-recexact comint-completion-addsuffix
2724 (string-equal pathnondir completion) 2728 (string-equal filenondir completion)
2725 (file-exists-p file)) 2729 (file-exists-p file))
2726 ;; It's not unique, but user wants shortest match. 2730 ;; It's not unique, but user wants shortest match.
2727 (insert (if (file-directory-p file) dirsuffix filesuffix)) 2731 (insert (if (file-directory-p file) dirsuffix filesuffix))
2728 (unless minibuffer-p 2732 (unless minibuffer-p
2729 (message "Completed shortest"))) 2733 (message "Completed shortest")))
2730 ((or comint-completion-autolist 2734 ((or comint-completion-autolist
2731 (string-equal pathnondir completion)) 2735 (string-equal filenondir completion))
2732 ;; It's not unique, list possible completions. 2736 ;; It's not unique, list possible completions.
2733 (comint-dynamic-list-filename-completions)) 2737 (comint-dynamic-list-filename-completions))
2734 (t 2738 (t
2735 (unless minibuffer-p 2739 (unless minibuffer-p
2736 (message "Partially completed"))))))) 2740 (message "Partially completed")))))))
2810 ;; If we bind this, it breaks remote directory tracking in rlogin.el. 2814 ;; If we bind this, it breaks remote directory tracking in rlogin.el.
2811 ;; I think it was originally bound to solve file completion problems, 2815 ;; I think it was originally bound to solve file completion problems,
2812 ;; but subsequent changes may have made this unnecessary. sm. 2816 ;; but subsequent changes may have made this unnecessary. sm.
2813 ;;(file-name-handler-alist nil) 2817 ;;(file-name-handler-alist nil)
2814 (filename (or (comint-match-partial-filename) "")) 2818 (filename (or (comint-match-partial-filename) ""))
2815 (pathdir (file-name-directory filename)) 2819 (filedir (file-name-directory filename))
2816 (pathnondir (file-name-nondirectory filename)) 2820 (filenondir (file-name-nondirectory filename))
2817 (directory (if pathdir (comint-directory pathdir) default-directory)) 2821 (directory (if filedir (comint-directory filedir) default-directory))
2818 (completions (file-name-all-completions pathnondir directory))) 2822 (completions (file-name-all-completions filenondir directory)))
2819 (if (not completions) 2823 (if (not completions)
2820 (message "No completions of %s" filename) 2824 (message "No completions of %s" filename)
2821 (comint-dynamic-list-completions 2825 (comint-dynamic-list-completions
2822 (mapcar 'comint-quote-filename completions))))) 2826 (mapcar 'comint-quote-filename completions)))))
2823 2827
2824 2828
2825 ;; This is bound locally in a *Completions* buffer to the list of 2829 ;; This is bound locally in a *Completions* buffer to the list of
2826 ;; completions displayed, and is used to detect the case where the same 2830 ;; completions displayed, and is used to detect the case where the same
2827 ;; command is repeatedly used without the set of completions changing. 2831 ;; command is repeatedly used without the set of completions changing.
2828 (defvar comint-displayed-dynamic-completions nil) 2832 (defvar comint-displayed-dynamic-completions nil)
2833
2834 (defvar comint-dynamic-list-completions-config nil)
2829 2835
2830 (defun comint-dynamic-list-completions (completions) 2836 (defun comint-dynamic-list-completions (completions)
2831 "List in help buffer sorted COMPLETIONS. 2837 "List in help buffer sorted COMPLETIONS.
2832 Typing SPC flushes the help buffer." 2838 Typing SPC flushes the help buffer."
2833 (let ((window (get-buffer-window "*Completions*"))) 2839 (let ((window (get-buffer-window "*Completions*")))
2854 (set-window-start window (point-min)) 2860 (set-window-start window (point-min))
2855 (save-selected-window 2861 (save-selected-window
2856 (select-window window) 2862 (select-window window)
2857 (scroll-up)))) 2863 (scroll-up))))
2858 2864
2859 (let ((conf (current-window-configuration))) 2865 ;; Display a completion list for the first time.
2860 (with-output-to-temp-buffer "*Completions*" 2866 (setq comint-dynamic-list-completions-config
2861 (display-completion-list completions)) 2867 (current-window-configuration))
2862 (message "Type space to flush; repeat completion command to scroll") 2868 (with-output-to-temp-buffer "*Completions*"
2863 (let (key first) 2869 (display-completion-list completions))
2864 (if (save-excursion 2870 (message "Type space to flush; repeat completion command to scroll"))
2865 (set-buffer (get-buffer "*Completions*")) 2871
2866 (set (make-local-variable 2872 ;; Read the next key, to process SPC.
2867 'comint-displayed-dynamic-completions) 2873 (let (key first)
2868 completions) 2874 (if (save-excursion
2869 (setq key (read-key-sequence nil) 2875 (set-buffer (get-buffer "*Completions*"))
2870 first (aref key 0)) 2876 (set (make-local-variable
2871 (and (consp first) (consp (event-start first)) 2877 'comint-displayed-dynamic-completions)
2872 (eq (window-buffer (posn-window (event-start first))) 2878 completions)
2873 (get-buffer "*Completions*")) 2879 (setq key (read-key-sequence nil)
2874 (eq (key-binding key) 'mouse-choose-completion))) 2880 first (aref key 0))
2875 ;; If the user does mouse-choose-completion with the mouse, 2881 (and (consp first) (consp (event-start first))
2876 ;; execute the command, then delete the completion window. 2882 (eq (window-buffer (posn-window (event-start first)))
2877 (progn 2883 (get-buffer "*Completions*"))
2878 (mouse-choose-completion first) 2884 (eq (key-binding key) 'mouse-choose-completion)))
2879 (set-window-configuration conf)) 2885 ;; If the user does mouse-choose-completion with the mouse,
2880 (if (eq first ?\ ) 2886 ;; execute the command, then delete the completion window.
2881 (set-window-configuration conf) 2887 (progn
2882 (setq unread-command-events (listify-key-sequence key))))))))) 2888 (mouse-choose-completion first)
2889 (set-window-configuration comint-dynamic-list-completions-config))
2890 (unless (eq first ?\ )
2891 (setq unread-command-events (listify-key-sequence key)))
2892 (unless (eq first ?\t)
2893 (set-window-configuration comint-dynamic-list-completions-config))))))
2883 2894
2884 2895
2885 (defun comint-get-next-from-history () 2896 (defun comint-get-next-from-history ()
2886 "After fetching a line from input history, this fetches the following line. 2897 "After fetching a line from input history, this fetches the following line.
2887 In other words, this recalls the input line after the line you recalled last. 2898 In other words, this recalls the input line after the line you recalled last.