home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / interfaces / faq.el < prev    next >
Encoding:
Text File  |  1993-04-19  |  7.0 KB  |  202 lines

  1. ;;; Description:
  2. ;;; Switch to a buffer visiting an archived Usenet newsgroup FAQ file,
  3. ;;; creating one if none already exists.
  4.  
  5. ;;; Copyright:
  6. ;;; Copyright (C) 1993 Kevin Rodgers
  7. ;;;
  8. ;;; This program is free software; you can redistribute it and/or modify
  9. ;;; it under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 1, or (at your option)
  11. ;;; any later version.
  12. ;;;
  13. ;;; This program is distributed in the hope that it will be useful,
  14. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with this program; if not, write to the Free Software
  20. ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. ;;;
  22. ;;; Martin Marietta has not disclaimed any copyright interest in
  23. ;;; faq.el.
  24. ;;;
  25. ;;; Kevin Rodgers            kevin@traffic.den.mmc.com
  26. ;;; Martin Marietta MS A16401        (303) 790-3971
  27. ;;; 116 Inverness Dr. East
  28. ;;; Englewood CO 80112 USA
  29.  
  30. ;;; Installation:
  31. ;;; 1. Put this file in a directory that is a member of load-path, and
  32. ;;;    byte-compile it for better performance.
  33. ;;; 2. Put this form in default.el or ~/.emacs:
  34. ;;;    (autoload (function find-faq) "faq"
  35. ;;;      "*Find the archived Usenet NEWSGROUP FAQ file..." t)
  36. ;;; 3. If you want to bind find-faq to a key in default.el or ~/.emacs,
  37. ;;;    I suggest using C-x F:
  38. ;;;    (global-set-key "\C-xF" (function find-faq))
  39.  
  40. ;;; Usage:
  41. ;;; M-x find-faq
  42.  
  43. ;;; Notes:
  44. ;;; 1. If your site does not archive Usenet FAQs locally, ange-ftp must
  45. ;;;    be installed to access a remote archive.  See faq-host.
  46. ;;; 2. find-faq depends on the archive at faq-host being organized
  47. ;;;    according to a two-level directory structure: the directory
  48. ;;;    faq-dir should contain subdirectories named for for Usenet
  49. ;;;    newsgroups, which in turn contain the FAQ files.  (See the
  50. ;;;    relevant "To do" item.)
  51.  
  52. ;;; To do:
  53. ;;; 1. Handle other archive organizations, such as the *.answers/X-faq/
  54. ;;;    partN structure based on the FAQ Archive-name: header and
  55. ;;;    described in the *.answers "Introduction to the *.answers
  56. ;;;    newsgroups" FAQ.
  57. ;;; 2. Consider whether faq-default-newsgroup (and perhaps the other
  58. ;;;    user options) should be buffer local variables, so that, for
  59. ;;;    example, Emacs-Lisp mode could set it to "gnu.emacs.help", C mode
  60. ;;;    could set it to "comp.lang.c", C++ mode could set it to
  61. ;;;    "comp.lang.c++", etc.
  62. ;;; 3. Provide more newsgroup-to-faq mappings in faq-default-faqs.
  63. ;;;    [Users are encouraged to submit the names of introductory FAQs
  64. ;;;    for newsgroups that they read to the author.]
  65. ;;; 4. Accept "canonical" FAQ file names, and search for compressed (.z
  66. ;;;    or .Z) files, or files with different capitalization.  This would
  67. ;;;    simplify maintenance of the file names in the faq-default-faqs
  68. ;;;    association list.
  69.  
  70. ;;; Acknowledgments:
  71. ;;; Thorbjoern Hansen <thansen@diku.dk>, for his suggestions.
  72. ;;; Jonathan I. Kamens <jik@GZA.COM>, for the FAQ archive at MIT.
  73. ;;; Andy Norman <ange@hplb.hpl.hp.com>, for ange-ftp.
  74.  
  75. ;;; LCD Archive Entry:
  76. ;;; faq|Kevin Rodgers|kevin@traffic.den.mmc.com|
  77. ;;; Switch to a buffer visiting an archived Usenet newsgroup FAQ file.|
  78. ;;; 19-Apr-1993|1.2.1|~/interfaces/faq.el.Z|
  79.  
  80.  
  81. ;; Package interface:
  82.  
  83. (provide 'faq)
  84.  
  85.  
  86. ;; User options:
  87.  
  88. (defvar faq-host "rtfm.mit.edu" ; nee' pit-manager.mit.edu
  89.   "*Name of remote host where Usenet newsgroup FAQs are archived, or nil if
  90. local.
  91. See faq-user and \\[find-faq].")
  92.  
  93. (defvar faq-dir "/pub/usenet"
  94.   "*Name of directory where Usenet newsgroup FAQs are archived.
  95. See \\[find-faq].")
  96.  
  97. (defvar faq-user "anonymous"
  98.   "*Name of user to access Usenet newsgroup FAQs archived remotely, or nil if
  99. same as user login name.
  100. See faq-host and \\[find-faq].")
  101.  
  102. (defvar faq-default-newsgroup "news.newusers.questions"
  103.   "*The name of the default Usenet NEWSGROUP for \\[find-faq].")
  104.  
  105. (defvar faq-default-faqs
  106.   '(("news.newusers.questions" .
  107.      "Welcome_to_news.newusers.questions!_(weekly_posting).Z")
  108.     ("gnu.emacs.help" .
  109.      "GNU_Emacs_FAQ_(0_5):_Intro_Contents.Z"))
  110.   "*An association list whose keys are Usenet newsgroups names that index
  111. their default FAQ file name for \\[find-faq].")
  112.  
  113. (defvar find-faq-hooks nil
  114.   "*A function or list of functions that are run before \\[find-faq] returns.")
  115.  
  116. (defvar faq-load-hooks nil
  117.   "*A function or list of functions that are run when faq.el is loaded.
  118. This is most useful for adding new entries to faq-default-faqs or
  119. enabling \\[find-faq]'s interactive argument history mechanism, like
  120. this:
  121.  
  122. \(setq faq-load-hooks 
  123.       \(function \(lambda \(\)
  124.           \(setq faq-default-faqs
  125.             \(cons '\(\"comp.lang.lisp\" .
  126.                 \"FAQ:_Lisp_Frequently_Asked_Questions_1_6_[Monthly_posting].Z\"\)
  127.                   faq-default-faqs\)\)
  128.           \(require 'gmhist\)\)\)\)
  129. ")
  130.  
  131.  
  132. ;; Commands:
  133.  
  134. (defun find-faq (newsgroup faq)
  135.   "*Find the archived Usenet NEWSGROUP FAQ file.  Completion is provided
  136. for both the NEWSGROUP name and FAQ file name, and history is provided
  137. for the NEWSGROUP name if the gmhist package is loaded \(see faq-load-
  138. hooks\).
  139. See faq-host, faq-dir, faq-user, faq-default-newsgroup, and
  140. faq-default-faqs."
  141.   (interactive
  142.    (let* ((insert-default-directory    ; simplify read-file-name prompt
  143.                     ; (and read relative pathnames)
  144.        nil)
  145.       (default-directory
  146.         (if faq-host
  147.         (progn
  148.           (require 'ange-ftp)    ; remote filename syntax
  149.           (file-name-as-directory
  150.            (concat "/" faq-user "@" faq-host ":" faq-dir)))
  151.           (file-name-as-directory faq-dir)))
  152.       (default-newsgroup-dir
  153.         (file-name-as-directory (or faq-default-newsgroup "")))
  154.       (newsgroup-dir
  155.        (if (featurep 'gmhist)
  156.            (progn
  157.          (put 'find-faq-newsgroup-dir-history 'initial-hist
  158.               (list default-newsgroup-dir))
  159.          (read-file-name-with-history-in
  160.           'find-faq-newsgroup-dir-history
  161.           "Newsgroup (append trailing /): "
  162.           nil
  163.           (if (boundp 'find-faq-newsgroup-dir-history)
  164.               (car find-faq-newsgroup-dir-history)
  165.             default-newsgroup-dir)
  166.           t))
  167.          (read-file-name (format "Newsgroup (append trailing /): [%s] "
  168.                      default-newsgroup-dir)
  169.                  nil
  170.                  default-newsgroup-dir
  171.                  t)))
  172.       (default-faq-file            ; newsgroup-specific
  173.         (or (cdr (assoc (directory-file-name newsgroup-dir)
  174.                 faq-default-faqs))
  175.         ""))
  176.       (faq-file
  177.        (progn
  178.          (setq default-directory
  179.            (concat default-directory newsgroup-dir))
  180.          (read-file-name (format "FAQ: [%s] " default-faq-file)
  181.                  nil
  182.                  default-faq-file
  183.                  t))))
  184.      (list (directory-file-name newsgroup-dir)
  185.        faq-file)))
  186.   (let ((newsgroup-faq
  187.      (concat (if faq-host
  188.              (concat "/" faq-user "@" faq-host ":" ))
  189.          (file-name-as-directory faq-dir)
  190.          (file-name-as-directory newsgroup)
  191.          faq)))
  192.     (if (file-exists-p newsgroup-faq)
  193.     (progn
  194.       (find-file newsgroup-faq)
  195.       (setq buffer-read-only t)
  196.       (run-hooks 'faq-hooks))
  197.       (error "File %s does not exist." newsgroup-faq))))
  198.  
  199.  
  200. ;; Run faq-load-hook:
  201. (run-hooks 'faq-load-hooks)
  202.