home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / gnus-hide.el < prev    next >
Encoding:
Text File  |  1991-06-19  |  28.4 KB  |  905 lines

  1. ; Path: dg-rtp!rock.concert.net!mcnc!stanford.edu!agate!ucbvax!van-bc!ubc-cs!unixg.ubc.ca!brazeau.ucs.ualberta.ca!alberta!cpsc.ucalgary.ca!krawchuk
  2. ; From: krawchuk@cpsc.UCalgary.ca (Bj Krawchuk)
  3. ; Newsgroups: gnu.emacs.sources
  4. ; Subject: gnus-hide.el 1.04
  5. ; Summary: a quote, signature and reference hider
  6. ; Date: 19 Jun 91 18:43:34 GMT
  7. ; Organization: The University of Calgary
  8. ; Here's a treat for GNUS users.
  9. ; It is a major enhancement of the old gnus-hide-quote.el.
  10. ; It does quote, signature and reference-line hiding.
  11. ; Please tell me about any bugs (I know of a couple already)
  12. ; so that I can iron them out for the next version.
  13. ; This version should work for almost all articles, however.
  14. ; Also please offer suggestions (or code!) for future versions. 
  15. ; Enjoy.
  16. ; Bj <krawchuk@cpsc.ucalgary.ca>
  17. ;;;--------------------------------------------------------------------
  18. ;;;
  19. ;;; gnus-hide.el    hide quotes and/or signatures
  20. ;;; v1.04        simplify references
  21. ;;;
  22. ;;; LCD Archive Entry:
  23. ;;; gnus-hide|Bj Krawchuk|krawchuk@cpsc.UCalgary.ca
  24. ;;; |A quote, signature and reference hider for the GNUS news reader
  25. ;;; |91-06-19|1.04|~/misc/gnus-hide.el.Z
  26. ;;;
  27. ;;; improve readability and reduce screen output time 
  28. ;;; (for slow baud rates) by hiding quotes and/or signatures.
  29. ;;;
  30. ;;;
  31. ;;; (Note: this file can be viewed/modified with Awefold 1.0)
  32. ;;;
  33. ;::         QUOTE HIDING
  34. ;;;
  35. ;;; Don't you hate it when an article has pages of quoted text that you've
  36. ;;; already read?  Load this file and you can just type 'h' or '['
  37. ;;; to get rid of it and 'H' or ']' to bring it back.
  38. ;;;
  39. ;;; If someone uses something other than ">" to mark the quoted text, it
  40. ;;; notices that; it can even cope with the kind of stuff that SuperCite
  41. ;;; inserts, and simple indentation (though it tries that as a last resort).
  42. ;;; If it can't figure out what the attribution string is, it prompts for it.
  43. ;;; 'C-uh' will make it prompt anyway, with it's guess as a default.  If a
  44. ;;; SuperCited article has multiple sections like
  45. ;;;
  46. ;;;       FOO> some text, some text
  47. ;;;       FOO> blah blah blah
  48. ;;;       oh yeah?
  49. ;;;       BAR> some text, some text
  50. ;;;       BAR> blah blah blah
  51. ;;;
  52. ;;; you can generally make both sections go away just by typing 'h' twice.
  53. ;;; Also, if two blocks of text to be elided are seperated only by blank
  54. ;;; lines, the blank lines are hidden as well.
  55. ;;;
  56. ;;;    To hide a quote while in subject mode: type "h" or "[".
  57. ;;;     To show everything including quotes and signature: type "H" or "]"
  58. ;;;
  59. ;;; Quote hiding can also be done automatically on selecting an article.
  60. ;;;     (see .emacs setup section below)
  61. ;;;     You may temporarily turn autohiding off by typing "'" or "C-cC-r"
  62. ;:|
  63. ;;;
  64. ;::         SIGNATURE HIDING
  65. ;;;
  66. ;;;    Can't stand long and ugly signatures? Hate seeing the 
  67. ;;;    same signatures over and over again? Hate scrolling 
  68. ;;;    the screen with <SPC> only to find a signature on the 
  69. ;;;    next page? TRY SIGNATURE HIDING!
  70. ;;;
  71. ;;;    o Hide signatures when they can be identified
  72. ;;;    o Useful for reading articles for people with long signatures
  73. ;;;      especially at low baud rates.
  74. ;;;    o Useful even at high baud rates to avoid the need for
  75. ;;;      extra scrolling and to aid readability.
  76. ;;;     o Will hide most signatures
  77. ;;;
  78. ;;;    To hide a signature while in subject mode: type "S" or "{"
  79. ;;;     To show everything including quotes and signature: type "H" or "]"
  80. ;;;
  81. ;;; Signature hiding can also be done automatically on selecting an article.
  82. ;;;     (see .emacs setup section below)
  83. ;:|
  84. ;;;
  85. ;::        REFERENCE SIMPLIFICATION
  86. ;;;
  87. ;;; Can't stand those ugly reference lines? Don't understand what 
  88. ;;; they mean anyway? Use reference simplification.
  89. ;;;
  90. ;;; Simply type "C-cC-r" or "}" in subject mode, and all those long 
  91. ;;; reference lines will be simplified.
  92. ;;; For example, 
  93. ;;;    In article < ... > foo@goo.edu (Jawn Dough) writes:
  94. ;;; will be simplified to:
  95. ;;;    (Jawn Dough) writes:
  96. ;;; 
  97. ;;; Reference hiding can also be done automatically on selecting an article.
  98. ;;;     (see .emacs setup section below)
  99. ;:|
  100. ;;;
  101. ;::         LIMITATIONS
  102. ;;;
  103. ;;;    o sometimes quote hiding and signature hiding will be overzealous
  104. ;;;      and hide stuff you really didn't want to hide. The user must
  105. ;;;      type "H" then, and put up with the quoting and signature 
  106. ;;;      for that article. This is particularly the case when 
  107. ;;;      gnus-hide-hookified-be-aggressive is set to t.
  108. ;;;
  109. ;;;    o Signature hiding may occasionally not recognize some things
  110. ;;;      that look like signatures. (Paragraphs with street addresses
  111. ;;;      without email addresses, for example).
  112. ;;;
  113. ;;;    o Reference simplification is not reversible. Reselecting the 
  114. ;;;      article will restore the original reference lines. (If using
  115. ;;;      autohiding -- hookified simplification -- first you will have to
  116. ;;;      toggle the autohiding by pressing "'", the apostrophe key.
  117. ;;;
  118. ;:|
  119. ;;;    
  120. ;::         .emacs startup
  121. ;;;
  122. ;:: Hooks
  123. ;;;
  124. ;;; To automatically load gnus-hide when starting gnus, 
  125. ;;; put this into your .emacs::
  126. ;;; (setq gnus-Startup-hook 
  127. ;;;   '(lambda ()
  128. ;;;    (require 'gnus-hide)))
  129. ;;;
  130. ;;; If you want gnus to do quote hiding automatically when you select
  131. ;;; an article:
  132. ;;; (setq  gnus-Article-prepare-hook 'gnus-Article-hide-quote)
  133. ;;;
  134. ;;; If you want gnus to do signature hiding automatically when you select
  135. ;;; an article:
  136. ;;; (setq  gnus-Article-prepare-hook 'gnus-Article-hide-sig)
  137. ;;;
  138. ;;; If you want gnus to do reference hiding automatically when you select
  139. ;;; an article:
  140. ;;; (setq  gnus-Article-prepare-hook 'gnus-Article-simplify-references)
  141. ;;;
  142. ;;; To use a couple or all three of these, put the names in a list like this:
  143. ;;;
  144. ;;; (setq gnus-Article-prepare-hook 
  145. ;;;    '(gnus-Article-hide-quote 
  146. ;;;      gnus-Article-hide-sig
  147. ;;;      gnus-Article-simplify-references))
  148. ;;;
  149. ;:|
  150. ;:: Variables
  151. ;;;
  152. ;;; -- To use aggressive quote prefixes in gnus-Article-hide-quote
  153. ;;;     (setq gnus-hide-hookified-be-aggressive t)
  154. ;;;
  155. ;;; -- To turn off aggressive signature hiding:
  156. ;;;     (setq gnus-hide-sig-aggressively nil)
  157. ;;;
  158. ;;; -- If you want to save "hidden articles", 
  159. ;;;     (setq gnus-save-article-prepare-hook nil)
  160. ;;;
  161. ;;;    (By default, it does unhiding, and most people won't want to
  162. ;;;     change this behavior.)
  163. ;;;
  164. ;;; -- To YANK Unhidden while followup posting or replying,
  165. ;;;     (setq mail-yank-hooks 'gnus-hide-yank-original-unhide)
  166. ;;;     (autoload 'gnus-hide-yank-original-unhide "gnus-hide" "" t)
  167. ;;;
  168. ;;;    I use supercite as well, so I use:
  169. ;;;     (setq mail-yank-hooks '(gnus-hide-yank-original-unhide 
  170. ;;;                sc-cite-original))
  171. ;;;
  172. ;;; -- To do automatic quote hiding only on followups:
  173. ;;;    (setq gnus-autohide-only-on-followup t)
  174. ;;;
  175. ;;; -- To not show the first line of a hidden quote
  176. ;;;    (setq gnus-hide-show-first-line nil)
  177. ;;;
  178. ;;; -- To not place the ellipsis on a newline (when gnus-hide-show-first-line
  179. ;;;    is set to nil), ie. place it on the same line as the reference line.
  180. ;;;    (setq gnus-hide-place-ellipsis-on-newline nil)
  181. ;;; 
  182. ;;; Other customizable variables are available for more experienced users...
  183. ;;;
  184. ;:|
  185. ;:|
  186. ;;;
  187. ;::         AUTHORS and HISTORY
  188. ;;;
  189. ;;;  14-dec-90    Tim Lambert <lambert@spectrum.cs.unsw.oz.au>
  190. ;;;        o Created gnus-hide-quote.el
  191. ;;;  27-jan-91    Jamie Zawinski <jwz@lucid.com>
  192. ;;;        o Made it automatic.
  193. ;;;   1-jun-91  Brent J. Krawchuk <krawchuk@cpsc.ucalgary.ca>
  194. ;;;             o renamed to gnus-hide.el
  195. ;;;        o autohiding (use of article prepare hook)
  196. ;;;             o signature hiding functions
  197. ;;;        o reference hiding functions
  198. ;;;        o made into awefold 1.0 file
  199. ;;;        Tim Lambert, J. Zawinski, Dave Brennan and Dan Jacobson
  200. ;;;        o added/improved code, suggestions, bug fixes
  201. ;;;
  202. ;;;  Feel free to contact the authors to make suggestions, or bug fixes.
  203. ;;;
  204. ;:|
  205. ;;;    
  206. ;;;--------------------------------------------------------------------
  207. (require 'gnus)
  208.  
  209. ;::        KEY DEFINITIONS
  210.  
  211. (define-key gnus-Subject-mode-map "S"    'gnus-Subject-hide-sig)
  212. (define-key gnus-Subject-mode-map "h"    'gnus-Subject-hide-quote)
  213. (define-key gnus-Subject-mode-map "H"    'gnus-Subject-unhide)
  214. (define-key gnus-Subject-mode-map "\C-c\C-r" 'gnus-Subject-simplify-references)
  215. (define-key gnus-Subject-mode-map "{"    'gnus-Subject-hide-sig)
  216. (define-key gnus-Subject-mode-map "}"    'gnus-Subject-simplify-references)
  217. (define-key gnus-Subject-mode-map "["    'gnus-Subject-hide-quote)
  218. (define-key gnus-Subject-mode-map "]"    'gnus-Subject-unhide)
  219. (define-key gnus-Subject-mode-map "'"      'gnus-hide-autohide-toggle)
  220.  
  221. ;:|
  222.  
  223. ;::         QUOTE HIDING FUNCTIONS
  224.  
  225. ;:: Quote Prefixes
  226.  
  227. (defvar gnus-possible-quote-prefixes
  228.     '("^[^ \t\n\(A-Z#%;]"    ;; first, search for ">", "}", etc.
  229.       "^[ \t]+[^ \t\n\(A-Z#%;]"    ;; then that with leading whitespace.
  230.                 ;; these don't use #%; because of shar files
  231.                       ;; and postscript and lisp code...
  232.       "^[ \t]*[A-Z]+[]}>[{<-]"  ;; then, SuperCite: "FOO> ", "  Yow>", etc.
  233.       )
  234.   "Regexps to search for to identify quoted-text attributions.
  235. These regexps should match the initial subsequence of the line that is the
  236. attribution prefix.  They are ordered; regexps which are less ambiguous and 
  237. less likely to produce mismatches should come first.  The entire buffer will 
  238. be searched for two or more consecutive lines which match the first element 
  239. of this list, then the second, and so on.  The initial subsequence of the 
  240. two lines which first match is returned. Regular quote hiding also
  241. uses gnus-aggressive-quote-prefixes, unlike hookified quote hiding 
  242. which, by default, does not.")
  243.  
  244. (defvar gnus-hide-hookified-be-aggressive nil
  245.   "Variable to determine if hooked calling of gnus-hide-Article-quote
  246. should use aggressive quote prefixes. If set to t, aggressive 
  247. prefixes will be used.
  248. Default: nil")
  249.  
  250.     
  251. (defvar gnus-aggressive-quote-prefixes
  252.     '("^[ \t]+"            ;;  simple indentation
  253.       "^[\(#%;]"        ;; "comment" chars...
  254.      )
  255.  "Regexps for last-resort hiding. By default, these are not 
  256. used in hookified calling (gnus-Article-hide-{quote/sig}).
  257. See gnus-hide-hookified-be-aggressive and gnus-possible-quote-prefixes.")
  258.  
  259.  
  260. (defun gnus-identify-quote-prefix (use-aggressive)
  261.   "Figure out what the current message uses for attribution.  See the
  262. documentation for gnus-possible-quote-prefixes."
  263.   (save-excursion
  264.    (save-restriction
  265.     (gnus-find-sig-position)
  266.     (if (not (= (point) (point-min)))
  267.     (narrow-to-region (point-min) (point)))
  268.     (goto-char (point-min))
  269.     (search-forward "\n\n" nil t)
  270.     (let ((match nil)
  271.       (start (point))
  272.       (rest (if use-aggressive 
  273.             (append gnus-possible-quote-prefixes
  274.                 gnus-aggressive-quote-prefixes)
  275.             gnus-possible-quote-prefixes)))
  276.       (while (and rest (not match))
  277.     (goto-char start)
  278.     (let ((regexp (car rest)))
  279.       (while (not (or match (eobp)))
  280.         (if (re-search-forward regexp nil 0)
  281.         (save-excursion
  282.           (beginning-of-line)
  283.           (let ((prefix (buffer-substring (point) (match-end 0))))
  284.             (forward-line 1)
  285.             (if (looking-at (regexp-quote prefix))
  286.             (setq match prefix)))))
  287.         (forward-line 1)))
  288.     (setq rest (cdr rest)))
  289.       match))))
  290.  
  291.  
  292. ;:|
  293. ;:: Hide Quote Routines
  294.  
  295. (defvar gnus-autohide-only-on-followup nil
  296.   "When set to t, the first articles in threads will not be hidden.")
  297.  
  298.  
  299. (defvar gnus-hide-show-first-line t
  300.   "When set to t (default), the first line of a quote is not
  301. hidden, to give some context.")
  302.  
  303. (defvar gnus-hide-place-ellipsis-on-newline t
  304.   "If t, put ellipsis on new line when gnus-hide-show-first-line is nil")
  305.  
  306.  
  307. (defun gnus-Article-is-followup ()
  308.   "Is current article a followup?"
  309.   (string-match "^[Rr][Ee][:\^] "
  310.         (gnus-fetch-field "Subject")))
  311.  
  312. (defun gnus-Article-hide-quote (&optional prefix-string)
  313.   "Hide quotations in current article.
  314. For use with gnus-Article-prepare-hook."
  315.   (if     gnus-hide-autohide-toggle
  316.   (progn
  317.   (setq prefix-string (or prefix-string 
  318.               (and (or (not gnus-autohide-only-on-followup)
  319.                    (gnus-Article-is-followup))
  320.               (gnus-identify-quote-prefix 
  321.                     gnus-hide-hookified-be-aggressive))))
  322.     (if prefix-string
  323.     (progn
  324.       (message "Hiding text beginning with \"%s\"..." prefix-string)
  325.       (save-excursion
  326.         (goto-char (point-min))
  327.         (let ((buffer-read-only nil)
  328.           (quote-regexp (concat "\n*" (regexp-quote prefix-string))))
  329.           (gnus-hide-quote-internal quote-regexp)
  330.           (set-buffer-modified-p nil))
  331.         (setq selective-display t)
  332.         )
  333.         (message "Hiding text beginning with \"%s\"... done." 
  334.          prefix-string))))))
  335.  
  336.  
  337. (defun gnus-Subject-hide-quote (&optional prefix-string)
  338.   "Hide quotations in current article."
  339.   (interactive (list
  340.          (let* ((default (gnus-eval-in-buffer-window 
  341.                    gnus-Article-buffer
  342.                    (gnus-identify-quote-prefix t)))
  343.             (string (if (or current-prefix-arg (not default))
  344.                     (read-from-minibuffer
  345.                       (concat
  346.                     "String that starts quotation lines"
  347.                     (if default
  348.                         (concat " \(default \"" 
  349.                             default "\"\)"))
  350.                     ": "))
  351.                     default)))
  352.            (if (string= "" string)
  353.                (or default (error "You tell me, buckaroo."))
  354.                string))))
  355.   (if (string= prefix-string "") (error "empty string"))
  356.   (let ((gnus-hide-autohide-toggle t))
  357.   (gnus-eval-in-buffer-window gnus-Article-buffer
  358.                   (gnus-Article-hide-quote prefix-string)))
  359. )
  360.  
  361.       
  362. (defun gnus-hide-quote-internal (prefix)
  363.   (let ((search-pattern (concat "\n+" prefix))
  364.     (looking-at-pattern (concat "^" prefix)))
  365.     (save-excursion
  366.       (save-restriction
  367.     (widen)
  368.     (goto-char (point-min))
  369.     (and (search-forward "\n\n" nil t)
  370.          (forward-char -1))
  371.     (while (re-search-forward search-pattern nil t)
  372.       (if gnus-hide-show-first-line
  373.         (forward-line 1)
  374.         (progn 
  375.         (goto-char (match-beginning 0))
  376.         (if gnus-hide-place-ellipsis-on-newline
  377.            (progn (forward-char 1)    ; skip first-newline
  378.              (if (looking-at prefix) ; already
  379.             (insert "\n"))))    ; add a new newline
  380.  
  381.         ; eat up leading newlines
  382.         (while (looking-at "\n")
  383.              (delete-char 1)
  384.              (insert "\^M"))))
  385.  
  386.  
  387.       (while (looking-at prefix)
  388.         (delete-char -1)
  389.         (insert "\^M")
  390.         (forward-line 1)))))))
  391.  
  392.  
  393.  
  394.  
  395. ;:|
  396.  
  397. ;:|
  398.  
  399. ;::         SIGNATURE HIDING FUNCTIONS
  400.  
  401. ;:: Signature Identification
  402.  
  403. (defvar gnus-possible-signature-prefixes
  404.   '(
  405.    "[\n\C-m]--[ \t]*$"          ;; gnus signature type
  406.                  ;; line type (at least 2 fancy chars)
  407.    "[\n\C-m][---=_~\*\$\+\|\^:;\\\/\<]+[---=_~\*\$\+\|\^:;\\\/\<]+[ \t]*$" 
  408.    "[\n\C-m]---"         ;; --- type
  409.    "[\n\C-m]--[A-Za-z ]"     ;; --Name ... type
  410.    "[\n\C-m]-[A-Za-z ]"         ;; -Name ... type
  411.    )
  412.   "Regexps to search for beginning of a signature.
  413.    They are ordered; regexps which are less ambiguous and 
  414.    less likely to produce mismatches should come first. 
  415.    Replace [\n\C-m] for ^ if you wish the sig indicator
  416.    to be shown."
  417. )
  418.  
  419.  
  420. (defvar gnus-hide-sig-aggressively t
  421.   "When set, the last paragraph will be searched 
  422. for an email address. If one is found, assume it is a signature,
  423. and hide it.")
  424.  
  425. (defvar gnus-hide-largest-signature 650
  426.   "The largest size of signature to hide. The larger this number,
  427. the greater the chance that non-signatures will be mistakenly hidden")
  428.  
  429. (defun gnus-find-sig-position ()
  430.   "Move point to start of signature. Moves to point-min if none found."
  431.   (let ((start     (max (progn (goto-char (point-min))
  432.                 (re-search-forward "\n\n" nil t)
  433.                 (point))
  434.              (- (point-max) gnus-hide-largest-signature))))
  435.     (goto-char start)
  436.     (gnus-search-for-sig-start gnus-possible-signature-prefixes start)
  437.      (if (= (point) start)             ; no divider
  438.       (if (not (gnus-last-paragraph-sigp))  ; no addr in last para
  439.           (goto-char (point-min))))
  440.     (point)))
  441.  
  442. (defun gnus-search-for-sig-start (regexp-list start)
  443.    "Loop through gnus-possible-signature-prefixes until 
  444.     a regexp matches or the end of list is found."
  445.     (if regexp-list 
  446.          (if (re-search-forward (car regexp-list) nil t)
  447.                 (goto-char (match-beginning 0))
  448.              (progn (goto-char start)
  449.                  (gnus-search-for-sig-start 
  450.                   (cdr regexp-list) start)))))
  451.  
  452.  
  453. (defun gnus-last-paragraph-point ()
  454.   "Point at start of last paragraph in buffer.
  455. Return nil if a \n\n is not found."
  456.   (save-excursion 
  457.     (goto-char (point-max))
  458.     (re-search-backward "[a-zA-Z]" nil t)    ; skip trailing whitespace
  459.     (if (re-search-backward "\n[\n\t ]*\n" nil t)
  460.         (match-beginning 0)
  461.         nil)))
  462.  
  463. (defun gnus-start-of-article-point ()
  464.  "Point at which article begins."
  465.   (save-excursion 
  466.     (goto-char (point-min))
  467.     (if (re-search-forward "\n\n" nil t)
  468.         (match-beginning 0)
  469.         nil)))
  470.  
  471.  
  472. (defun gnus-last-paragraph-sigp ()
  473.   "Is last paragraph a signature? If so, move point there.
  474. The last paragraph is not considered to be a signature if 
  475. it is the only paragraph in the article."
  476.    (if gnus-hide-sig-aggressively
  477.    (let ((lpp (gnus-last-paragraph-point)))
  478.     (if (not (= lpp (gnus-start-of-article-point)))  ; not only para
  479.     (if lpp  (progn (goto-char lpp) (gnus-address-belowp)))))))
  480.  
  481.  
  482. (defun gnus-address-belowp ()
  483.   "non-nil if there is what looks like an email address below this
  484. point in the buffer (handles internet and uucp addresses)."
  485.   (or    (string-match "[a-zA-Z0-9]+@[---a-zA-Z0-9\.]+[\"\|\)>\n\t ]" ;internet 
  486.        (buffer-substring (point) (point-max)))
  487.     (string-match "\\([a-zA-Z0-9]+\!\\)+[a-zA-Z0-9]+[\n\t ]" ;uucp
  488.        (buffer-substring (point) (point-max)))))
  489.     
  490.  
  491.  
  492. ;:|
  493. ;:: The Signature Hiding Functions
  494.  
  495.  
  496. (defun gnus-Article-hide-sig ()
  497.   "Signature hiding for use with gnus-Article-prepare-hook."
  498.   (if     gnus-hide-autohide-toggle
  499.   (save-excursion
  500.     (let ((buffer-read-only nil))
  501.       (if (not (= 1 (gnus-find-sig-position)))
  502.       (gnus-hide-to-eob))
  503.       (set-buffer-modified-p nil))
  504.     (setq selective-display t))))
  505.  
  506.  
  507. (defun gnus-Subject-hide-sig ()
  508.   "Hide signature."
  509.   (interactive)
  510.   (gnus-eval-in-buffer-window gnus-Article-buffer
  511.     (save-excursion
  512.       (let ((buffer-read-only nil))
  513.     (if (not (= 1 (gnus-find-sig-position)))
  514.         (gnus-hide-to-eob))
  515.         (set-buffer-modified-p nil))
  516.       (setq selective-display t))))
  517.  
  518.  
  519. (defun gnus-hide-to-eob ()
  520.   "Hide all lines to end of buffer."
  521.   (subst-char-in-region (point) (point-max) ?\n ?\C-M))
  522.  
  523.  
  524.  
  525. ;:|
  526.  
  527. ;:|
  528.  
  529. ;::         REFERENCE CLEANING FUNCTIONS
  530.  
  531. (defvar gnus-reference-regexps 
  532.  '(
  533.     "In article \<.*\>.*\("
  534.     "In \<.*\>.*\("
  535.     "On .*T, .*\@.*\("
  536.     "In article \<.*\>.*\n[^>]*\("         ; across 2 lines
  537.     "In \<.*\>.*\n[^>]*\("                  ; "" (no quote > before ()
  538.     "In article \<.*\>[ ,\t\n]*"         ; empty name
  539.     "\>\>\>\>\>.*\n*.*\("                    ; Supercite verbose
  540.     "^[A-Za-z]*\>+[ ]*In.*\("            ; Sc simple    
  541.     "^.*\@.*\(.*\) writes:"            ; no In article.
  542.     "^.*\@.*\(.*\) \/.*\/.* writes:"    ; " In article with date
  543.      )
  544.  "Regexps to match reference lines."
  545. )
  546.  
  547.  
  548. (defun orify-regexp-list (regexps)
  549.  "Convert list of reg expressions to or form."
  550.  (if regexps
  551.  (if (cdr regexps)
  552.     (concat (car regexps) "\\|" (orify-regexp-list (cdr regexps)))
  553.         (car regexps))))
  554.  
  555. (defun gnus-simplify-references ()
  556.   "Create one big or'ed together regexp from a list of regexps."
  557.   (let ((Ref-Regexp (orify-regexp-list gnus-reference-regexps)))
  558.   (goto-char (point-min))
  559.   (while  (re-search-forward Ref-Regexp nil t)
  560.     (gnus-ref-simplify)
  561.     (forward-line 1) 
  562.     (beginning-of-line))))
  563.  
  564.  
  565. (defun gnus-ref-simplify ()
  566.  "Simplify found reference"
  567.  (let    ((MB (match-beginning 0))
  568.      (ME (match-end 0)))
  569.   (goto-char MB)
  570.   (bjk-replace  (if (re-search-forward "^[A-Za-z]*[=:#>]+" ME t)
  571.             (match-end 0)     ; end of quote marker
  572.             MB)
  573.         (if (re-search-forward "(" ME t) 
  574.             (match-beginning 0) 
  575.             ME)            ; can't find a name    
  576.         "")
  577.   ;; hack to get rid of date strings still leftover
  578.   (goto-char MB)
  579.   (if (re-search-forward "\/.*\/" ME t)
  580.       (bjk-replace (match-beginning 0) (match-end 0) ""))
  581.   ;; hack to get rid of newlines in middle of namestring
  582.   (goto-char MB)
  583.   (if (looking-at "([a-zA-Z ]+\n[a-zA-Z ]+)")
  584.     (progn (end-of-line) (delete-char 1) (insert " "))) ))
  585.   
  586.  
  587.  
  588. (defun bjk-replace (Start End String)
  589.  "replace text between Start and End with String"
  590.  (save-excursion
  591.     (delete-region Start End)
  592.     (goto-char  Start)
  593.     (insert String)))
  594.  
  595. (defun gnus-Article-simplify-references ()
  596.  "Simplify all references in current buffer."
  597.  (if gnus-hide-autohide-toggle
  598.  (save-excursion 
  599.   (let ((buffer-read-only nil))
  600.     (gnus-simplify-references)
  601.      (set-buffer-modified-p nil)))))
  602.  
  603.  
  604. (defun gnus-Subject-simplify-references ()
  605.  "Simplify all references in current article."
  606.   (interactive)
  607.   (let ((gnus-hide-autohide-toggle t))    
  608.   (gnus-eval-in-buffer-window gnus-Article-buffer
  609.     (gnus-Article-simplify-references))))
  610.  
  611.  
  612. ;:|
  613.  
  614. ;::         UNHIDE
  615.  
  616.  
  617. (defun gnus-Subject-unhide ()
  618.   "Show signature and quotations in current article."
  619.   (interactive)
  620.   (gnus-eval-in-buffer-window gnus-Article-buffer
  621.       (let ((buffer-read-only nil))
  622.     (subst-char-in-region (point-min) (point-max) ?\C-M ?\n)
  623.     (set-buffer-modified-p nil))))
  624.  
  625.  
  626. (defun gnus-hide-yank-original-unhide ()
  627.  "Unhiding function for use in mail-yank-hooks."
  628.   (let ((buffer-read-only nil))
  629.     (subst-char-in-region (point-min) (point-max) ?\C-M ?\n)
  630.     (set-buffer-modified-p nil)))
  631.  
  632.  
  633. ;:|
  634.  
  635. ;::        TOGGLE
  636. (defvar gnus-hide-autohide-toggle t
  637.  "Only use autohiding functions if t (not nil). This toggle
  638. is changed by the function gnus-hide-autohide-toggle.")
  639.  
  640. (defun gnus-hide-autohide-toggle ()
  641.  "Toggle the autohiding feature. May be useful for 
  642. saving articles that use auto reference simplification."
  643.  (interactive)
  644.  (setq gnus-hide-autohide-toggle (not gnus-hide-autohide-toggle))
  645.  (message (if gnus-hide-autohide-toggle "Autohiding on." "Autohiding off.")))
  646.  
  647.  
  648. ;:|
  649.  
  650. ;::        OVERLOAD FUNCTIONS 
  651. ;;;
  652. ;::    Overload Code 
  653. ;; Code from Barry Warsaw, Supercite 2.2 
  654. ;; (with minor renaming mods for gnus-hide)
  655. ;; ======================================================================
  656. ;; functions which do the overloading
  657. ;; based on code supplied by umerin@tc.nagasaki.go.jp
  658.  
  659. (defvar gnus-hide-overload-functions
  660.   '((mail-yank-original            sc-mail-yank-original) 
  661.     (gnus-Subject-save-in-rmail  gnus-hide-Subject-save-in-rmail)
  662.     (gnus-Subject-save-in-mail      gnus-hide-Subject-save-in-mail)
  663.     (gnus-Subject-save-in-file      gnus-hide-Subject-save-in-file)
  664.     (gnus-Subject-save-in-folder gnus-hide-Subject-save-in-folder)
  665.     )
  666.   "*Functions to be overloaded by gnus-hide.
  667. It is a list of '(original overload)', where original is the original
  668. function symbol, overload is the supercite equivalent function.")
  669.  
  670.  
  671. (defun gnus-hide-overload-functions ()
  672.   "Overload functions defined by the variable gnus-hide-overload-functions.
  673. If the original symbol is not yet bound, it will not be overloaded.
  674. Also, if the symbol has already been overloaded, it will not be
  675. overloaded again."
  676.   (let ((binding nil)
  677.     (overloads gnus-hide-overload-functions))
  678.     (while overloads
  679.       (setq binding (car overloads)
  680.         overloads (cdr overloads))
  681.       (and (fboundp (car binding))
  682.        (not (get (car binding) 'gnus-hide-overloaded))
  683.        (progn
  684.          (fset (car binding) (symbol-function (car (cdr binding))))
  685.          (put (car binding) 'gnus-hide-overloaded 'gnus-hide-overloaded))
  686.        )
  687.       )))
  688.  
  689.  
  690.  
  691. ;:|
  692.  
  693. ;::    Sendmail Overloads 
  694. ;; Code from Barry Warsaw's Supercite 2.2 (with minor mods)
  695. ;; ======================================================================
  696. ;; sendmail.el overload functions. This is the heart of supercite
  697. ;; conformance by packages which rely on distribution emacs elisp. You
  698. ;; should almost always overload this function.
  699.  
  700. (defun sc-mail-yank-original (arg)
  701.   "Supercite version of mail-yank-original.
  702. This function is the workhorse which many packages rely upon to do
  703. citing. It inserts the message being replied to in the reply buffer.
  704. Puts point before the mail headers and mark after body of text.
  705.  
  706. Citation is accomplished by running the hook mail-yank-hooks and is
  707. thus user configurable. Default is to indent each nonblank line ARG
  708. spaces (default 3). Just \\[universal-argument] as argument means
  709. don't indent and don't delete any header fields."
  710.   (interactive "P")
  711.   (if mail-reply-buffer
  712.       (let ((start (point)))
  713.     (delete-windows-on mail-reply-buffer)
  714.     (insert-buffer mail-reply-buffer)
  715.     (if (consp arg)
  716.         nil
  717.       ;; mod 28-Jul-1989 bwarsaw@cen.com
  718.       ;; generalized, hookified citations
  719.       (run-hooks 'mail-yank-hooks))
  720.     (exchange-point-and-mark)
  721.     (if (not (eolp)) (insert ?\n)))))
  722.  
  723. (defvar mail-yank-hooks nil 
  724.   "*Hook to run citation function.
  725. Expects point and mark to be set to the region to cite.")
  726.  
  727.  
  728.  
  729. ;:|
  730.  
  731. ;::    Article Saving Overloads
  732.  
  733.  
  734.  
  735. (defvar gnus-save-article-prepare-hook '(lambda () (gnus-Subject-unhide))
  736.  "Hook to prepare article buffer for saving, (o,C-o)
  737.   eg. undoing things that are done by gnus-article-prepare-hook."
  738. )
  739.  
  740. ;;; The only difference between these and the gnus 3.13 functions
  741. ;;; is the addition of 'gnus-save-article-prepare-hook
  742.  
  743.  
  744. ;:: Rmail Save 
  745. (defun gnus-hide-Subject-save-in-rmail (&optional filename)
  746.   "Append this article to Rmail file.
  747. Optional argument FILENAME specifies file name.
  748. Directory to save to is default to `gnus-article-save-directory' which
  749. is initialized from the SAVEDIR environment variable."
  750.   (interactive)
  751.   (gnus-Subject-select-article
  752.    (not (null gnus-save-all-headers)) gnus-save-all-headers)
  753.   (run-hooks 'gnus-save-article-prepare-hook)
  754.   (gnus-eval-in-buffer-window gnus-Article-buffer
  755.     (save-excursion
  756.       (save-restriction
  757.     (widen)
  758.     (let ((default-name
  759.         (funcall gnus-rmail-save-name
  760.              gnus-newsgroup-name
  761.              gnus-current-headers
  762.              gnus-newsgroup-last-rmail
  763.              )))
  764.       (or filename
  765.           (setq filename
  766.             (read-file-name
  767.              (concat "Save article in Rmail file: (default "
  768.                  (file-name-nondirectory default-name)
  769.                  ") ")
  770.              (file-name-directory default-name)
  771.              default-name)))
  772.       (gnus-make-directory (file-name-directory filename))
  773.       (gnus-output-to-rmail filename)
  774.       ;; Remember the directory name to save articles.
  775.       (setq gnus-newsgroup-last-rmail filename)
  776.       )))
  777.     ))
  778.  
  779. ;:|
  780. ;:: Unix Mail Save
  781.  
  782. (defun gnus-Subject-save-in-mail (&optional filename)
  783.   "Append this article to Unix mail file.
  784. Optional argument FILENAME specifies file name.
  785. Directory to save to is default to `gnus-article-save-directory' which
  786. is initialized from the SAVEDIR environment variable."
  787.   (interactive)
  788.   (gnus-Subject-select-article
  789.    (not (null gnus-save-all-headers)) gnus-save-all-headers)
  790.   (run-hooks 'gnus-save-article-prepare-hook)
  791.   (gnus-eval-in-buffer-window gnus-Article-buffer
  792.     (save-excursion
  793.       (save-restriction
  794.     (widen)
  795.     (let ((default-name
  796.         (funcall gnus-mail-save-name
  797.              gnus-newsgroup-name
  798.              gnus-current-headers
  799.              gnus-newsgroup-last-mail
  800.              )))
  801.       (or filename
  802.           (setq filename
  803.             (read-file-name
  804.              (concat "Save article in Unix mail file: (default "
  805.                  (file-name-nondirectory default-name)
  806.                  ") ")
  807.              (file-name-directory default-name)
  808.              default-name)))
  809.       (gnus-make-directory (file-name-directory filename))
  810.       (rmail-output filename)
  811.       ;; Remember the directory name to save articles.
  812.       (setq gnus-newsgroup-last-mail filename)
  813.       )))
  814.     ))
  815.  
  816.  
  817. ;:|
  818. ;:: Gnus File Save
  819.  
  820. (defun gnus-hide-Subject-save-in-file (&optional filename)
  821.   "Append this article to file.
  822. Optional argument FILENAME specifies file name.
  823. Directory to save to is default to `gnus-article-save-directory' which
  824. is initialized from the SAVEDIR environment variable."
  825.   (interactive)
  826.   (gnus-Subject-select-article
  827.    (not (null gnus-save-all-headers)) gnus-save-all-headers)
  828.   (run-hooks 'gnus-save-article-prepare-hook)
  829.   (gnus-eval-in-buffer-window gnus-Article-buffer
  830.     (save-excursion
  831.       (save-restriction
  832.     (widen)
  833.     (let ((default-name
  834.         (funcall gnus-file-save-name
  835.              gnus-newsgroup-name
  836.              gnus-current-headers
  837.              gnus-newsgroup-last-file
  838.              )))
  839.       (or filename
  840.           (setq filename
  841.             (read-file-name
  842.              (concat "Save article in file: (default "
  843.                  (file-name-nondirectory default-name)
  844.                  ") ")
  845.              (file-name-directory default-name)
  846.              default-name)))
  847.       (gnus-make-directory (file-name-directory filename))
  848.       (gnus-output-to-file filename)
  849.       ;; Remember the directory name to save articles.
  850.       (setq gnus-newsgroup-last-file filename)
  851.       )))
  852.     ))
  853.  
  854. ;:|
  855. ;:: MH Folder Save
  856.  
  857. (defun gnus-hide-Subject-save-in-folder (&optional folder)
  858.   "Save this article to MH folder (using `rcvstore' in MH library).
  859. Optional argument FOLDER specifies folder name."
  860.   (interactive)
  861.   (gnus-Subject-select-article
  862.    (not (null gnus-save-all-headers)) gnus-save-all-headers)
  863.   (run-hooks 'gnus-save-article-prepare-hook)
  864.   (gnus-eval-in-buffer-window gnus-Article-buffer
  865.     (save-restriction
  866.       (widen)
  867.       ;; Thanks to yuki@flab.Fujitsu.JUNET and ohm@kaba.junet.
  868.       (mh-find-path)
  869.       (let ((folder
  870.          (or folder
  871.          (mh-prompt-for-folder "Save article in"
  872.                        (funcall gnus-folder-save-name
  873.                         gnus-newsgroup-name
  874.                         gnus-current-headers
  875.                         gnus-newsgroup-last-folder
  876.                         )
  877.                        t
  878.                        )))
  879.         (errbuf (get-buffer-create " *GNUS rcvstore*")))
  880.     (unwind-protect
  881.         (call-process-region (point-min) (point-max)
  882.                  (expand-file-name "rcvstore" mh-lib)
  883.                  nil errbuf nil folder)
  884.       (set-buffer errbuf)
  885.       (if (zerop (buffer-size))
  886.           (message "Article saved in folder: %s" folder)
  887.         (message "%s" (buffer-string)))
  888.       (kill-buffer errbuf)
  889.       (setq gnus-newsgroup-last-folder folder))
  890.     ))
  891.     ))
  892. ;:|
  893. ;:|
  894. ;:|
  895.  
  896. (provide 'gnus-hide)
  897.  
  898. ;:|
  899.