home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / sccs-comment.el < prev    next >
Encoding:
Text File  |  1993-02-28  |  7.1 KB  |  182 lines

  1. ; From: kevin@traffic.den.mmc.com (Kevin Rodgers)
  2. ; Subject: GNU Elisp Archive submission: sccs-comment.el
  3. ; Date: Mon, 1 Mar 93 09:10:59 MST
  4. ; >Newsgroups: gnu.emacs.sources
  5. ; >Path: news.den.mmc.com!csn!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!ulowell!das.wang.com!wang!tegra!vail
  6. ; >From: vail@tegra.com (Johnathan Vail)
  7. ; >Subject: sccs-comment.el Release
  8. ; >Message-ID: <C3310x.3HF@tegra.com>
  9. ; >Organization: Tegra-Varityper, Inc. Billerica, MA
  10. ; >Date: Sat, 27 Feb 1993 00:50:56 GMT
  11. ; >Lines: 169
  12. ; >
  13. ; >This is the sccs comment string editing package written by Kevin
  14. ; >Rodgers.  It is an option added to the previosly posted sccs.el
  15. ; >package.
  16. ; >
  17. ; >
  18. ; >happy hacking, jv
  19. ; >
  20. ; > _____
  21. ; >|     | Johnathan Vail     vail@tegra.com     (508) 663-7435
  22. ; >|Tegra| jv@n1dxg.ampr.org    N1DXG@448.625-(WorldNet)
  23. ; > -----  MEMBER: League for Programming Freedom (league@prep.ai.mit.edu)
  24. ;;;;    sccs-comment.el
  25. ;;;;
  26. ;;;;    Define sccs-edit-comment, which pops up a buffer for editing an
  27. ;;;;    'SCCS' delta comment, then returns the buffer's contents as a
  28. ;;;;    string.  This for use with sccs.el (written by Jonathan Vail)
  29. ;;;;    version 2.0, by providing a suitable functional value for
  30. ;;;;    sccs-delta-comments.
  31. ;;;;
  32. ;;;;    Copyright (C) 1993 Kevin Rodgers
  33. ;;;;
  34. ;;;;    This program is free software; you can redistribute it and/or modify
  35. ;;;;    it under the terms of the GNU General Public License as published by
  36. ;;;;    the Free Software Foundation; either version 1, or (at your option)
  37. ;;;;    any later version.
  38. ;;;;
  39. ;;;;    This program is distributed in the hope that it will be useful,
  40. ;;;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. ;;;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  42. ;;;;    GNU General Public License for more details.
  43. ;;;;
  44. ;;;;    You should have received a copy of the GNU General Public License
  45. ;;;;    along with this program; if not, write to the Free Software
  46. ;;;;    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47. ;;;;
  48. ;;;;    Martin Marietta has not disclaimed any copyright interest in
  49. ;;;;    sccs-comment.el.
  50. ;;;;
  51. ;;;;    Kevin Rodgers                kevin@traffic.den.mmc.com
  52. ;;;;    Martin Marietta MS A16401        (303) 790-3971
  53. ;;;;    116 Inverness Dr. East
  54. ;;;;    Englewood CO 80112 USA
  55. ;;;;
  56. ;;;;    Installation:
  57. ;;;;    1. Put this file in a directory that is a member of load-path, and
  58. ;;;;       byte-compile it for better performance.
  59. ;;;;    2. Put these forms in ~/.emacs:
  60. ;;;;       (setq sccs-delta-comments (function sccs-edit-comment))
  61. ;;;;       (autoload 'sccs-edit-comment "sccs-edit-comment"
  62. ;;;;             "Pop up a buffer for editing an 'SCCS' delta comment...")
  63. ;;;;
  64. ;;;;    Usage:
  65. ;;;;    See sccs.el first: sccs-edit-comment is invoked via sccs-delget
  66. ;;;;    and sccs-deledit.
  67. ;;;;
  68. ;;;;    You may want to set the sccs-edit-comment-hooks variable; for
  69. ;;;;    example: (setq sccs-edit-comment-hooks (function text-mode))
  70. ;;;;
  71. ;;;;    LCD Archive Entry:
  72. ;;;;    sccs-comment|Kevin Rodgers|kevin@traffic.den.mmc.com|
  73. ;;;;    sccs-delta-comments customization for sccs.el 2.0.|
  74. ;;;;    1993-02-23|1.0|~/misc/sccs-comment.el.Z|
  75.  
  76. (require 'sccs)
  77.  
  78. (defvar sccs-comment-buffer-name "*Comment*"
  79.   "The name of the buffer used by sccs-edit-comment.")
  80.  
  81. (defvar sccs-edit-comment-hooks nil
  82.   "The hook variable used by sccs-edit-comment.")
  83.  
  84. (defun sccs-edit-comment ()
  85.   "Pop up a buffer for editing an 'SCCS' delta comment, and return the
  86. buffer contents as a string.  The hook variable edit-comment-hooks is
  87. run after the buffer is created.
  88.  
  89. This function invokes a recursive edit, which is exited by sccs-exit-
  90. edit-comment; it is intended for use as a value of sccs-delta-comments
  91. \(which see\)."
  92.   (save-excursion
  93.     (save-window-excursion
  94.       (pop-to-buffer (get-buffer-create sccs-comment-buffer-name))
  95.       (widen)
  96.       (erase-buffer)
  97.       (run-hooks 'sccs-edit-comment-hooks)
  98.       (unwind-protect            ; restore exit-recursive-edit keybinding
  99.       (catch 'sccs-edit-comment    ; catch and return comment
  100.         (sccs:substitute-key-definition (function exit-recursive-edit)
  101.                         (function sccs-exit-edit-comment)
  102.                         (current-global-map)
  103.                         t)
  104.         (message "Type %s to return the contents of the '%s' buffer, or %s to abort"
  105.              (substitute-command-keys "\\[sccs-exit-edit-comment]")
  106.              sccs-comment-buffer-name
  107.              (substitute-command-keys "\\[abort-recursive-edit]"))
  108.         (recursive-edit)
  109.         ;; In case exit-recursive-edit was explicitly invoked:
  110.         (error "Recursive edit of '%s' buffer exited without returning \
  111. comment string"
  112.            sccs-comment-buffer-name))
  113.     (sccs:substitute-key-definition (function sccs-exit-edit-comment)
  114.                     (function exit-recursive-edit)
  115.                     (current-global-map)
  116.                     t)))))
  117.       
  118. (defun sccs-exit-edit-comment ()
  119.   "*Return the contents of the sccs-comment-buffer-name buffer to sccs-
  120. edit-comment."
  121.   (interactive)
  122.   (let ((sccs-comment-buffer (get-buffer sccs-comment-buffer-name)))
  123.     (if (and (or sccs-comment-buffer
  124.          (error "'%s' buffer does not exist" sccs-comment-buffer-name))
  125.          (or (> (recursion-depth) 0)
  126.          (error "No recursive edit is in progress")))
  127.     (save-excursion
  128.       (set-buffer sccs-comment-buffer)
  129.       (let ((comment (buffer-string)))
  130.         (set-buffer-modified-p nil)
  131.         ;; (bury-buffer)        ; not necessary, since catch is
  132.                     ; protected by save-window-excursion
  133.         (throw 'sccs-edit-comment comment)))))) ; exits recursive-edit, too
  134.  
  135.  
  136. ;; Define sccs:substitute-key-definition (compatible with substitute-
  137. ;; key-definition):
  138.  
  139. (defun sccs:substitute-key-definition (olddef newdef keymap &optional recur)
  140.   "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
  141. In other words, OLDDEF is replaced with NEWDEF where ever it appears.
  142.  
  143. If the optional argument RECUR is non-nil, also recursively substitute
  144. NEWDEF for OLDEF in keymaps accessible from KEYMAP via a non-empty
  145. prefix key.  If RECUR is t, do so for all accessible keymaps; otherwise,
  146. it should be a predicate \(i.e. a function of one argument\) which is
  147. applied to each accessible keymap to determine \(according to whether
  148. the result is non-nil\) whether the substitution will be performed in it."
  149. (if (keymapp keymap)
  150.     (progn
  151.       (cond ((and (vectorp keymap) (= (length keymap) 128))
  152.          (let ((i 0))
  153.            (while (< i 128)
  154.          (if (eq (aref keymap i) olddef)
  155.              (aset keymap i newdef))
  156.          (setq i (1+ i)))))
  157.         ((and (consp keymap) (eq (car keymap) 'keymap))
  158.          (let ((key-defs (cdr keymap)))
  159.            (while key-defs
  160.          (if (eq (cdr-safe (car-safe key-defs)) olddef)
  161.              (setcdr (car key-defs) newdef))
  162.          (setq key-defs (cdr key-defs))))))
  163.       (if recur
  164.       ;; accessible-keymaps returns all keymaps recursively
  165.       ;; accessible from its argument keymap, so the recursive call
  166.       ;; to sccs:substitute-key-definition should disable any further
  167.       ;; recursion by explicitly passing nil as the fourth argument.
  168.       (let ((sub-keymap-alist (cdr (accessible-keymaps keymap))))
  169.         (while sub-keymap-alist
  170.           (if (or (eq recur t)
  171.               (funcall recur (cdr (car sub-keymap-alist))))
  172.           (sccs:substitute-key-definition olddef newdef
  173.                           (cdr (car sub-keymap-alist))
  174.                           nil))
  175.           (setq sub-keymap-alist (cdr sub-keymap-alist))))))))
  176.  
  177.  
  178.  
  179.