home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / fixwd.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  4.4 KB  |  111 lines

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!mips!bridge2!jarthur!spectre.ccsf.caltech.edu!news Sat Mar  3 17:27:34 EST 1990
  2. ;Article 1530 of comp.emacs:
  3. ;Xref: ark1 gnu.emacs:1259 comp.emacs:1530
  4. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!mips!bridge2!jarthur!spectre.ccsf.caltech.edu!news
  5. ;>From: johns@macondo.ccsf.caltech.edu (John Salmon)
  6. ;Newsgroups: gnu.emacs,comp.emacs
  7. ;Subject: Re: Better Directory Tracking Engine for GNU emacs
  8. ;Message-ID: <1990Mar3.011743.11263@spectre.ccsf.caltech.edu>
  9. ;Date: 3 Mar 90 01:17:43 GMT
  10. ;References: <WARSAW.90Mar1192018@rtg.cme.nist.gov>
  11. ;Sender: news@spectre.ccsf.caltech.edu
  12. ;Reply-To: johns@macondo.ccsf.caltech.edu (John Salmon)
  13. ;Followup-To: gnu.emacs
  14. ;Organization: Caltech Concurrent Supercomputing Facility
  15. ;Lines: 91
  16. ;In-Reply-To: warsaw@cme.nist.gov (Barry A. Warsaw)
  17. ;
  18. ;In article <WARSAW.90Mar1192018@rtg.cme.nist.gov>, warsaw@cme (Barry A. Warsaw) writes:
  19. ;>
  20. ;>And the like. Someone mentioned an interesting idea where the pwd
  21. ;>command might be used to resync the tracking engine, but I opted for
  22. ;>an explicit resync command (tk-resync) instead.
  23. ;>
  24. ;etc.
  25. ;>
  26. ;>NAME: Barry A. Warsaw                USMAIL: National Institute of Standards
  27. ;>TELE: (301) 975-3460                         and Technology (formerly NBS)
  28. ;>UUCP: {...}!uunet!cme-durer!warsaw           Rm. B-124, Bldg. 220
  29. ;>ARPA: warsaw@cme.nist.gov                    Gaithersburg, MD 20899
  30. ;>
  31. ;
  32. ;Here is a set of elisp functions that partially automate
  33. ;the process of resync-ing a process buffer.  They send a
  34. ;pwd command to the running process, and then cd to the
  35. ;answer.  I have tried to put in sanity checks, but
  36. ;it still isn't impossible to completely confuse these functions.
  37. ;Thus, the fwd-reset-filter function is provided.
  38. ;
  39. ;I also have some code for following a user's 'cdpath', but
  40. ;it is not nearly so self-contained.  I can post diffs to
  41. ;cmushell.el, if there's interest.
  42. ;
  43. ;John Salmon
  44. ;johns@macondo.ccsf.caltech.edu
  45. ;johns@caltech.bitnet
  46. ;
  47. ;------------------- cut here, filename: fixwd.el  ---------------------
  48. ;; Author: John Salmon
  49. ;; Copyright 1989, John Salmon
  50. ;; Licensing: This software is made available under the terms
  51. ;; of the GNU EMACS GENERAL PUBLIC LICENSE (11 Feb 1989 version)
  52. ;;
  53. ;; An attempt to send 'pwd' to a process running in a buffer
  54. ;; shell, and then use the output
  55. ;; to fix up the current working directory.
  56. ;; As it stands, this should work as well with shell.el, comint.el
  57. ;; or any of their clients.  It would be prettier if it were
  58. ;; merged into comint.el, with an interface using a
  59. ;; local variables like:
  60. ;; (defvar comint-pwd-command "pwd")
  61. ;; Another necessary improvement is some kind of timeout,
  62. ;; if the process does not respond to the 'pwd' command.
  63. ;;
  64. ;; Usage:
  65. ;; I have the following in my .emacs (this file is called fixwd.el)
  66. ;; (autoload 'fwd "fixwd"
  67. ;;      "Use pwd to repair a process buffer's notion of current-directory"
  68. ;;      t)
  69. ;; (setq cmushell-load-hook
  70. ;;       '((lambda () 
  71. ;;       (define-key cmushell-mode-map "\C-cf" 'fwd))))
  72. ;;
  73. ;;
  74. (provide 'fwd)
  75.  
  76. (defvar pwd-old-filter nil "The previous filter, in place before the fixwd.")
  77.  
  78. (defun pwd-filter (proc str) 
  79.   "STR should be the output from pwd.  We peel off the terminal
  80. newline, and hand it to the elisp function cd.  Thus, we go to
  81. where the PROC really is.  In addition, we return filtering
  82. for PROC to whatever was doing it before.  See also fwd."
  83.   (set-process-filter proc pwd-old-filter)
  84.   (let ((to (substring str 0 (string-match "\n" str))))
  85.     (if (file-directory-p to)
  86.     (cd to)
  87.       (message "Strange reply from pwd: %s" to))))
  88.  
  89. (defun fwd ()
  90.   "Fix up the current directory, by using (process-send-string \"pwd\")
  91. to enquire directly, and then cd'ing to the answer.  Only valid in
  92. a buffer with an active process."
  93.   (interactive)
  94.   (make-local-variable 'pwd-old-filter)
  95.   (let* ((proc (get-buffer-process (current-buffer))))
  96.     (if    (processp proc)
  97.     (progn
  98.       (set-variable 'pwd-old-filter (process-filter proc))
  99.       (set-process-filter proc 'pwd-filter)
  100.       (process-send-string proc "pwd\n"))
  101.       (error "Can't fix working directory if there is no process."))))
  102.  
  103. (defun fwd-reset-filter() "If fwd got very confused, this may be necessary."
  104.   (interactive)
  105.   (let ((proc (get-buffer-process (current-buffer))))
  106.     (if (processp proc)
  107.     (set-process-filter proc nil) ;; pwd-old-filter may be wrong!
  108.       (error "Can't reset the process filter if there's no process."))))
  109.  
  110.  
  111.