Changeset 4085 for trunk/lisp/shell.el
- Timestamp:
- 05/18/06 16:19:18 (3 years ago)
- Files:
-
- trunk/lisp/shell.el (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lisp/shell.el
r4058 r4085 151 151 152 152 (defcustom shell-completion-fignore nil 153 " *List of suffixes to be disregarded during file/command completion.153 "List of suffixes to be disregarded during file/command completion. 154 154 This variable is used to initialize `comint-completion-fignore' in the shell 155 155 buffer. The default is nil, for compatibility with most shells. … … 200 200 201 201 (defcustom shell-command-regexp "[^;&|\n]+" 202 " *Regexp to match a single command within a pipeline.202 "Regexp to match a single command within a pipeline. 203 203 This is used for directory tracking and does not do a perfect job." 204 204 :type 'regexp … … 206 206 207 207 (defcustom shell-command-separator-regexp "[;&|\n \t]*" 208 " *Regexp to match a single command within a pipeline.208 "Regexp to match a single command within a pipeline. 209 209 This is used for directory tracking and does not do a perfect job." 210 210 :type 'regexp … … 212 212 213 213 (defcustom shell-completion-execonly t 214 " *If non-nil, use executable files only for completion candidates.214 "If non-nil, use executable files only for completion candidates. 215 215 This mirrors the optional behavior of tcsh. 216 216 … … 220 220 221 221 (defcustom shell-popd-regexp "popd" 222 " *Regexp to match subshell commands equivalent to popd."222 "Regexp to match subshell commands equivalent to popd." 223 223 :type 'regexp 224 224 :group 'shell-directories) 225 225 226 226 (defcustom shell-pushd-regexp "pushd" 227 " *Regexp to match subshell commands equivalent to pushd."227 "Regexp to match subshell commands equivalent to pushd." 228 228 :type 'regexp 229 229 :group 'shell-directories) 230 230 231 231 (defcustom shell-pushd-tohome nil 232 " *If non-nil, make pushd with no arg behave as \"pushd ~\" (like cd).232 "If non-nil, make pushd with no arg behave as \"pushd ~\" (like cd). 233 233 This mirrors the optional behavior of tcsh." 234 234 :type 'boolean … … 236 236 237 237 (defcustom shell-pushd-dextract nil 238 " *If non-nil, make \"pushd +n\" pop the nth dir to the stack top.238 "If non-nil, make \"pushd +n\" pop the nth dir to the stack top. 239 239 This mirrors the optional behavior of tcsh." 240 240 :type 'boolean … … 242 242 243 243 (defcustom shell-pushd-dunique nil 244 " *If non-nil, make pushd only add unique directories to the stack.244 "If non-nil, make pushd only add unique directories to the stack. 245 245 This mirrors the optional behavior of tcsh." 246 246 :type 'boolean … … 248 248 249 249 (defcustom shell-cd-regexp "cd" 250 " *Regexp to match subshell commands equivalent to cd."250 "Regexp to match subshell commands equivalent to cd." 251 251 :type 'regexp 252 252 :group 'shell-directories) … … 257 257 "[]a-zA-Z^_`\\[\\\\]:" 258 258 nil) 259 " *If non-nil, is regexp used to track drive changes."259 "If non-nil, is regexp used to track drive changes." 260 260 :type '(choice regexp 261 261 (const nil)) … … 263 263 264 264 (defcustom shell-dirtrack-verbose t 265 " *If non-nil, show the directory stack following directory change.265 "If non-nil, show the directory stack following directory change. 266 266 This is effective only if directory tracking is enabled." 267 267 :type 'boolean … … 269 269 270 270 (defcustom explicit-shell-file-name nil 271 " *If non-nil, is file name to use for explicitly requested inferior shell."271 "If non-nil, is file name to use for explicitly requested inferior shell." 272 272 :type '(choice (const :tag "None" nil) file) 273 273 :group 'shell) … … 279 279 '("-i" "-T") 280 280 '("-i")) 281 " *Args passed to inferior shell by M-x shell, if the shell is csh.281 "Args passed to inferior shell by \\[shell], if the shell is csh. 282 282 Value is a list of strings, which may be nil." 283 283 :type '(repeat (string :tag "Argument")) … … 297 297 '("-i") 298 298 '("--noediting" "-i"))) 299 " *Args passed to inferior shell by M-x shell, if the shell is bash.299 "Args passed to inferior shell by \\[shell], if the shell is bash. 300 300 Value is a list of strings, which may be nil." 301 301 :type '(repeat (string :tag "Argument")) … … 303 303 304 304 (defcustom shell-input-autoexpand 'history 305 " *If non-nil, expand input command history references on completion.305 "If non-nil, expand input command history references on completion. 306 306 This mirrors the optional behavior of tcsh (its autoexpand and histlit). 307 307 … … 434 434 (make-local-variable 'shell-last-dir) 435 435 (setq shell-last-dir nil) 436 (make-local-variable 'shell-dirtrackp) 437 (setq shell-dirtrackp t) 438 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t) 436 (shell-dirtrack-mode 1) 439 437 (setq comint-input-autoexpand shell-input-autoexpand) 440 438 ;; This is not really correct, since the shell buffer does not really … … 559 557 buffer) 560 558 561 ;; ;Don't do this when shell.el is loaded, only while dumping.559 ;; Don't do this when shell.el is loaded, only while dumping. 562 560 ;;;###autoload (add-hook 'same-window-buffer-names "*shell*") 563 561 564 562 ;;; Directory tracking 565 ;; ;566 ;; ;This code provides the shell mode input sentinel567 ;; ;SHELL-DIRECTORY-TRACKER568 ;; ;that tracks cd, pushd, and popd commands issued to the shell, and569 ;; ;changes the current directory of the shell buffer accordingly.570 ;; ;571 ;; ;This is basically a fragile hack, although it's more accurate than572 ;; ;the version in Emacs 18's shell.el. It has the following failings:573 ;; ;1. It doesn't know about the cdpath shell variable.574 ;; ;2. It cannot infallibly deal with command sequences, though it does well575 ;; ;with these and with ignoring commands forked in another shell with ()s.576 ;; ;3. More generally, any complex command is going to throw it. Otherwise,577 ;; ;you'd have to build an entire shell interpreter in Emacs Lisp. Failing578 ;; ;that, there's no way to catch shell commands where cd's are buried579 ;; ;inside conditional expressions, aliases, and so forth.580 ;; ;581 ;; ;The whole approach is a crock. Shell aliases mess it up. File sourcing582 ;; ;messes it up. You run other processes under the shell; these each have583 ;; ;separate working directories, and some have commands for manipulating584 ;; ;their w.d.'s (e.g., the lcd command in ftp). Some of these programs have585 ;; ;commands that do *not* affect the current w.d. at all, but look like they586 ;; ;do (e.g., the cd command in ftp). In shells that allow you job587 ;; ;control, you can switch between jobs, all having different w.d.'s. So588 ;; ;simply saying %3 can shift your w.d..589 ;; ;590 ;; ;The solution is to relax, not stress out about it, and settle for591 ;; ;a hack that works pretty well in typical circumstances. Remember592 ;; ;that a half-assed solution is more in keeping with the spirit of Unix,593 ;; ;anyway. Blech.594 ;; ;595 ;; ;One good hack not implemented here for users of programmable shells596 ;; ;is to program up the shell w.d. manipulation commands to output597 ;; ;a coded command sequence to the tty. Something like598 ;; ;ESC | <cwd> |599 ;; ;where <cwd> is the new current working directory. Then trash the600 ;; ;directory tracking machinery currently used in this package, and601 ;; ;replace it with a process filter that watches for and strips out602 ;; ;these messages.563 ;; 564 ;; This code provides the shell mode input sentinel 565 ;; SHELL-DIRECTORY-TRACKER 566 ;; that tracks cd, pushd, and popd commands issued to the shell, and 567 ;; changes the current directory of the shell buffer accordingly. 568 ;; 569 ;; This is basically a fragile hack, although it's more accurate than 570 ;; the version in Emacs 18's shell.el. It has the following failings: 571 ;; 1. It doesn't know about the cdpath shell variable. 572 ;; 2. It cannot infallibly deal with command sequences, though it does well 573 ;; with these and with ignoring commands forked in another shell with ()s. 574 ;; 3. More generally, any complex command is going to throw it. Otherwise, 575 ;; you'd have to build an entire shell interpreter in Emacs Lisp. Failing 576 ;; that, there's no way to catch shell commands where cd's are buried 577 ;; inside conditional expressions, aliases, and so forth. 578 ;; 579 ;; The whole approach is a crock. Shell aliases mess it up. File sourcing 580 ;; messes it up. You run other processes under the shell; these each have 581 ;; separate working directories, and some have commands for manipulating 582 ;; their w.d.'s (e.g., the lcd command in ftp). Some of these programs have 583 ;; commands that do *not* affect the current w.d. at all, but look like they 584 ;; do (e.g., the cd command in ftp). In shells that allow you job 585 ;; control, you can switch between jobs, all having different w.d.'s. So 586 ;; simply saying %3 can shift your w.d.. 587 ;; 588 ;; The solution is to relax, not stress out about it, and settle for 589 ;; a hack that works pretty well in typical circumstances. Remember 590 ;; that a half-assed solution is more in keeping with the spirit of Unix, 591 ;; anyway. Blech. 592 ;; 593 ;; One good hack not implemented here for users of programmable shells 594 ;; is to program up the shell w.d. manipulation commands to output 595 ;; a coded command sequence to the tty. Something like 596 ;; ESC | <cwd> | 597 ;; where <cwd> is the new current working directory. Then trash the 598 ;; directory tracking machinery currently used in this package, and 599 ;; replace it with a process filter that watches for and strips out 600 ;; these messages. 603 601 604 602 (defun shell-directory-tracker (str) … … 608 606 default directory to track these commands. 609 607 610 You may toggle this tracking on and off with M-x dirtrack-mode.611 If Emacs gets confused, you can resync with the shell with M-x dirs.608 You may toggle this tracking on and off with \\[dirtrack-mode]. 609 If Emacs gets confused, you can resync with the shell with \\[dirs]. 612 610 613 611 See variables `shell-cd-regexp', `shell-chdrive-regexp', `shell-pushd-regexp', … … 678 676 string))) 679 677 680 ;; ;popd [+n]678 ;; popd [+n] 681 679 (defun shell-process-popd (arg) 682 680 (let ((num (or (shell-extract-num arg) 0))) … … 704 702 (expand-file-name dir)))) 705 703 706 ;; ;cd [dir]704 ;; cd [dir] 707 705 (defun shell-process-cd (arg) 708 706 (let ((new-dir (cond ((zerop (length arg)) (concat comint-file-name-prefix … … 714 712 (shell-dirstack-message))) 715 713 716 ;; ;pushd [+n | dir]714 ;; pushd [+n | dir] 717 715 (defun shell-process-pushd (arg) 718 716 (let ((num (shell-extract-num arg))) … … 763 761 (string-to-number str))) 764 762 765 766 (def un shell-dirtrack-mode ()763 (defvaralias 'shell-dirtrack-mode 'shell-dirtrackp) 764 (define-minor-mode shell-dirtrack-mode 767 765 "Turn directory tracking on and off in a shell buffer." 768 (interactive)769 ( if (setq shell-dirtrackp (not shell-dirtrackp))770 (setq list-buffers-directory default-directory)771 (setq list-buffers-directory nil))772 (message "Directory tracking %s" (if shell-dirtrackp "ON" "OFF")))773 774 ;; ;For your typing convenience:775 (defalias 'shell-dirtrack-toggle 'shell-dirtrack-mode) 766 nil nil nil 767 (setq list-buffers-directory (if shell-dirtrack-mode default-directory)) 768 (if shell-dirtrack-mode 769 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t) 770 (remove-hook 'comint-input-filter-functions 'shell-directory-tracker t))) 771 772 ;; For your typing convenience: 773 (defalias 'shell-dirtrack-toggle 'shell-dirtrack-mode) ;??Convenience?? 776 774 (defalias 'dirtrack-toggle 'shell-dirtrack-mode) 777 775 (defalias 'dirtrack-mode 'shell-dirtrack-mode) … … 779 777 (defun shell-cd (dir) 780 778 "Do normal `cd' to DIR, and set `list-buffers-directory'." 779 (cd dir) 781 780 (if shell-dirtrackp 782 (setq list-buffers-directory (file-name-as-directory 783 (expand-file-name dir)))) 784 (cd dir)) 781 (setq list-buffers-directory default-directory))) 785 782 786 783 (defun shell-resync-dirs () … … 842 839 (error (message "Couldn't cd"))))))) 843 840 844 ;; ;For your typing convenience:841 ;; For your typing convenience: 845 842 (defalias 'dirs 'shell-resync-dirs) 846 843 847 844 848 ;; ;Show the current dirstack on the message line.849 ;; ;Pretty up dirs a bit by changing "/usr/jqr/foo" to "~/foo".850 ;; ;(This isn't necessary if the dirlisting is generated with a simple "dirs".)851 ;; ;All the commands that mung the buffer's dirstack finish by calling852 ;; ;this guy.845 ;; Show the current dirstack on the message line. 846 ;; Pretty up dirs a bit by changing "/usr/jqr/foo" to "~/foo". 847 ;; (This isn't necessary if the dirlisting is generated with a simple "dirs".) 848 ;; All the commands that mung the buffer's dirstack finish by calling 849 ;; this guy. 853 850 (defun shell-dirstack-message () 854 851 (when shell-dirtrack-verbose … … 1077 1074 (provide 'shell) 1078 1075 1079 ;; ;arch-tag: bcb5f12a-c1f4-4aea-a809-2504bd5bd7971076 ;; arch-tag: bcb5f12a-c1f4-4aea-a809-2504bd5bd797 1080 1077 ;;; shell.el ends here
