home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / interfaces / rcs.shar / rcsco < prev    next >
Encoding:
Text File  |  1989-06-27  |  2.7 KB  |  69 lines

  1. This file was taken from a news posting on 10 Jan 87 in comp.emacs.
  2. Original author is:
  3. Mark A. Yoder <yoder@pur-ee.UUCP>
  4. seismo!gatech!cuae2!ihnp4!inuxc!pur-ee!yoder
  5.  
  6. [ I replaced (my-string-match) with calls to (file-name-directory)
  7.   and (file-name-nondirectory).  Added a (cd dir) before attempting
  8.   the co. - Ed Simpson ]
  9.   
  10. Ed Simpson's emacs/RCS provides a nice method for checking files into RCS
  11. from emacs.  The following function complements his routines
  12. nicely in that it provides a nice way to automatically checkout files.
  13.  
  14. This function uses the find-file-not-found-hooks in version 18
  15. (or find-file-not-found-hook in version 17).  When (find-file) cannot
  16. find a given file the (my-RCS-file) function will look to see if there is
  17. an RCS version of the file.  If so, it will ask if it should be checked
  18. and if it should be locked.  If is is not locked, the file will be checked
  19. out and read into a buffer and then deleted.  
  20.  
  21. This works nicely with TAGS if you run etags on all your files before checking
  22. them in.
  23.  
  24. Put the following in your .emacs file:
  25.  
  26. (setq find-file-not-found-hooks 'my-RCS-file) ; version 18 emacs
  27.  
  28. or:
  29.  
  30. (setq find-file-not-found-hook 'my-RCS-file) ; version 17 emacs
  31.  
  32. The load the following into emacs:
  33.  
  34. ;;;
  35. ;;; The following uses the find-file-not-found-hook to look for a file
  36. ;;; in the RCS directory.  If a file isn't found, RCS/filename,v is
  37. ;;; first checked, and then filename,v is checked to see if the file
  38. ;;; checked into RCS.  If it is not found, my-RCS-file does nothing.
  39. ;;; If it is found, the user is asked if they want to check the file out,
  40. ;;; and if they want it locked.
  41.  
  42. (defun my-RCS-file ()
  43.         ;; Set dir to the directory the file is to be in.
  44.   (let ((dir (file-name-directory buffer-file-name))
  45.     ;; Set file to the name of the file excluding the path.
  46.     (file (file-name-nondirectory buffer-file-name)))
  47.     ;; Look for the RCS file
  48.     (if (or
  49.      (file-exists-p (concat dir "RCS/" file ",v"))
  50.      (file-exists-p (concat buffer-file-name ",v")))
  51.     ;; if found, ask the user if they want it checked out.
  52.       (if (y-or-n-p (message "Can't find \"%s\", shall I check it out? "
  53.                  file))
  54.       ;; If it is to be check out, ask about locking it.
  55.       (progn
  56.         (cd dir)
  57.         (if (y-or-n-p "Shall I lock it? ")
  58.         ;; Check the file out, but don't send input to "co", or
  59.         ;; read the output from co.  This could cause problems
  60.         ;; if "co" couldn't check the file out.
  61.         (call-process "co" nil nil nil "-l" filename)
  62.           (call-process "co" nil nil nil filename))
  63.         ;; If the file is now there, read it in
  64.         (if (file-exists-p filename)
  65.         (progn
  66.           (insert-file-contents filename t)
  67.           (setq error nil))
  68.           (error "Couldn't check out \"%s\"!" file)))))))
  69.