]> code.delx.au - gnu-emacs/blobdiff - lisp/info-look.el
(insert-for-yank): Set yank-undo-function after calling FUNCTION,
[gnu-emacs] / lisp / info-look.el
index 3ae7b701a124f77580eb184ba97232ec0c2ab2b5..1de84d3e4216b7d59367f791e7a8318fc480b574 100644 (file)
@@ -1,10 +1,10 @@
-;;; info-look.el --- major-mode-sensitive Info index lookup facility.
+;;; info-look.el --- major-mode-sensitive Info index lookup facility
 ;; An older version of this was known as libc.el.
 
-;; Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+;; Copyright (C) 1995,96,97,98,99,2001  Free Software Foundation, Inc.
 
-;; Author: Ralph Schleicher <rs@purple.UL.BaWue.DE>
-;; Maintainers: FSF (unless Schleicher can be found)
+;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org>
+;;         (did not show signs of life (Nov 2001)  -stef)
 ;; Keywords: help languages
 
 ;; This file is part of GNU Emacs.
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
+;; Really cool code to lookup info indexes.
+;; Try especially info-lookup-symbol (aka C-h TAB).
+
 ;;; Code:
 
 (require 'info)
@@ -51,10 +56,7 @@ Setting this variable to nil disables highlighting."
   "Overlay object used for highlighting.")
 
 (defcustom info-lookup-file-name-alist
-  '(("\\`configure\\.in\\'" . autoconf-mode)
-    ("\\`aclocal\\.m4\\'" . autoconf-mode)
-    ("\\`acsite\\.m4\\'" . autoconf-mode)
-    ("\\`acinclude\\.m4\\'" . autoconf-mode))
+  '(("\\`ac\\(local\\|site\\|include\\)\\.m4\\'" . autoconf-mode))
   "Alist of file names handled specially.
 List elements are cons cells of the form
 
@@ -125,13 +127,6 @@ OTHER-MODES is a list of cross references to other help modes.")
 (defsubst info-lookup->other-modes (topic mode)
   (nth 5 (info-lookup->mode-value topic mode)))
 
-(eval-and-compile
-  (mapcar (lambda (keyword)
-           (or (boundp keyword)
-               (set keyword keyword)))
-         '(:topic :mode :regexp :ignore-case
-           :doc-spec :parse-rule :other-modes)))
-
 (defun info-lookup-add-help (&rest arg)
   "Add or update a help specification.
 Function arguments are one or more options of the form
@@ -148,7 +143,7 @@ to `symbol', and the help mode defaults to the current major mode."
   (apply 'info-lookup-add-help* nil arg))
 
 (defun info-lookup-maybe-add-help (&rest arg)
-  "Add a help specification iff no one is defined.
+  "Add a help specification iff none is defined.
 See the documentation of the function `info-lookup-add-help'
 for more details."
   (apply 'info-lookup-add-help* t arg))
@@ -323,18 +318,29 @@ If optional argument QUERY is non-nil, query for the help mode."
   (or mode (setq mode (info-lookup-select-mode)))
   (or (info-lookup->mode-value topic mode)
       (error "No %s help available for `%s'" topic mode))
-  (let ((entry (or (assoc (if (info-lookup->ignore-case topic mode)
-                             (downcase item) item)
-                         (info-lookup->completions topic mode))
-                  (error "Not documented as a %s: %s" topic (or item ""))))
-       (modes (info-lookup->all-modes topic mode))
-       (window (selected-window))
-       found doc-spec node prefix suffix doc-found)
+  (let* ((completions (info-lookup->completions topic mode))
+         (ignore-case (info-lookup->ignore-case topic mode))
+         (entry (or (assoc (if ignore-case (downcase item) item) completions)
+                    (assoc-ignore-case item completions)
+                    (error "Not documented as a %s: %s" topic (or item ""))))
+         (modes (info-lookup->all-modes topic mode))
+         (window (selected-window))
+         found doc-spec node prefix suffix doc-found)
     (if (or (not info-lookup-other-window-flag)
            (eq (current-buffer) (get-buffer "*info*")))
        (info)
-      (save-window-excursion (info))
-      (switch-to-buffer-other-window "*info*"))
+      (progn
+       (save-window-excursion (info))
+       ;; Determine whether or not the Info buffer is visible in
+       ;; another frame on the same display.  If it is, simply raise
+       ;; that frame.  Otherwise, display it in another window.
+       (let* ((window (get-buffer-window "*info*" t))
+              (info-frame (and window (window-frame window))))
+         (if (and info-frame
+                  (display-multi-frame-p)
+                  (memq info-frame (frames-on-display-list)))
+           (select-frame info-frame)
+         (switch-to-buffer-other-window "*info*")))))
     (while (and (not found) modes)
       (setq doc-spec (info-lookup->doc-spec topic (car modes)))
       (while (and (not found) doc-spec)
@@ -351,7 +357,12 @@ If optional argument QUERY is non-nil, query for the help mode."
                 nil))
          (condition-case nil
              (progn
-               (Info-menu (or (cdr entry) item))
+                ;; Don't use Info-menu, it forces case-fold-search to t
+                (let ((case-fold-search nil))
+                  (re-search-forward
+                   (concat "^\\* " (regexp-quote (or (cdr entry) (car entry)))
+                           ":")))
+                (Info-follow-nearest-node)
                (setq found t)
                (if (or prefix suffix)
                    (let ((case-fold-search
@@ -359,12 +370,12 @@ If optional argument QUERY is non-nil, query for the help mode."
                          (buffer-read-only nil))
                      (goto-char (point-min))
                      (re-search-forward
-                      (concat prefix (regexp-quote item) suffix))
+                      (concat prefix (regexp-quote (car entry)) suffix))
                      (goto-char (match-beginning 0))
                      (and (display-color-p) info-lookup-highlight-face
                           ;; Search again for ITEM so that the first
-                          ;; occurence of ITEM will be highlighted.
-                          (re-search-forward (regexp-quote item))
+                          ;; occurrence of ITEM will be highlighted.
+                          (re-search-forward (regexp-quote (car entry)))
                           (let ((start (match-beginning 0))
                                 (end (match-end 0)))
                             (if (overlayp info-lookup-highlight-overlay)
@@ -377,6 +388,11 @@ If optional argument QUERY is non-nil, query for the help mode."
            (error nil)))
        (setq doc-spec (cdr doc-spec)))
       (setq modes (cdr modes)))
+    ;; Alert the user if case was munged, and do this after bringing up the
+    ;; info buffer since that can print messages
+    (unless (or ignore-case
+                (string-equal item (car entry)))
+      (message "Found in different case: %s" (car entry)))
     (or doc-found
        (error "Info documentation for lookup was not found"))
     ;; Don't leave the Info buffer if the help item couldn't be looked up.
@@ -641,8 +657,11 @@ Return nil if there is nothing appropriate in the buffer near point."
  :mode 'makefile-mode
  :regexp "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*"
  :doc-spec '(("(make)Name Index" nil
+             "^[ \t]*`" "'")
+            ("(automake)Macro and Variable Index" nil
              "^[ \t]*`" "'"))
- :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+")
+ :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+"
+ :other-modes '(automake-mode))
 
 (info-lookup-maybe-add-help
  :mode 'texinfo-mode
@@ -663,9 +682,14 @@ Return nil if there is nothing appropriate in the buffer near point."
 (info-lookup-maybe-add-help
  :mode 'autoconf-mode
  :regexp "A[CM]_[_A-Z0-9]+"
- :doc-spec '(("(autoconf)Macro Index" "AC_"
+ :doc-spec '(("(autoconf)Autoconf Macro Index" "AC_"
+             "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>")
+            ("(automake)Macro and Variable Index" nil
+             "^[ \t]*`" "'")
+            ;; These are for older versions (probably pre autoconf 2.5x):
+            ("(autoconf)Macro Index" "AC_"
              "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>")
-            ("(automake)Index" nil
+            ("(automake)Macro and Variable Index" nil
              "^[ \t]*`" "'"))
  ;; Autoconf symbols are M4 macros.  Thus use M4's parser.
  :parse-rule 'ignore
@@ -718,6 +742,11 @@ Return nil if there is nothing appropriate in the buffer near point."
              "^" "\\b"))
  :parse-rule "[$@%]?\\([_a-zA-Z0-9]+\\|[^a-zA-Z]\\)")
 
+(info-lookup-maybe-add-help
+ :mode 'cperl-mode
+ :regexp "[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*"
+ :other-modes '(perl-mode))
+
 (info-lookup-maybe-add-help
  :mode 'latex-mode
  :regexp "\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
@@ -726,33 +755,26 @@ Return nil if there is nothing appropriate in the buffer near point."
 
 (info-lookup-maybe-add-help
  :mode 'emacs-lisp-mode
- :regexp "[^()' \t\n]+"
+ :regexp "[^][()'\" \t\n]+"
  :doc-spec '(("(emacs)Command Index")
             ("(emacs)Variable Index")
-            ("(elisp)Index"
-             (lambda (item)
-               (let ((sym (intern-soft item)))
-                 (cond ((null sym)
-                        (if (string-equal item "nil") item))
-                       ((or (boundp sym) (fboundp sym))
-                        item))))
-             "^[ \t]+- [^:]+:[ \t]*" "\\b")))
+            ("(elisp)Index")))
 
 (info-lookup-maybe-add-help
  :mode 'lisp-interaction-mode
- :regexp "[^()' \t\n]+"
+ :regexp "[^][()'\" \t\n]+"
  :parse-rule 'ignore
  :other-modes '(emacs-lisp-mode))
 
 (info-lookup-maybe-add-help
  :mode 'lisp-mode
- :regexp "[^()' \t\n]+"
+ :regexp "[^()'\" \t\n]+"
  :parse-rule 'ignore
  :other-modes '(emacs-lisp-mode))
 
 (info-lookup-maybe-add-help
  :mode 'scheme-mode
- :regexp "[^()' \t\n]+"
+ :regexp "[^()'\" \t\n]+"
  :ignore-case t
  ;; Aubrey Jaffer's rendition from <URL:ftp://ftp-swiss.ai.mit.edu/pub/scm>
  :doc-spec '(("(r5rs)Index" nil