home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / sc-23.zip / SC-OLOAD.EL < prev    next >
Lisp/Scheme  |  1993-01-08  |  10KB  |  263 lines

  1. ;; -*- Mode: Emacs-Lisp -*-
  2. ;; sc-oloads.el  --  Version 2.3
  3.  
  4. ;; ========== Introduction ==========
  5. ;; This file contains overloading facilities for supercite.  Supercite
  6. ;; interfaces to various news and mail reading packages in a standard
  7. ;; way, as determined in 1989 by the supercite mailing list
  8. ;; participants.  Many mail/news package authors participated in the
  9. ;; discussion and the standard is an outcome of those discussions.
  10.  
  11. ;; As of the date of this writing (7-Feb-1991), both VM 4.40+ and MH-E
  12. ;; 3.7+ (as shipped with emacs 18.57) conform to the standard
  13. ;; out-of-the-package.  Since RMAIL, GNUS, RNEWS, and other packages
  14. ;; utilize elisp in the emacs 18.57 distribution, and since this
  15. ;; distribution does not conform to the standard, the interface
  16. ;; functions provided in this file are required to make supercite work
  17. ;; with those packages.
  18.  
  19. ;; Previous versions of supercite provided patches to distribution
  20. ;; elisp (18.55) but this method is no longer viable for a number of
  21. ;; reasons. The function overloads are the only supported way to
  22. ;; interface supercite with non-conforming packages. Using this
  23. ;; package, you should be able to interface supercite with all the
  24. ;; 18.55+ based readers including GNUS 3.12+, RMAIL and RNEWS, GNEWS
  25. ;; and PCMAIL. If you come across other reader packages that you'd
  26. ;; like to interface, please let me know.
  27.  
  28. ;; ========== Disclaimer ==========
  29. ;; This software is distributed in the hope that it will be useful,
  30. ;; but WITHOUT ANY WARRANTY.  No author or distributor accepts
  31. ;; responsibility to anyone for the consequences of using it or for
  32. ;; whether it serves any particular purpose or works at all, unless he
  33. ;; says so in writing.
  34.  
  35. ;; Some of this software was written as part of the supercite author's
  36. ;; official duty as an employee of the United States Government and is
  37. ;; thus in the public domain.  You are free to use that particular
  38. ;; software as you wish, but WITHOUT ANY WARRANTY WHATSOEVER.  It
  39. ;; would be nice, though if when you use any of this code, you give
  40. ;; due credit to the author.
  41.  
  42. ;; Other parts of this code were written by other people.  Wherever
  43. ;; possible, credit to that author, and the copy* notice supplied by
  44. ;; the author are included with that code. In all cases, the spirit,
  45. ;; if not the letter of the GNU General Public Licence applies.
  46.  
  47. ;; ========== Author (unless otherwise stated) ==========
  48. ;; NAME: Barry A. Warsaw        USMAIL: Century Computing, Inc.
  49. ;; TELE: (301) 593-3330                 1014 West Street
  50. ;; UUCP: uunet!cen.com!bwarsaw          Laurel, MD 20707
  51. ;; INET: bwarsaw@cen.com                    
  52.  
  53. ;; Want to be on the Supercite mailing list?
  54. ;;
  55. ;; Send articles to:
  56. ;;         INET: supercite@anthem.nlm.nih.gov
  57. ;;         UUCP: uunet!warsaw.nlm.nih.gov!supercite
  58. ;; 
  59. ;; Send administrivia (additions/deletions to list, etc) to:
  60. ;;         INET: supercite-request@anthem.nlm.nih.gov
  61. ;;         UUCP: uunet!warsaw.nlm.nih.gov!supercite-request
  62. ;;
  63. (provide 'sc-oloads)
  64.  
  65.  
  66.  
  67. ;; ======================================================================
  68. ;; functions which do the overloading
  69. ;; based on code supplied by umerin@tc.nagasaki.go.jp
  70.  
  71. (defvar sc-overload-functions
  72.   '((mail-yank-original       sc-mail-yank-original)
  73.     (news-reply-yank-original sc-news-reply-yank-original)
  74.     (reply-yank               sc-gnews-reply-yank)
  75.     (group-reply-yank         sc-group-reply-yank)
  76.     (group-follow-yank        sc-group-follow-yank)
  77.     )
  78.   "*Functions to be overloaded by supercite.
  79. It is a list of '(original overload)', where original is the original
  80. function symbol, overload is the supercite equivalent function.")
  81.  
  82.  
  83. (defun sc-overload-functions ()
  84.   "Overload functions defined by the variable sc-overload-functions.
  85. If the original symbol is not yet bound, it will not be overloaded.
  86. Also, if the symbol has already been overloaded, it will not be
  87. overloaded again."
  88.   (let ((binding nil)
  89.     (overloads sc-overload-functions))
  90.     (while overloads
  91.       (setq binding (car overloads)
  92.         overloads (cdr overloads))
  93.       (and (fboundp (car binding))
  94.        (not (get (car binding) 'sc-overloaded))
  95.        (progn
  96.          (fset (car binding) (symbol-function (car (cdr binding))))
  97.          (put (car binding) 'sc-overloaded 'sc-overloaded))
  98.        )
  99.       )))
  100.  
  101.  
  102.  
  103. ;; ======================================================================
  104. ;; sendmail.el overload functions. This is the heart of supercite
  105. ;; conformance by packages which rely on distribution emacs elisp. You
  106. ;; should almost always overload this function.
  107.  
  108. (defun sc-mail-yank-original (arg)
  109.   "Supercite version of mail-yank-original.
  110. This function is the workhorse which many packages rely upon to do
  111. citing. It inserts the message being replied to in the reply buffer.
  112. Puts point before the mail headers and mark after body of text.
  113.  
  114. Citation is accomplished by running the hook mail-yank-hooks and is
  115. thus user configurable. Default is to indent each nonblank line ARG
  116. spaces (default 3). Just \\[universal-argument] as argument means
  117. don't indent and don't delete any header fields."
  118.   (interactive "P")
  119.   (if mail-reply-buffer
  120.       (let ((start (point)))
  121.     (delete-windows-on mail-reply-buffer)
  122.     (insert-buffer mail-reply-buffer)
  123.     (if (consp arg)
  124.         nil
  125.       ;; mod 28-Jul-1989 bwarsaw@cen.com
  126.       ;; generalized, hookified citations
  127.       (run-hooks 'mail-yank-hooks))
  128.     (exchange-point-and-mark)
  129.     (if (not (eolp)) (insert ?\n)))))
  130.  
  131. ;; added 28-Jul-1989 bwarsaw@cen.com
  132. ;; generalized, hookified citations
  133. (defvar mail-indention-spaces 3
  134.   "*Set to number of spaces to indent when yanking a reply.")
  135.  
  136.  
  137. ;; added 28-Jul-1989 bwarsaw@cen.com
  138. ;; generalized, hookified citations
  139. (defvar mail-yank-hooks
  140.   '(lambda ()
  141.      (indent-rigidly (point) (mark) mail-indention-spaces))
  142.   "*Hook to run citation function.
  143. Expects point and mark to be set to the region to cite.")
  144.  
  145.  
  146.  
  147. ;; ======================================================================
  148. ;; rnewspost.el overload functions.  Not strictly necessary for supercite
  149. ;; to work but it reduces the amount of manual cleaning the user has to
  150. ;; do for GNUS and other news readers.
  151.  
  152. (defun sc-news-reply-yank-original (arg)
  153.   "Supercite version of news-reply-yank-original.
  154. Insert the message being replied to in the reply buffer. Puts point
  155. before the mail headers and mark after body of the text.  Calls
  156. mail-yank-original to actually yank the message into the buffer and
  157. cite text.  
  158.  
  159. If mail-yank-original is not overloaded by supercite, each nonblank
  160. line is indented ARG spaces (default 3).  Just \\[universal-argument]
  161. as ARG means don't indent and don't delete any header fields."
  162.   (interactive "P")
  163.   (mail-yank-original arg)
  164.   (exchange-point-and-mark)
  165.   ;; added 14-Jun-1989 bwarsaw@cen.com
  166.   ;; generalized, hookified citations
  167.   (run-hooks 'news-reply-header-hook))
  168.  
  169.  
  170. ;; added 14-Jun-1989 bwarsaw@cen.com generalized, hookified
  171. ;; citations (modified 18-Jul-1990)
  172. (defvar news-reply-header-hook
  173.   '(lambda ()
  174.      (insert "In article " news-reply-yank-message-id
  175.          " " news-reply-yank-from " writes:\n\n"))
  176.   "*Hook for inserting a header at the top of a yanked message.")
  177.  
  178.  
  179.  
  180. ;; ======================================================================
  181. ;; gnews overloads supplied by:
  182. ;; Piet* van Oostrum, Dept of Computer Science, Utrecht University,
  183. ;; Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
  184. ;; Telephone: +31 30 531806   Uucp:   uunet!mcsun!ruuinf!piet
  185. ;; Telefax:   +31 30 513791   Internet:  piet@cs.ruu.nl   (*`Pete')
  186. ;;
  187. ;; His overload functions were provided in a mail message dated
  188. ;; 5-Oct-1990, in which he also gives this caveat:
  189. ;; 
  190. ;; I use Gnews as my newsreader. I hacked a few definitions to use
  191. ;; supercite with gnews. The definitions are a hack in that you can't
  192. ;; easily customize them to get the original behaviour, but anyway,
  193. ;; here are they:
  194. ;;
  195. (defun sc-gnews-reply-yank (arg)
  196.   (interactive "P")
  197.   (open-line 2)
  198.   (delete-blank-lines)
  199.   (forward-char 1)
  200.   (mail-yank-original arg)
  201.   (exchange-point-and-mark)
  202.   (run-hooks 'gnews-reply-header-hook))
  203.  
  204.  
  205. (defun sc-group-reply-yank (pfx arg)
  206.   "Reply by e-mail to current article with original article inserted.
  207. With non-nil prefix argument PFX, set up the current article for e-mail
  208. forwarding."
  209.   (interactive "P\np")
  210.   (if pfx (group-forward-article)
  211.     (if (group-reply)
  212.     (progn
  213.       (forward-paragraph)
  214.       (sc-gnews-reply-yank 1)
  215.       (run-hooks 'group-reply-hook)
  216.       (set-buffer-modified-p nil)))))
  217.  
  218.  
  219. (defun sc-group-follow-yank (pfx arg)
  220.   "Follow up to current article with that article inserted, indented
  221. using the value of reply-prefix.\n
  222. Otherwise identical to group-follow, which see."
  223.   (interactive "P\np")
  224.   (let ((end (< article-final article-current))
  225.     file goal-column)
  226.     (if end (setq file (read-file-name "Include file: " nil "" t)
  227.           file (if (string< "" file) (expand-file-name file))))
  228.     (if (group-follow pfx arg)
  229.     (progn
  230.       (if file
  231.           (progn
  232.         (goto-char (point-max))
  233.         (insert ?\n?\n)
  234.         (insert-file file)
  235.         (if (looking-at "^\\(Newsgroups\\|Path\\|From\\): ")
  236.             (delete-region 1 (point)))))
  237.       (forward-paragraph)
  238.       (if (not file) (open-line 1))
  239.       (forward-line 1)
  240.       (if (not end)
  241.           (sc-gnews-reply-yank 1))
  242.       (run-hooks 'group-follow-hook)
  243.       (set-buffer-modified-p nil)))))
  244.  
  245. (defvar gnews-reply-header-hook nil
  246.   "*Hook for inserting a header at the top of a yanked message.")
  247.  
  248. ;    (setq gnews-reply-header-hook
  249. ;      '(lambda ()
  250. ;         (insert "In article " (article-field "Message-ID")
  251. ;                 " " (article-field "From") " writes:\n\n")))
  252.  
  253. ;; This is now done by sc-overload-functions
  254. ;;  5-Oct-1990 bwarsaw@cen.com
  255. ;;
  256. ; (defun sc-gnews-redefine ()
  257. ;  (fset 'reply-yank 'sc-gnews-reply-yank)
  258. ;  (fset 'group-reply-yank 'sc-group-reply-yank)
  259. ;  (fset 'group-follow-yank 'sc-group-follow-yank)
  260. ; )
  261.  
  262. ; (setq gnews-ready-hook 'sc-gnews-redefine)
  263.