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

  1. ;From utkcs2!emory!samsung!usc!snorkelwacker!paperboy!meissner Tue Jun 19 12:06:21 EDT 1990
  2. ;Article 3008 of gnu.emacs:
  3. ;Xref: utkcs2 comp.emacs:4466 gnu.emacs:3008
  4. ;Path: utkcs2!emory!samsung!usc!snorkelwacker!paperboy!meissner
  5. ;>From: meissner@osf.org (Michael Meissner)
  6. ;Newsgroups: comp.emacs,gnu.emacs
  7. ;Subject: Re: cmushell cannot handle cdpath
  8. ;Message-ID: <MEISSNER.90Jun19104034@curley.osf.org>
  9. ;Date: 19 Jun 90 14:40:34 GMT
  10. ;References: <88@ttrnds.UUCP>
  11. ;Sender: news@OSF.ORG
  12. ;Organization: Open Software Foundation
  13. ;Lines: 114
  14. ;In-reply-to: dave@ttrnds.UUCP's message of 18 Jun 90 16:23:03 GMT
  15. ;
  16. ;In article <88@ttrnds.UUCP> dave@ttrnds.UUCP (David M. Karr) writes:
  17. ;
  18. ;| I just installed cmushell.el.  It seems to work pretty well, except
  19. ;| for one really huge problem.  The directory tracker does not know
  20. ;| about directories reached through the "cdpath" variable.  I believe
  21. ;| there was a released solution for this problem to use with shell.el,
  22. ;| but I don't know if that solution will work for cmushell.  I assume it
  23. ;| would have to be SOMETHING like what is done for shell.el.
  24. ;
  25. ;I posted this last year.  If you load the following lisp file, it
  26. ;replaces the 'cd' elisp function, with one that does know about
  27. ;CDPATH.  You have to use load and not autoload, since cd is already
  28. ;bound into emacs.  I use cmushell all of the time, and it works for
  29. ;me.
  30. ;
  31. ;; File input and output commands for Emacs
  32. ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  33.  
  34. ;; This file is part of GNU Emacs.
  35.  
  36. ;; GNU Emacs is distributed in the hope that it will be useful,
  37. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  38. ;; accepts responsibility to anyone for the consequences of using it
  39. ;; or for whether it serves any particular purpose or works at all,
  40. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  41. ;; License for full details.
  42.  
  43. ;; Everyone is granted permission to copy, modify and redistribute
  44. ;; GNU Emacs, but only under the conditions described in the
  45. ;; GNU Emacs General Public License.   A copy of this license is
  46. ;; supposed to have been given to you along with GNU Emacs so you
  47. ;; can know your rights and responsibilities.  It should be in a
  48. ;; file named COPYING.  Among other things, the copyright notice
  49. ;; and this notice must be preserved on all copies.
  50. ;;
  51. ;; Replacement for "cd" that knows about CDPATH.
  52.  
  53. (defun pwd ()
  54.   "Show the current default directory."
  55.   (interactive nil)
  56.   (message "Directory %s" default-directory))
  57.  
  58. (defun cd-orig (dir)
  59.   "Make DIR become the current buffer's default directory."
  60.   (interactive "DChange default directory: ")
  61.   (setq dir (expand-file-name dir))
  62.   (if (not (eq system-type 'vax-vms))
  63.       (setq dir (file-name-as-directory dir)))
  64.   (if (not (file-directory-p dir))
  65.       (error "%s is not a directory" dir)
  66.     (setq default-directory dir))
  67.   (pwd))
  68.  
  69.  
  70. (defun cd-expand-cdpath (dir)
  71.   "Expand DIR like the shells would, by using the environment variable CDPATH
  72. for directory prefixes.  If the directory is not found, the original directory
  73. is returned."
  74.  
  75.   (interactive "FDirectory (uses CDPATH): ")
  76.   (if (string-match "^[/~]" dir)
  77.       dir                ; directory already expanded
  78.     (progn
  79.       (let (done dir2 cd-prefix cd-dir cd-start cd-colon cd-path)
  80.  
  81.     (setq cd-start 0)
  82.     (setq dir2 (substitute-in-file-name dir))
  83.     (if (not (setq cd-path (getenv "CDPATH")))
  84.         (setq cd-path ""))
  85.     
  86.     (while (and cd-path (not done))
  87.       (progn
  88.         (setq cd-colon (string-match ":" cd-path cd-start))
  89.         (setq cd-prefix (substring cd-path cd-start cd-colon))
  90.         (if cd-colon
  91.         (setq cd-start (+ cd-colon 1))
  92.           (setq cd-path nil)
  93.           )
  94.         
  95.         (if (> (length cd-prefix) 0)
  96.         (progn
  97.           (setq cd-dir cd-prefix)
  98.           (if (or (string-equal cd-prefix "~")
  99.               (not (string-equal (substring cd-dir -1) "/")))
  100.               (setq cd-dir (concat cd-dir "/"))
  101.             )
  102.           )
  103.           (setq cd-dir "")
  104.           )
  105.         
  106.         (setq cd-dir (expand-file-name (concat cd-dir dir2)))
  107.         (setq done (file-directory-p cd-dir))
  108.         )
  109.       )
  110.  
  111.     (if done cd-dir dir)
  112.       )
  113.     )
  114.   )
  115. )
  116.  
  117.  
  118. (defun cd (dir)
  119.   "Make DIR become the current buffer's default directory.  Searches the
  120. environment variable CDPATH for directory prefixes, just like the shells."
  121.  
  122.   (interactive "FChange default directory (uses CDPATH): ")
  123.   (cd-orig (cd-expand-cdpath dir))
  124. )
  125. ;--
  126. ;Michael Meissner    email: meissner@osf.org        phone: 617-621-8861
  127. ;Open Software Foundation, 11 Cambridge Center, Cambridge, MA
  128. ;
  129. ;Do apple growers tell their kids money doesn't grow on bushes?
  130.  
  131.  
  132.