SCCS vs RCS under emacs

Lars Pensj| lars at myab.se
Tue Jul 11 19:48:48 AEST 1989


I have also written a package for emacs for using sccs.
It automatically detects an sccs file and does 'get' or 'delta' with
comments from the user.

We usually store the s-files in a subdirectory called '.sc'.

#--------CUT---------CUT---------CUT---------CUT--------#
#########################################################
#                                                       #
# This is a shell archive file.  To extract files:      #
#                                                       #
#    1)	Make a directory for the files.                 #
#    2) Write a file, such as "file.shar", containing   #
#       this archive file into the directory.           #
#    3) Type "sh file.shar".  Do not use csh.           #
#                                                       #
#########################################################
#
#
echo Extracting sccs.el:
sed 's/^Z//' >sccs.el <<\STUNKYFLUFF
Z;;
Z;; @(#)sccs.el	1.9 89/06/19 14:28:41
Z;;
Z;; A package for using sccs in emacs.
Z;;
Z;; You have to create the g-file and s-file manually.
Z;;
Z;; No special commands has to be called, everything is done automatically
Z;; because emacs knows when a file is an sccs-file.
Z;;
Z;; Saving a g-file:
Z;;	Emacs will detect that a saving of a sccs-file (through
Z;;	write-file-hooks) and ask if to make a delta. It will then
Z;;	ask for a comment and make the delta. Do NOT use ' in the comment.
Z;;
Z;; Loading a g-file:
Z;;	When a readonly g-file is loaded, the only action is to locally rebind
Z;;	^X^Q to sccs-toggle-read-only (instead of toggle-read-only).
Z;;	When the user wants to change the file (which is readonly),
Z;;	he will type ^X^Q and will be asked if he want to "get" the
Z;;	file for editing.
Z;;
Z;; To load this file automatically, put (require 'sccs)
Z;; in your .emacs.
Z;;
Z;; The s-files can be kept at another directory than the g-file.
Z;; Change sccs-make-special-file-name to reflect your needs.
Z;;
Z;; First version of sccs.el created March 10, 1989 by Lars Pensj|, lars at myab.se
Z;;
Z
Z(provide 'sccs)
Z
Z;
Z; This function defines where to find the special sccs files, given the g-file.
Z; FILE is the full path name.
Z;
Z(defun sccs-make-special-file-name (type file)
Z  "Construct the special p-files or s-files TYPE from file FILE.
Z   This should probably be configured differently for other users."
Z  (concat (file-name-directory file) ".sc/"
Z	  type (file-name-nondirectory file)))
Z
Z(defconst sccs-scratch-buffer "*sccs-scratch*"
Z  "Scratch buffer used by the sccs-package.")
Z
Z(defconst sccs-log-file "LOG"
Z  "*A file where all delta comments will be added.")
Z
Z(defun sccs-append-log (comment file)
Z  "Append the delta comment on a log file, if sccs-log-file is non nil."
Z  (interactive "sComment: \nfFile: ")
Z  (if sccs-log-file
Z      (progn
Z	(call-process "/bin/sh" nil nil nil "-c"
Z		      (message "%s" (format "echo \"%s %s `date %s` %s\" >> %s"
Z			      (getenv "LOGNAME")
Z			      (file-name-nondirectory file)
Z			      "'+%a %h %d %T'"
Z			      comment
Z			      sccs-log-file))))))
Z
Z(defun sccs-get-file (s-file directory)
Z  "Use get(1) to extract a S-FILE for editing into DIRECTORY."
Z  (message "get -e %s" s-file)
Z  (let ((buffer (get-buffer-create sccs-scratch-buffer)))
Z    (set-buffer buffer)
Z    (setq default-directory directory)
Z    (erase-buffer)
Z    (call-process "/usr/bin/get" nil buffer nil "-e" s-file)
Z    (sccs-check-result)
Z    ))
Z
Z;
Z; Called automatically through write-file-hooks.
Z; If it is an sccs-file, ask user if to do a delta.
Z;
Z(defun sccs-check-for-delta ()
Z  "Check if a file to be written should make a delta."
Z  (interactive)
Z  (let* ((file (buffer-file-name))
Z	(s-file (sccs-make-special-file-name "s." file))
Z	(p-file (sccs-make-special-file-name "p." file))
Z	(buffer (current-buffer))
Z	(directory (file-name-directory file))
Z	(oline (sccs-current-line))
Z	(ocol (current-column))
Z	(query (format "Make delta for %s " file)))
Z    (if (file-exists-p s-file)
Z	(progn
Z	  (if (not (file-exists-p p-file))
Z	      (error "No p-file: %s" p-file))
Z	  (if (not (file-writable-p file))
Z	      (error "You can not write file %s" file))
Z	  (if (yes-or-no-p query)
Z	      (progn
Z		(if (buffer-modified-p)
Z		    (write-region (point-min) (point-max) file nil t))
Z		(set-buffer (get-buffer-create sccs-scratch-buffer))
Z		(setq default-directory directory)
Z		(let ((comment (read-input "Comment: ")))
Z		  (message "delta -y'%s' %s" comment s-file)
Z		  (erase-buffer)
Z		  (call-process "/usr/bin/delta" nil t nil
Z				(concat "-y'" comment "'")
Z				s-file)
Z		  (sccs-append-log comment file))
Z		(sccs-check-result)
Z		(message "get %s" s-file)
Z		(call-process "/usr/bin/get" nil t nil s-file)
Z		(sccs-check-result)
Z		(set-buffer buffer)
Z		(setq buffer-file-name nil)
Z		(erase-buffer)
Z		(insert-file-contents file t)
Z		(setq buffer-read-only t)
Z		(goto-line oline)
Z		(sccs-goto-col ocol)
Z		(local-set-key "\C-X\C-Q" 'sccs-toggle-read-only)
Z		t
Z		)
Z	    nil
Z	    )
Z	  ))))
Z
Z(defun sccs-check-result ()
Z  "Check the result of an sccs operation. If okey, display it.
ZThe result is in the sccs scratch buffer."
Z  (set-buffer-modified-p nil)
Z  (goto-char (point-min))
Z  (if (re-search-forward "ERROR.*" (point-max) t)
Z      (error "%s"
Z	     (buffer-substring (match-beginning 0) (match-end 0))))
Z  (replace-string "\n" ", ")
Z  (message "%s" (buffer-substring (point-min) (point-max)))
Z  (erase-buffer)
Z  (set-buffer-modified-p nil))
Z
Z;
Z; Called through find-file-hooks.
Z;
Z(defun sccs-check-for-get ()
Z  "If current file is a readonly sccs-file, then rebind ^X^Q to
Zsccs-toggle-read-only."
Z  (let ((s-file (sccs-make-special-file-name "s." buffer-file-name)))
Z    (if (and
Z	 (file-exists-p s-file)
Z	 buffer-read-only
Z	 (not (buffer-modified-p)))
Z	(local-set-key "\C-X\C-Q" 'sccs-toggle-read-only)
Z      )))
Z
Z;
Z;The user wants to modify this file (it is read-only). Ask him if
Z;he wants to get the sccs file for editing, or only toggle read-only.
Z;
Z(defun sccs-toggle-read-only ()
Z  "Get sccs file for editing or just toggle read-only flag."
Z  (interactive)
Z  (let* ((file (buffer-file-name))
Z	 (attr (file-attributes file))
Z	 (s-file (sccs-make-special-file-name "s." file))
Z	 (already-edited (file-exists-p
Z			  (sccs-make-special-file-name "p." file)))
Z	 (ocol (current-column))
Z	 (oline (sccs-current-line))
Z	 (buffer (buffer-name)))
Z    (if (not (file-exists-p s-file))
Z	(toggle-read-only)
Z      (if (and
Z	   attr
Z	   (string= "-r--r--r--" (nth 8 attr))
Z	   (not (buffer-modified-p))
Z	   buffer-read-only
Z	   (not already-edited))
Z	  (progn
Z	    (if (y-or-n-p "get sccs file for modification ")
Z		(progn
Z		  (sccs-get-file (sccs-make-special-file-name "s." file)
Z				 (file-name-directory file))
Z		  (switch-to-buffer buffer)
Z		  (setq buffer-file-name nil)
Z		  (setq buffer-read-only nil)
Z		  (erase-buffer)
Z		  (insert-file-contents file t)
Z		  (goto-line oline)
Z		  (sccs-goto-col ocol))
Z	      (toggle-read-only)))
Z	(if already-edited
Z	    (error "File is being edited by: %s" (sccs-get-name-of-owner file))
Z	  (toggle-read-only)))
Z      )))
Z
Z(defun sccs-get-name-of-owner (file)
Z  "Get the name of the person owning FILE."
Z  (setq file (expand-file-name file))
Z  (let ((p-file (sccs-make-special-file-name "p." file)))
Z    (if (not (file-exists-p p-file))
Z	(error "No p-file %s" p-file))
Z    (set-buffer (get-buffer-create sccs-scratch-buffer))
Z    (erase-buffer)
Z    (insert-file-contents p-file nil)
Z    (goto-char (point-min))
Z    (re-search-forward ".* .* \\(.* .* .*\\)")
Z    (buffer-substring (match-beginning 1) (match-end 1))))
Z
Z(defun sccs-current-line ()
Z  "Get the current line number."
Z  (save-restriction
Z    (widen)
Z    (save-excursion
Z      (beginning-of-line)
Z      (1+ (count-lines 1 (point))))))
Z
Z(defun sccs-goto-col (col)
Z  "Move to colomn COL, compensating for tabs."
Z  (while (and (< (current-column) col) (not (= (point) (point-max))))
Z    (forward-char)))
Z
Z(setq write-file-hooks (cons 'sccs-check-for-delta write-file-hooks))
Z(setq find-file-hooks (cons 'sccs-check-for-get find-file-hooks))
STUNKYFLUFF
set `wc sccs.el`
if test 221 != $1
then
echo sccs.el: Checksum error. Is: $1, should be: 221.
fi
echo All done
exit 0
-- 
    Lars Pensj|
    lars at myab.se



More information about the Comp.unix.questions mailing list