home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / sable.zip / SABLE.EL < prev   
Lisp/Scheme  |  1993-03-25  |  18KB  |  493 lines

  1. ; Newsgroups: gnu.emacs.sources
  2. ; Path: hal.com!decwrl!sun-barr!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!bgsuvax!att!att!dptg!ucs!skdutta
  3. ; From: skdutta@ucs.att.com (Saumen Dutta)
  4. ; Subject: emacs front end for sable.
  5. ; Organization: AT&T Universal Card Services, Jacksonville FL
  6. ; Date: Mon, 9 Nov 1992 10:13:09 GMT
  7. ; Sable is a product for managing configuration control and releases of 
  8. ; software. The command set of sable is extensive and complicated. The
  9. ; command line interface requires the presence of Korn Shell. It has
  10. ; a curses interface too but that requires user to type many fields
  11. ; before a command can be executed. The following utility helps users
  12. ; to use the power of emacs and execute sable commands from within
  13. ; emacs. You need to have sable and korn shell to use this.
  14. ;;
  15. ;;
  16. ;; sable.el -- front end code for using Sable from GNU Emacs
  17. ;;             by Saumen K. Dutta (skdutta@ucs.att.com)
  18. ;;             v1.0 October 31 1992
  19. ;;
  20. ;;
  21.  
  22. ;; LCD Archive Entry:
  23. ;; sable|Saumen Dutta|skdutta@ucs.att.com|
  24. ;; Front end code for using Sable from GNU Emacs|
  25. ;; 92-10-31|1.0|~/interfaces/sable.el.Z|
  26.  
  27. ;;
  28. ;; Description:
  29. ;;       sable.el is a GNU Emacs utility to help Assigned Developers
  30. ;; to interact with sable in a friendly manner. Most of the commands
  31. ;; are reduced to simple keystrokes. Parameters of the frequently used
  32. ;; commands are stored and can be reused. Issuing of edget and edput
  33. ;; to get and put files are not required as the program can find out
  34. ;; the next logical operation. Buffers are loaded direcly from the 
  35. ;; command so that all the required sable commands and file editing can
  36. ;; be tackled from the same emacs environment. Limited report and query
  37. ;; support is also available.
  38. ;;
  39. ;;
  40.  
  41. ;;
  42. ;; Use:
  43. ;;    To start the environment you need to issue `M-x sable'. From then on
  44. ;; all global keymapping will take into effect. Press C-ch for help
  45. ;;
  46.  
  47. ;;
  48. ;; User Modifiable Variables (don't modify these unless you are required to!)
  49. ;;
  50.  
  51. (defvar sable-ksh-program "ksh" "The korn shell executable")
  52. (defvar sable-buffer "*sable*" "Name of the sable buffer")
  53.  
  54. ;;;
  55. ;;; VARIABLES
  56. ;;;
  57.  
  58. (defvar sable-ksh-process nil "Process running the sable")
  59. (defvar sable-generic nil "Name of the sable generic")
  60. (defvar sable-mr nil "Name of the sable modification request")
  61. (defvar sable-dir nil "directory from where edgotten in sable")
  62. (defvar sable-command nil "sable command string to be executed")
  63. (defvar sable-process-status nil "Status of the sable process, The following
  64.   conventions are followed, 0 = sable process has started, 1 = sable process
  65.   has returned successfully and 2 = sable process has failed")
  66. (defvar sable-file nil "file to be operated upon by sable")
  67. (defvar sable-autodependency nil "level of autodependency")
  68. (defvar sable-query-relation nil "relation name of the sable query")
  69.  
  70.  
  71. (defun sable-start-ksh ()
  72.     "Start the ksh and initialize sable environment"
  73.     ;; first time or if process dies
  74.     (if (and (processp sable-ksh-process)
  75.          (or (eq 'stop (process-status sable-ksh-process))
  76.          (eq 'run (process-status sable-ksh-process)))) nil
  77.     (setq sable-ksh-process   ;; [re]start the ksh process
  78.           (start-process "sable" 
  79.                  (get-buffer-create sable-buffer) 
  80.                  sable-ksh-program))
  81.     (save-excursion
  82.       (set-buffer sable-buffer)
  83.       (set-marker (process-mark sable-ksh-process) 1)))
  84.     (set-process-filter sable-ksh-process 'sable-filter)
  85.         (process-kill-without-query sable-ksh-process)
  86.     (setq sable-command (concat ". sablime " sable-generic))
  87.     (sable-process-command)
  88.     (message "Done!"))
  89.  
  90.  
  91. (defun sable-filter(process input)
  92.   "Filter for the Sable process to catch sable errors"
  93.   (let ((old-buffer (current-buffer)))
  94.     (unwind-protect
  95.     (set-buffer (process-buffer process))
  96.     (save-excursion
  97.       (goto-char (process-mark process))
  98.       (insert input)
  99.       (set-marker (process-mark process) (point)))
  100.       (goto-char (process-mark process))
  101.       (set-buffer old-buffer)))
  102.       
  103.   ;; search for the bell character in the input
  104.   (if (eq nil (string-match "\007" input)) (setq sable-process-status 1)
  105.     (progn (display-buffer (process-buffer process))
  106.        (setq sable-process-status 2)
  107.        (error "Sable Error..." ))))
  108.  
  109.  
  110. (defun sable-process-command()
  111.   "Process the sable command"
  112.   (setq sable-process-status 0)
  113.   (message "Sending command to sable...")
  114.   (save-excursion
  115.     (set-buffer (process-buffer sable-ksh-process))
  116.     (erase-buffer))
  117.   (process-send-string sable-ksh-process 
  118.                (concat sable-command "\n")) 
  119.   (accept-process-output)
  120.   ;; guarantees that the sable buffer is loaded fully
  121.   (while (eq sable-process-status 0) (sleep-for 1)))
  122.  
  123.  
  124.  
  125. (defun sable-edget-(&optional long)
  126.   "short edget without a parameter, long edget with one"
  127.   (if (buffer-file-name) 
  128.       (progn (setq sable-file (file-name-nondirectory buffer-file-name))
  129.          (if (or (eq sable-mr nil) long)
  130.          (setq sable-mr (read-string "MR Number: " sable-mr)))
  131.          (if (or (eq sable-dir nil) long)
  132.          (setq sable-dir (read-string "Directory: " sable-dir)))
  133.          ;; Change the directory to the buffer's one before composing the command
  134.          (setq sable-command (concat "cd " (file-name-directory buffer-file-name) "; "))
  135.          ;; Now form the sable command from the global variables
  136.          (setq sable-command (format 
  137.                   "%s edget g=%s mr=%s rm=y dir=%s srf=%s prompt=n"
  138.                   sable-command sable-generic sable-mr sable-dir
  139.                   sable-file))
  140.          (sable-process-command)
  141.          (if (eq sable-process-status 1) 
  142.          (progn
  143.            ;; making sure that the file is gotten properly
  144.            (while (eq (file-writable-p buffer-file-name) nil) (sleep-for 1))           
  145.            (revert-buffer nil t)
  146.            (message "Done!"))))
  147.     (error "There is no file associated with buffer %s" (buffer-name))))
  148.  
  149.  
  150. (defun sable-unedget-(&optional long)
  151.   "short unedget without a parameter, long unedget with one"
  152.   (if (buffer-file-name) 
  153.       (progn (setq sable-file (file-name-nondirectory buffer-file-name))
  154.          (if (or (eq sable-mr nil) long)
  155.          (setq sable-mr (read-string "MR Number: " sable-mr)))
  156.          (if (or (eq sable-dir nil) long)
  157.          (setq sable-dir (read-string "Directory: " sable-dir)))
  158.          ;; Change the directory to the buffer's one before composing the command
  159.          (setq sable-command (concat "cd " (file-name-directory buffer-file-name) "; "))
  160.          ;; Now form the sable command from the global variables
  161.          (setq sable-command (format 
  162.                   "%s unedget g=%s mr=%s dir=%s srf=%s prompt=n"
  163.                   sable-command sable-generic sable-mr sable-dir
  164.                   sable-file))
  165.          (sable-process-command)
  166.          (if (eq sable-process-status 1) 
  167.          (progn
  168.            ;; making sure that the file is gotten properly
  169.            (while (eq (file-writable-p buffer-file-name) nil) (sleep-for 1))
  170.            ;; make the file read-only. Sable does not do it but I think it 
  171.            ;; should have!
  172.            (set-file-modes buffer-file-name 292)
  173.            (revert-buffer nil t)
  174.            (message "Done!"))))
  175.     (error "There is no file associated with buffer %s" (buffer-name))))
  176.  
  177.  
  178.  
  179. (defun sable-edput-(&optional long)
  180.   "short edput without a parameter, long edput with one"
  181.   (if (buffer-file-name) 
  182.       (progn 
  183.     ;;give the user a chance to save the file if he has unsaved edits
  184.     (if (and (buffer-modified-p)
  185.          (y-or-n-p (format "%s has been modified. Write it out?" (buffer-name))))
  186.         (save-buffer))
  187.     (setq sable-file (file-name-nondirectory buffer-file-name))
  188.     (if (or (eq sable-mr nil) long)
  189.         (setq sable-mr (read-string "MR Number: " sable-mr)))
  190.     (if (or (eq sable-dir nil) long)
  191.         (setq sable-dir (read-string "Directory: " sable-dir)))
  192.     (if (or (eq sable-autodependency nil) long)
  193.         (setq sable-autodependency (read-string "Autodependency: " "line-level"))) 
  194.     ;; Change the directory to the buffer's one before composing the command
  195.     (setq sable-command (concat "cd " (file-name-directory buffer-file-name) "; "))
  196.     ;; Now form the sable command from the global variables
  197.     (setq sable-command (format 
  198.                  "%s edput g=%s mr=%s rm=n dir=%s adep=%s srf=%s prompt=n"
  199.                  sable-command sable-generic sable-mr sable-dir
  200.                  sable-autodependency sable-file))
  201.     (sable-process-command)
  202.     (if (eq sable-process-status 1) 
  203.         (progn
  204.           ;; making sure that the file is put properly
  205.           (while (eq (file-writable-p buffer-file-name) t) (sleep-for 1))           
  206.           (message "Loading file in buffer")
  207.           (revert-buffer nil t)
  208.           (message "Done!"))))
  209.     (error "There is no file associated with buffer %s" (buffer-name))))
  210.  
  211.  
  212. (defun sable-query-(&optional long)
  213.   "forced parameter prompt with long queries"
  214.   (if (or (eq sable-mr nil) long)
  215.       (setq sable-mr (read-string "MR Number: " sable-mr)))
  216.   (if (or (eq sable-query-relation nil) long)
  217.       (setq sable-query-relation (read-string "Relation: " "MD"))) 
  218.   (setq sable-command (format
  219.                "query mr=%s relation=%s prompt=n"
  220.                sable-mr sable-query-relation))
  221.   (sable-process-command)
  222.   (if (eq sable-process-status 1)
  223.       (save-excursion
  224.     (display-buffer (process-buffer sable-ksh-process))
  225.     (message "Done!"))))
  226.     
  227.  
  228.  
  229.  
  230. (defun sable-reset()
  231.   "Reset all the sable temporary variables"
  232.   (setq sable-generic nil)
  233.   (setq sable-mr nil)
  234.   (setq sable-dir nil)
  235.   (setq sable-file nil)
  236.   (setq sable-command nil)
  237.   (setq sable-process-status nil)
  238.   (setq sable-query-relation nil)
  239.   (setq sable-autodependency nil))
  240.  
  241.  
  242. (defun sable-key-bind()
  243.   (define-key (current-global-map) "\C-c?" 'sable-status)
  244.   (define-key (current-global-map) "\C-ci" 'sable)
  245.   (define-key (current-global-map) "\C-cr" 'sable-report)
  246.   (define-key (current-global-map) "\C-cg" 'sable-edget)
  247.   (define-key (current-global-map) "\C-cp" 'sable-edput)
  248.   (define-key (current-global-map) "\C-cn" 'sable-next-short)
  249.   (define-key (current-global-map) "\C-cN" 'sable-next-long)
  250.   (define-key (current-global-map) "\C-cu" 'sable-unedget-short)
  251.   (define-key (current-global-map) "\C-cU" 'sable-unedget-long)
  252.   (define-key (current-global-map) "\C-cq" 'sable-query-short)
  253.   (define-key (current-global-map) "\C-cQ" 'sable-query-long)
  254.   (define-key (current-global-map) "\C-c\C-g" 'sable-getversion)
  255.   (define-key (current-global-map) "\C-c\C-s" 'sable-submit)
  256.   (define-key (current-global-map) "\C-ch" 'sable-help))
  257.  
  258. ;;;
  259. ;;; Minibuffer commands
  260. ;;;
  261.  
  262.  
  263. (defun sable(generic)
  264.   "Initialize the sable generic and calls korn shell"
  265.   (interactive "sGeneric: ")
  266.   (sable-reset)
  267.   (sable-key-bind)
  268.   (setq sable-generic generic)
  269.   (sable-start-ksh))
  270.  
  271. (defun sable-next-short()
  272.   "Invoke the logical form of next short sable edit command"
  273.   (interactive)
  274.   (if (eq sable-generic nil) (error "Sable not Initialized")
  275.     (if buffer-read-only (sable-edget-)
  276.       (sable-edput-))))
  277.  
  278. (defun sable-next-long()
  279.   "Invoke the logical form of next long sable edit command"
  280.   (interactive)
  281.   (if (eq sable-generic nil) (error "Sable not Initialized")
  282.     (if buffer-read-only (sable-edget- 1)
  283.       (sable-edput- 1))))
  284.  
  285. (defun sable-edget()
  286.   "Invoke the short form of sable edget"
  287.   (interactive)
  288.   (if (eq sable-generic nil) (error "Sable not Initialized")
  289.     (sable-edget-)))
  290.  
  291. (defun sable-edput()
  292.   "Invoke the short form of sable edput"
  293.   (interactive)
  294.   (if (eq sable-generic nil) (error "Sable not Initialized")
  295.     (sable-edput-)))
  296.  
  297.  
  298. (defun sable-query-short()
  299.   "Invoke short query"
  300.   (interactive)
  301.   (if (eq sable-generic nil) (error "Sable not Initialized")
  302.     (sable-query-)))
  303.  
  304. (defun sable-query-long()
  305.   "Invoke query with parameter prompting"
  306.   (interactive)
  307.   (if (eq sable-generic nil) (error "Sable not Initialized")
  308.     (sable-query- 1)))
  309.  
  310. (defun sable-unedget-short()
  311.   "Invoke short unedget"
  312.   (interactive)
  313.   (if (eq sable-generic nil) (error "Sable not Initialized")
  314.     (sable-unedget-)))
  315.  
  316. (defun sable-unedget-long()
  317.   "Invoke unedget with parameter prompting"
  318.   (interactive)
  319.   (if (eq sable-generic nil) (error "Sable not Initialized")
  320.     (sable-unedget- 1)))
  321.  
  322. (defun sable-report()
  323.   "Produce a short report of all MRs"
  324.   (interactive)
  325.   (if (eq sable-generic nil) (error "Sable not Initialized")
  326.     (progn 
  327.       (setq sable-command (format
  328.                "report prompt=n"))
  329.       (sable-process-command)
  330.       (if (eq sable-process-status 1)
  331.       (save-excursion
  332.         (display-buffer (process-buffer sable-ksh-process))
  333.         (message "Done!"))))))
  334.  
  335.  
  336. (defun sable-getversion()
  337.   "Do a getversion on the generic"
  338.   (interactive)
  339.   (if (eq sable-generic nil) (error "Sable not Initialized")
  340.     (progn
  341.       (setq sable-command (concat
  342.                "getversion br="
  343.                (read-string "Branch <mr/ofc>: " "mr")))
  344.       (let* ((sable-tmp-mrs 
  345.           (read-string "MRs for file selection: "))
  346.          (sable-tmp-umrs 
  347.           (read-string "MRs for additional changes: ")))
  348.     (if (string= sable-tmp-mrs "")nil
  349.       (setq sable-command (concat
  350.                    sable-command " mrs=" sable-tmp-mrs)))
  351.     (if (string= sable-tmp-umrs "")nil
  352.       (setq sable-command (concat
  353.                    sable-command " umrs=" sable-tmp-umrs))))
  354.       (if (string= (read-string "List of files only <y/n>: ") "n")
  355.       (setq sable-command (concat
  356.                    sable-command 
  357.                    " list=n"
  358.                    " node=" (read-string "Target-node: ")
  359.                    " rm=" (read-string "Remove files: ")))
  360.     (setq sable-command (concat
  361.                  sable-command
  362.                  " list=y")))
  363.       (setq sable-command (concat
  364.                sable-command
  365.                " prompt=n"))
  366.       (sable-process-command)
  367.       (if (eq sable-process-status 1)
  368.       (save-excursion
  369.         (display-buffer (process-buffer sable-ksh-process))
  370.         (message "Done!"))))))
  371.  
  372.  
  373. (defun sable-submit()
  374.   "a simple sable submit mechanism"
  375.   (interactive)
  376.   (if (eq sable-generic nil) (error "Sable not Initialized")
  377.     (progn
  378.       (setq sable-command (concat
  379.                "getversion mr="
  380.                (read-string "MR Number: ")
  381.                " copyto="
  382.                (read-string "Resolution File[Mandatory]: ")
  383.                " prompt=n"))
  384.       (if (y-or-n-p "Will submit the MR. Are you sure?")
  385.       (progn
  386.         (sable-process-command)
  387.         (if (eq sable-process-status 1)
  388.         (save-excursion
  389.           (display-buffer (process-buffer sable-ksh-process))
  390.           (message "Done!"))))))))             
  391.       
  392.  
  393.       
  394.  
  395. (defun sable-status()
  396.   "Show the internal states and the default variables"
  397.   (interactive)
  398.   (if (eq sable-generic nil) (error "Sable not Initialized")
  399.   (save-excursion
  400.     (set-buffer (process-buffer sable-ksh-process))
  401.     (goto-char 1)
  402.     (insert "---------> Internal State of the Sable Mode <---------\n\n")
  403.     (insert "Background Korn Shell process: " sable-ksh-program "\n")
  404.     (insert "Sable Generic: ")
  405.     (if (and sable-generic (not (string= sable-generic "")))
  406.     (insert sable-generic "\n") 
  407.     (insert "*Not Set*\n"))
  408.     (insert "Sable Directory: ") 
  409.     (if sable-dir (insert sable-dir "\n") (insert "*Not Set*\n")) 
  410.     (insert "Sable File: ") 
  411.     (if sable-file (insert sable-file "\n") (insert "*Not Set*\n")) 
  412.     (insert "MR: ") 
  413.     (if sable-mr (insert sable-mr "\n") (insert "*Not Set*\n")) 
  414.     (insert "Sable Autodependency: ")
  415.     (if sable-autodependency (insert sable-autodependency "\n") 
  416.       (insert "*Not Set*\n")) 
  417.     (insert "Sable Query Relation: ")
  418.     (if sable-query-relation (insert sable-query-relation "\n") 
  419.       (insert "*Not Set*\n")) 
  420.     (insert "Last Sable Command: ")
  421.     (if sable-command (insert sable-command "\n") (insert "*Not Set*\n")) 
  422.     (insert "\n------------------------------------------------------\n\n")
  423.     (insert "Buffer History: \n\n")
  424.     (display-buffer (process-buffer sable-ksh-process)))))
  425.  
  426.  
  427. (defun sable-help()
  428.   "Print an explanation of keyboard macros in the sable environment"
  429.   (interactive)
  430.   (if (eq sable-generic nil) (error "Sable not Initialized")
  431.   ;; there should be a better way to do this
  432.     (save-excursion
  433.       (set-buffer (process-buffer sable-ksh-process))
  434.       (erase-buffer)
  435.       (insert
  436.        "\nThe Following Keyboard sequence is activated globally after the first\n"
  437.        "time sable is called\n"
  438.        "\n"
  439.        "   Key     Command              Description\n"
  440.        "   ---     -------              -----------\n"
  441.        "\n"
  442.        "  \\C\-c?  sable-status         Show the internal variables of emacs sable.\n"
  443.        "\n"
  444.        "  \\C\-ci  sable                Initialize the sable environment for a \n"
  445.        "                                new modification request. This command is\n"
  446.        "                                required before executing any other sable\n"
  447.        "                                commands.\n"
  448.        "\n"
  449.        "  \\C\-cr  sable-report         Generate a short sable report\n"
  450.        "\n"
  451.        "  \\C\-cn  sable-next-short     Initiate the next logical sable operation.\n"
  452.        "                                This will execute edget or edput.\n"
  453.        "\n"
  454.        "  \\C\-cN  sable-next-long      Long version of the initiate the next request.\n"
  455.        "\n"
  456.        "  \\C\-cg  sable-edget          Initiate the short edget operation.\n"
  457.        "\n"
  458.        "  \\C\-cp  sable-edput          Initiate the short edput operation.\n"
  459.        "\n"
  460.        "  \\C\-cu  sable-unedget-short  Initiate the short unedget operation.\n"
  461.        "\n"
  462.        "  \\C\-cU  sable-unedget-long   Long version of the unedget\n"
  463.        "\n"
  464.        "  \\C\-ch  sable-help           Print this help message\n"
  465.        "\n"
  466.        "  \\C\-cq  sable-query-short    Initiate the sable query.\n"
  467.        "\n"
  468.        "  \\C\-cQ  sable-query-long     Initiate the query with parameter prompting.\n"
  469.        "\n"
  470.        "  \\C\-c\\C-g  sable-getversion  \n"
  471.        "\n"
  472.        "  \\C\-c\\C-s  sable-submit  \n"
  473.        )
  474.       (display-buffer (process-buffer sable-ksh-process)))))
  475.  
  476.  
  477.  
  478.  
  479.  
  480. ;;; Wish List
  481. ;;; ---------
  482. ;;; have a new sable mode
  483. ;;; have a dired show up with getversion
  484. ;;; deal with the resolution file of the submit command correctly
  485. ;;; add some more commands with some more user abstractions
  486.  
  487. ;;; Bugs
  488. ;;; ----
  489. ;;; reports get screwed up if the cursor is in the *sable* window when the report
  490. ;;; command is executed. Looks like the buffer is not erasing properly - 10312250
  491. ;;; Fixed - 11011430
  492.