home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / lispref.el < prev    next >
Encoding:
Text File  |  1990-07-30  |  7.8 KB  |  190 lines

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!sgtp.apple.juice.or.jp!shin Mon Feb 26 13:09:28 1990
  2. ;Article 1162 of gnu.emacs:
  3. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!sgtp.apple.juice.or.jp!shin
  4. ;>From shin@sgtp.apple.juice.or.jp (Shinichirou Sugou)
  5. ;Newsgroups: gnu.emacs
  6. ;Subject: lispref.el
  7. ;Message-ID: <9002171123.AA01239@sgtp.apple.juice.or.jp>
  8. ;Date: 17 Feb 90 11:23:12 GMT
  9. ;Sender: daemon@tut.cis.ohio-state.edu
  10. ;Distribution: gnu
  11. ;Organization: GNUs Not Usenet
  12. ;Lines: 176
  13. ;
  14. ;[Having posted this article ago seems to fail... Try one more]
  15. ;
  16. ;If you are EmacsLisp programmer, you are tired of examining the function
  17. ;definition using the hard manual or Emacs info.
  18. ;
  19. ;lispref.el makes your life easier.  Enjoy.
  20.  
  21. ;; lispref.el -- On line quick reference tool for lispref info manual.
  22. ;; Copyright (C) Shinichirou Sugou, Feb 1990
  23.  
  24. ;; Any comment, bug report are welcome.
  25. ;;
  26. ;;   shin%sgtp.apple.juice.or.jp@uunet.uu.net
  27.  
  28. ;; This file is not yet (and will not be forever) part of GNU Emacs.
  29.  
  30. ;; GNU Emacs is distributed in the hope that it will be useful,
  31. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  32. ;; accepts responsibility to anyone for the consequences of using it
  33. ;; or for whether it serves any particular purpose or works at all,
  34. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  35. ;; License for full details.
  36.  
  37. ;; Everyone is granted permission to copy, modify and redistribute
  38. ;; GNU Emacs, but only under the conditions described in the
  39. ;; GNU Emacs General Public License.   A copy of this license is
  40. ;; supposed to have been given to you along with GNU Emacs so you
  41. ;; can know your rights and responsibilities.  It should be in a
  42. ;; file named COPYING.  Among other things, the copyright notice
  43. ;; and this notice must be preserved on all copies.
  44.  
  45. ;; SUMMARY
  46. ;;
  47. ;; lispref searches {function,command,variable...} you specified in lispref
  48. ;; info manual.  lispref searches twice, strictly and non-strictly.  For example,
  49. ;; if you specify "window", lispref searches the regexp pattern "\bwindow\b",
  50. ;; then the regexp pattern "\(\S +window\)\|(window\S +\).  Also, you can
  51. ;; use regexp.  For example, if you want to search something which includes
  52. ;; "undef" or "unset", specify "\(undef\|unset\)".  Some special regexp characters,
  53. ;; such as "^" or "$", cannot be used (if you use them, search merely fails).
  54. ;; See strict-pat/non-strict-pat in the program why these regexp isn't desirable.
  55.  
  56. ;; INSTALLATION
  57. ;;
  58. ;; When you use lispref, you must have installed lispref.texinfo into Emacs
  59. ;; info directory.  You will find lispref.texinfo file in the latest GNU product.
  60. ;; Read info in Emacs info about the way how to install lispref.texinfo
  61. ;; into info directory.
  62.  
  63. ;; USAGE
  64. ;;
  65. ;; Binding the command lispref-search to some key is a good idea.
  66. ;; (define-key global-map "\C-^i" 'lispref-search) will bind this function to
  67. ;; CTRL-^i though you can choose any key you want.
  68. ;; When lispref-search is invoked, it looks for the appropriate symbol around
  69. ;; the cursor for the default.  If you simply type <RET>, default symbol will
  70. ;; be searched.  Using Meta-^i(lisp-complete-symbol) makes life easier for typing
  71. ;; symbol.  If no appropriate symbol is found (or if the cursor is within info buffer),
  72. ;; typing <RET> will search the last symbol.
  73.  
  74.  
  75. (require 'info)
  76. (require 'cl)
  77. (defconst lispref-search-strictly t "Control variable.")
  78. (defconst lispref-search-last-symbol "" "")
  79. (defun lispref-empty-string-p (str)
  80.   (string= str ""))
  81. (defun lispref-looking-back (str)
  82.   "Return t if looking back reg-exp STR before point."
  83.   (and (save-excursion (re-search-backward str nil t))
  84.        (= (point) (match-end 0))))
  85. (defun lispref-symbol-around-point ()
  86.   "Return lisp symbol around the point, or nil if can't find."
  87.   (condition-case stub
  88.       (save-excursion
  89.         (cond ((looking-at "\(")
  90.                (skip-chars-forward "\(")
  91.                (set-mark (point))
  92.                (forward-sexp 1))
  93.               ((looking-at "\\sw\\|\\s_")
  94.                (forward-sexp 1)
  95.                (set-mark (point))
  96.                (backward-sexp 1))
  97.               ((lispref-looking-back "\\(\\sw\\|\\s_\\)\\s *")
  98.                (backward-sexp 1)
  99.                (set-mark (point))
  100.                (forward-sexp 1))
  101.               ((looking-at "\\s +\(")
  102.                (skip-chars-forward "\( \t")
  103.                (set-mark (point))
  104.                (forward-sexp 1))
  105.               ((lispref-looking-back "\\(\\sw\\|\\s_\\)\)+\\s *")
  106.                (skip-chars-backward "\) \t")
  107.                (set-mark (point))
  108.                (backward-sexp 1))
  109.               (t
  110.                (error "")))
  111.         (car (read-from-string (buffer-substring (point) (mark)))))
  112.     (error nil)))
  113. (defun lispref-search (symbol)
  114.   "Symbol is regexps.  Search lispref manual, display text in other-window."
  115.   (interactive
  116.    (let ((default nil)
  117.          (prompt "Search symbol: ")
  118.          input)
  119.      (if (not (string= (buffer-name) "*info*"))
  120.          (setq default (lispref-symbol-around-point)))
  121.      (if default
  122.          (setq prompt (concat prompt (format "(default %s) " default))))
  123.      (setq input (read-string prompt))
  124.      (list (or (and (not (lispref-empty-string-p input)) input)
  125.                (and default (format "%s" default))
  126.                ""))))
  127.  
  128.   ;; if symbol is empty string, it means that use last used symbol
  129.   (catch 'bye
  130.     (let ((old-buf (current-buffer))
  131.           (from-beg nil)
  132.           strict-pat non-strict-pat)
  133.       (if (lispref-empty-string-p symbol)
  134.           (setq symbol lispref-search-last-symbol)
  135.         (setq lispref-search-last-symbol symbol
  136.               lispref-search-strictly t
  137.               from-beg t))
  138.       (if (lispref-empty-string-p symbol)
  139.           (error "No previous symbol defined"))
  140.       (let ((pop-up-windows t))
  141.         (pop-to-buffer "*info*"))
  142.       (if (not (eq major-mode 'Info-mode))
  143.           (Info-directory))
  144.       (if from-beg
  145.           (progn (Info-goto-node "(dir)")
  146.                  (Info-menu "emacslisp")))
  147.       ;; search lispref manual twice, strictly and non-strictly
  148.       (setq strict-pat (concat (format "^\\* \\(%s\\|%s\\|%s\\|%s\\|%s\\): "
  149.                                        "command" "function" "variable" "special form"
  150.                                        "user option")
  151.                                (format "\\(%s\\)\\($\\|\\s \\)"
  152.                                        symbol)))
  153.       (setq non-strict-pat (concat (format "^\\* \\(%s\\|%s\\|%s\\|%s\\|%s\\): "
  154.                                            "command" "function" "variable" "special form"
  155.                                            "user option")
  156.                                    (format "\\(%s\\|%s\\)"
  157.                                            (format "\\(\\(%s\\)\\S +\\)" symbol)
  158.                                            (format "\\(\\S +\\(%s\\)\\)" symbol))))
  159.       (setq pat (if lispref-search-strictly
  160.                     strict-pat
  161.                   non-strict-pat))
  162.       (loop
  163.        (condition-case stub
  164.            (throw 'bye (progn (Info-search pat)
  165.                               ;; found.  move point to the beginning of symbol
  166.                               (beginning-of-line)
  167.                               (re-search-forward pat)
  168.                               (goto-char (match-beginning 2))))
  169.          (search-failed ()))
  170.        (if (not lispref-search-strictly) ; second trial failed
  171.            (throw 'bye (progn
  172.                          (pop-to-buffer old-buf) ; return back to old buffer
  173.                          (error "%s not found" symbol))))
  174.        (setq lispref-search-strictly nil
  175.             pat non-strict-pat)))))
  176.  
  177.  
  178.  
  179.  
  180.  
  181. ;CAUTION: (1) Reply-command in the mail system may NOT generate my address
  182. ;             correctly.  Please use the following address instead.
  183. ;
  184. ;               shin%sgtp.apple.juice.or.jp@uunet.uu.net
  185. ;
  186. ;         (2) I have no relation to Apple Computer Inc. :-)
  187. ;
  188. ;---
  189. ;S.Sugou
  190.