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

  1. ;From tegra!vail@uunet.uu.net Fri Jul 20 13:29:03 1990
  2. ;From: tegra!vail@uunet.uu.net
  3. ;Date: Fri, 20 Jul 90 11:13:01 EDT
  4. ;To: uunet!stc06.CTD.ORNL.GOV!de5@uunet.UU.NET
  5. ;In-Reply-To: SILL D E's message of Fri, 20 Jul 90 10:59:43 EDT <9007201459.AA14712@stc06.CTD.ORNL.GOV>
  6. ;Subject: SCCS elisp package
  7. ;
  8. ;
  9. ;Here is my SCCS code.  The RCS version bas done by a friend of a
  10. ;friend (don@coral.com??).
  11. ;
  12. ;If you need anything else to go with it, let me know.
  13. ;
  14. ;Shar and Enjoy, jv
  15. ;
  16. ;Stattinger's Law: It works better if you plug it in.
  17. ; _____
  18. ;|     | Johnathan Vail | n1dxg@tegra.com
  19. ;|Tegra| (508) 663-7435 | N1DXG@448.625-(WorldNet)
  20. ; -----  jv@n1dxg.ampr.org {...sun!sunne ..uunet}!tegra!vail
  21.  
  22.  
  23. ;;;;
  24. ;;;;    sccs.el
  25. ;;;;
  26. ;;;;              "SCCS: The condom of promiscuous programmers"
  27. ;;;;
  28. ;;;;    Written November 1989 Johnathan Vail, Tegra Varityper
  29. ;;;;        tegra!vail@ulowell.edu    sunne!tegra!vail@sun.com
  30. ;;;;        ...uunet!tegra!vail
  31. ;;;;        (508) 663-7435
  32. ;;;;
  33. ;;;;    Perform common sccs commands from within Emacs with a
  34. ;;;;        minimum of hassle.  See the following set-keys
  35. ;;;;        for the defined functions.
  36. ;;;;
  37. ;;;;    This file is not part of GNU Emacs although FSF is
  38. ;;;;    welcome to it, as is anyone else who finds it useful.
  39. ;;;;
  40. ;;;;    RESTRICTIONS ON DISTRIBUTION:
  41. ;;;;        Share and Enjoy
  42. ;;;;    (Please keep my name attached somewhere to feed my own vanity)
  43. ;;;;
  44. ;;;;    Revision History:
  45. ;;;;
  46. ;;;;     5 Dec 1989 JV    - Pretty up comments
  47. ;;;;    14 Nov 1989 JV    - Examine error list to decide to reparse errors
  48. ;;;;    10 Nov 1989 JV    - Add next-error hacks
  49. ;;;;     8 Nov 1989 JV    - Add Comment defaults
  50. ;;;;     7 Nov 1989 JV    - Fix column position bug
  51. ;;;;     6 Nov 1989 JV    - Another day, another hack
  52. ;;;;
  53.  
  54.  
  55.  
  56.  
  57. (defvar sccs-buffer "*SCCS*"
  58.   "Buffer name used for sccs command output")
  59.  
  60.  
  61.  
  62. (global-set-key "\C-ci" 'sccs-info)
  63. (global-set-key "\C-cp" 'sccs-prt)
  64. (global-set-key "\C-cg" 'sccs-get)
  65. (global-set-key "\C-ce" 'sccs-edit)
  66. (global-set-key "\C-cE" 'sccs-delget)
  67. (global-set-key "\C-cN" 'sccs-create)
  68.  
  69.  
  70.  
  71.  
  72.  
  73. (defun sccs-create (revision)
  74.   "Put the current file into SCCS"
  75.  
  76.   (interactive "sVersion? ")
  77.  
  78.   (let ((fname (buffer-file-name)))
  79.     (maybe-save)
  80.     (message "Putting %s into SCCS..." (file-name-nondirectory fname))
  81.     (sccs-do "create" fname revision)))
  82.  
  83.  
  84.  
  85.  
  86.  
  87. (defun sccs-get (revision)
  88.   "Get the file from sccs, asking for a REVISION"
  89.  
  90.   (interactive "sVersion? ")
  91.  
  92.   (let ((fname (buffer-file-name)))
  93.     (maybe-save)
  94.     (message "Getting file %s from SCCS..." (file-name-nondirectory fname))
  95.     (sccs-do "get" fname revision)))
  96.  
  97.  
  98.  
  99.  
  100.  
  101. (defun sccs-edit ()
  102.   "If the buffer is read only then do a `sccs edit' and re-read the buffer"
  103.  
  104.   (interactive)
  105.  
  106.   (if buffer-read-only ()
  107.     (error "Current buffer is writeable"))
  108.  
  109.   (let ((fname (buffer-file-name)))
  110.     (message "Getting file %s from SCCS for editing..." (file-name-nondirectory fname))
  111.  
  112.     (sccs-do "edit" fname)))
  113.  
  114.  
  115.  
  116.  
  117. ;;;
  118. ;;; sccs-delget
  119. ;;;
  120. ;;; This function will try to default the comment string to the revision
  121. ;;; history comment that you just put it.  It does this by looking for the
  122. ;;; first datestamp (for today!) and using anything after it for the comment
  123. ;;; Of course if you don't use tegra-datestamp then you will have no default.
  124. ;;; (Of course you could define tegra-date-stamp to return a string that
  125. ;;;  will determine the start of your header comment and that will work)
  126. ;;;
  127. ;;; tegra-datestamp is a local hack that returns a string such as
  128. ;;; " 5 Dec 1989 JV    - " that is used for this company's coding standards.
  129. ;;; It is defined in a file called tegra.el and is very company specific that
  130. ;;; it is not of general use.  You could define tegra datestamp to something
  131. ;;; useful, take it our completely or ignore it since it checks first to see
  132. ;;; if it exists.  If you would like a copy of tegra.el just ask.  It includes
  133. ;;; the datestamp function, automagic function and files headers and such.
  134. ;;;
  135.  
  136. (defun sccs-delget (comments)
  137.   "sccs delget command on current file, replacing this version in SCCS"
  138.  
  139.   (interactive (list (read-string "Comments? "
  140.                   (save-excursion
  141.                     (and (fboundp 'tegra-datestamp)
  142.                      (goto-char (point-min))
  143.                      (re-search-forward (concat (tegra-datestamp)
  144.                                  "\\(.*$\\)") nil t)
  145.                      (buffer-substring (match-beginning 1) (match-end 1)))))))
  146.   (let ((fname (buffer-file-name)))
  147.     (maybe-save)
  148.     (message "Putting %s back into SCCS..." (file-name-nondirectory fname))
  149.  
  150.     (sccs-do "delget" fname nil comments)))
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. (defun sccs-info ()
  158.   "Show SCCS info"
  159.  
  160.   (interactive)
  161.  
  162.   (message "Getting  SCCS info...")
  163.   (sccs-do "info"))
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171. (defun sccs-prt ()
  172.   "Show history for current file"
  173.  
  174.   (interactive)
  175.  
  176.   (let ((fname (buffer-file-name)))
  177.     (message "Getting SCCS history for %s..." (file-name-nondirectory fname))
  178.     (sccs-do "prt" fname)))
  179.  
  180.  
  181.  
  182.  
  183. ;;;
  184. ;;; sccs-do
  185. ;;;
  186. ;;; This is the function that does all the work.  As such, it has a lot of
  187. ;;; hacks to handle all the different uses it may be exposed to.  Generally
  188. ;;; this function will call sccs with appropriate args, then parse the output
  189. ;;; for re-display on the echo line or display in the other window.  It also
  190. ;;; will re-load the file and re-position the cursor where it was where it
  191. ;;; started.  This makes the sccs-commands almost transparent when used.
  192. ;;;
  193. ;;;
  194. ;;; For use with next-error and the *compilation* buffer, a lot of logic has
  195. ;;; been added to make that work transparently.  I will try to explain:
  196. ;;;
  197. ;;; First, if you don't use compilation and error commands then sccs-do
  198. ;;;   should not barf or do anything special.
  199. ;;;
  200. ;;; The next-error command keeps a list of errors, each error is a list of
  201. ;;;   the mark in the *compilation* buffer where the error was found and a
  202. ;;;   mark in the source file.
  203. ;;;
  204. ;;; If you now go and use the sccs-command to get the file out of sccs then
  205. ;;;   when sccs-do loads the version the markers in the error list
  206. ;;;   are no longer valid.
  207. ;;;
  208. ;;; The first attempt to fix this was to kill the error list and set the parse
  209. ;;;   point in the *compilation* buffer to be where we left off.  This would
  210. ;;;   cause a re-parse when next-error was called and the reparse would start
  211. ;;;   from the current error and all would be well, except:
  212. ;;;
  213. ;;; If your editing to the file causes lines to be inserted or deleted then
  214. ;;;   next-error, when it re-parses will set the new marks to the old lines.
  215. ;;;
  216. ;;; The solution to this is to see if the file being edited is on the error
  217. ;;;   list at all (so we don't waste our time reparsing when we don't need to)
  218. ;;;   *before* we mung the markers with loading a new file.
  219. ;;;
  220. ;;; Finally, if it is on the error list and a new file is loaded then reparse
  221. ;;;   the errors from the current error. NP.
  222. ;;;
  223. ;;; Hope this helps, jv
  224. ;;;
  225.  
  226. (defun sccs-do (command  &optional fname revision comments)
  227.   "Exec sccs COMMAND on FNAME, with optional REVISION and COMMENTS"
  228.  
  229.   (let ((line-num (count-lines (point-min) (point)))
  230.     column-num sccs-buf re-parse cbuf)
  231.     (save-excursion
  232.       (set-buffer (setq sccs-buf (get-buffer-create sccs-buffer)))
  233.       (widen) (erase-buffer))
  234.  
  235.     (if (not fname)            ; two different flavors, might be combined..
  236.     (call-process "sccs" nil sccs-buf nil command)
  237.       (call-process "sccs" nil sccs-buf nil command fname
  238.             (if (or (not revision) (equal revision "")) "" (concat "-r" revision))
  239.             (if comments (concat "-y" comments) ""))
  240.       (if (buffer-modified-p) ()
  241.     (setq re-parse (and (boundp 'compilation-parsing-end)
  242.                 (boundp 'compilation-error-list)
  243.                 (listp compilation-error-list)
  244.                 (setq cbuf (current-buffer))
  245.                 (memq t (mapcar '(lambda (l)
  246.                            (eq cbuf
  247.                            (marker-buffer (car (cdr l)))))
  248.                         compilation-error-list))))
  249.     (setq column-num (- (point) (progn (beginning-of-line) (point))))
  250.     (find-alternate-file fname)
  251.     (goto-line line-num)
  252.     (or (> column-num 0)
  253.         (eq line-num 0)
  254.         (forward-line 1))
  255.     (goto-char (+ (point) column-num))
  256.  
  257.     (if (not re-parse) ()
  258.       (setq compilation-parsing-end (car (car compilation-error-list)))
  259.       (setq compilation-error-list nil)
  260.       (if (setq cbuf (get-buffer "*compilation*"))
  261.           (save-excursion
  262.         (switch-to-buffer cbuf)
  263.         (set-buffer-modified-p nil)
  264.         (compilation-parse-errors))))))
  265.  
  266.     (save-excursion
  267.       (set-buffer sccs-buf)
  268.       (goto-char (point-min))
  269.       (message
  270.        (format "%s %s: %s" command (if fname (file-name-nondirectory fname) "")
  271.            (cond ((looking-at "ERROR.*$")
  272.               (buffer-substring (match-beginning 0)(match-end 0)))
  273.              ((re-search-forward "^\\([0-9.]+\\)[^0-9.]new delta \\([0-9.]+\\)[^0-9.]\\([0-9]+\\) lines" nil t)
  274.               (format "%s->%s %s lines"
  275.                   (buffer-substring (match-beginning 1)(match-end 1))
  276.                   (buffer-substring (match-beginning 2)(match-end 2))
  277.                   (buffer-substring (match-beginning 3)(match-end 3))))
  278.              ((re-search-forward "^\\([0-9.]+\\)[^0-9.]\\([0-9.]+ inserted\\)[^0-9.]\\([0-9]+ deleted\\)$" nil t)
  279.               (format "%s  %s, %s"
  280.                   (buffer-substring (match-beginning 1)(match-end 1))
  281.                   (buffer-substring (match-beginning 2)(match-end 2))
  282.                   (buffer-substring (match-beginning 3)(match-end 3))))
  283.              ((re-search-forward "^[0-9.]+$" nil t)
  284.               (buffer-substring (match-beginning 0)(match-end 0)))
  285.              (t (delete-other-windows)
  286.             (split-window)
  287.             (set-window-buffer (selected-window) sccs-buf)
  288.             (other-window 1)
  289.             "Type C-x 1 to remove SCCS window")))))))
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. (defun maybe-save ()
  299.   "Maybe save the current file"
  300.  
  301.   (and
  302.    (buffer-modified-p)
  303.    (y-or-n-p (format "Save file %s? " buffer-file-name))
  304.  
  305.    (save-buffer)))
  306.