]> code.delx.au - gnu-emacs/blobdiff - lisp/info-look.el
Wrap around error in coreutil's ls
[gnu-emacs] / lisp / info-look.el
index eb780fe562075442ad0bf2ce1d5d0e166fde0a5d..899f41e850df6a994f7464408161f4f89af952c5 100644 (file)
@@ -1,7 +1,7 @@
 ;;; info-look.el --- major-mode-sensitive Info index lookup facility -*- lexical-binding: t -*-
 ;; An older version of this was known as libc.el.
 
 ;;; info-look.el --- major-mode-sensitive Info index lookup facility -*- lexical-binding: t -*-
 ;; An older version of this was known as libc.el.
 
-;; Copyright (C) 1995-1999, 2001-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1995-1999, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org>
 ;;         (did not show signs of life (Nov 2001)  -stef)
 
 ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org>
 ;;         (did not show signs of life (Nov 2001)  -stef)
 ;; Really cool code to lookup info indexes.
 ;; Try especially info-lookup-symbol (aka C-h S).
 
 ;; Really cool code to lookup info indexes.
 ;; Try especially info-lookup-symbol (aka C-h S).
 
+;; Some additional sources of (Tex)info files for non-GNU packages:
+;;
+;; Scheme: <URL:http://groups.csail.mit.edu/mac/ftpdir/scm/r5rs.info.tar.gz>
+;; LaTeX:
+;;  <URL:ftp://ctan.tug.org/tex-archive/info/latex2e-help-texinfo/latex2e.texi>
+;;  (or CTAN mirrors)
+;; Perl: <URL:ftp://ftp.cpan.org/pub/CPAN/doc/manual/texinfo/> (or CPAN mirrors)
+
+;; Traditionally, makeinfo quoted `like this', but version 5 and later
+;; quotes 'like this' or ‘like this’.  Doc specs with patterns
+;; therefore match open and close quotes with ['`‘] and ['’],
+;; respectively.
+
 ;;; Code:
 
 (require 'info)
 ;;; Code:
 
 (require 'info)
@@ -129,7 +142,7 @@ OTHER-MODES is a list of cross references to other help modes.")
   "Add or update a help specification.
 Function arguments are specified as keyword/argument pairs:
 
   "Add or update a help specification.
 Function arguments are specified as keyword/argument pairs:
 
-    \(KEYWORD . ARGUMENT)
+    (KEYWORD . ARGUMENT)
 
 KEYWORD is either `:topic', `:mode', `:regexp', `:ignore-case',
  `:doc-spec', `:parse-rule', or `:other-modes'.
 
 KEYWORD is either `:topic', `:mode', `:regexp', `:ignore-case',
  `:doc-spec', `:parse-rule', or `:other-modes'.
@@ -252,7 +265,7 @@ minibuffer.  In the minibuffer, use M-n to yank the default argument
 value into the minibuffer so you can edit it.  The default symbol is the
 one found at point.
 
 value into the minibuffer so you can edit it.  The default symbol is the
 one found at point.
 
-With prefix arg a query for the symbol help mode is offered."
+With prefix arg MODE a query for the symbol help mode is offered."
   (interactive
    (info-lookup-interactive-arguments 'symbol current-prefix-arg))
   (info-lookup 'symbol symbol mode))
   (interactive
    (info-lookup-interactive-arguments 'symbol current-prefix-arg))
   (info-lookup 'symbol symbol mode))
@@ -266,7 +279,7 @@ In the minibuffer, use M-n to yank the default file name
 into the minibuffer so you can edit it.
 The default file name is the one found at point.
 
 into the minibuffer so you can edit it.
 The default file name is the one found at point.
 
-With prefix arg a query for the file help mode is offered."
+With prefix arg MODE a query for the file help mode is offered."
   (interactive
    (info-lookup-interactive-arguments 'file current-prefix-arg))
   (info-lookup 'file file mode))
   (interactive
    (info-lookup-interactive-arguments 'file current-prefix-arg))
   (info-lookup 'file file mode))
@@ -298,6 +311,21 @@ If optional argument QUERY is non-nil, query for the help mode."
        (when (string-match (caar file-name-alist) file-name)
          (setq info-lookup-mode (cdar file-name-alist)))
        (setq file-name-alist (cdr file-name-alist)))))
        (when (string-match (caar file-name-alist) file-name)
          (setq info-lookup-mode (cdar file-name-alist)))
        (setq file-name-alist (cdr file-name-alist)))))
+
+  ;; If major-mode has no setups in info-lookup-alist, under any topic, then
+  ;; search up through derived-mode-parent to find a parent mode which does
+  ;; have some setups.  This means that a `define-derived-mode' with no
+  ;; setups of its own will select its parent mode for lookups, if one of
+  ;; its parents has some setups.  Good for example on `makefile-gmake-mode'
+  ;; and similar derivatives of `makefile-mode'.
+  ;;
+  (let ((mode major-mode)) ;; Look for `mode' with some setups.
+    (while (and mode (not info-lookup-mode))
+      (dolist (topic-cell info-lookup-alist) ;; Usually only two topics here.
+        (if (info-lookup->mode-value (car topic-cell) mode)
+            (setq info-lookup-mode mode)))
+      (setq mode (get mode 'derived-mode-parent))))
+
   (or info-lookup-mode (setq info-lookup-mode major-mode)))
 
 (defun info-lookup-change-mode (topic)
   (or info-lookup-mode (setq info-lookup-mode major-mode)))
 
 (defun info-lookup-change-mode (topic)
@@ -585,8 +613,8 @@ Return nil if there is nothing appropriate in the buffer near point."
   (condition-case nil
       (save-excursion
        (let ((case-fold-search t)
   (condition-case nil
       (save-excursion
        (let ((case-fold-search t)
-             (ignored-chars "][()`',:.\" \t\n")
-             (significant-chars "^][()`',:.\" \t\n")
+             (ignored-chars "][()`'‘’,:.\" \t\n")
+             (significant-chars "^][()`'‘’,:.\" \t\n")
              beg end)
          (cond
           ((and (memq (get-char-property (point) 'face)
              beg end)
          (cond
           ((and (memq (get-char-property (point) 'face)
@@ -606,7 +634,8 @@ Return nil if there is nothing appropriate in the buffer near point."
                     (setq end (point))
                     (> end beg))
                (and (looking-at "[ \t\n]")
                     (setq end (point))
                     (> end beg))
                (and (looking-at "[ \t\n]")
-                    (looking-back (concat "[" significant-chars "]"))
+                    (looking-back (concat "[" significant-chars "]")
+                                   (1- (point)))
                     (setq end (point))
                     (skip-chars-backward significant-chars)
                     (setq beg (point))
                     (setq end (point))
                     (skip-chars-backward significant-chars)
                     (setq beg (point))
@@ -693,12 +722,12 @@ Return nil if there is nothing appropriate in the buffer near point."
              ;; suffix "\\>" is not used because that sends DBL_MAX to
              ;; DBL_MAX_EXP ("_" is a non-word char)
             ("(libc)Variable Index" nil
              ;; suffix "\\>" is not used because that sends DBL_MAX to
              ;; DBL_MAX_EXP ("_" is a non-word char)
             ("(libc)Variable Index" nil
-              "^\\([ \t]+-+ \\(Variable\\|Macro\\): .*\\<\\|`\\)"
-              "\\( \\|'?$\\)")
+              "^\\([ \t]+-+ \\(Variable\\|Macro\\): .*\\<\\|['`‘]\\)"
+              "\\( \\|['’]?$\\)")
             ("(libc)Type Index" nil
              "^[ \t]+-+ Data Type: \\<" "\\>")
             ("(termcap)Var Index" nil
             ("(libc)Type Index" nil
              "^[ \t]+-+ Data Type: \\<" "\\>")
             ("(termcap)Var Index" nil
-             "^[ \t]*`" "'"))
+             "^[ \t]*['`‘]" "['’]"))
  :parse-rule 'info-lookup-guess-c-symbol)
 
 (info-lookup-maybe-add-help
  :parse-rule 'info-lookup-guess-c-symbol)
 
 (info-lookup-maybe-add-help
@@ -710,7 +739,7 @@ Return nil if there is nothing appropriate in the buffer near point."
  :mode 'bison-mode
  :regexp "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+"
  :doc-spec '(("(bison)Index" nil
  :mode 'bison-mode
  :regexp "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+"
  :doc-spec '(("(bison)Index" nil
-             "`" "'"))
+             "['`‘]" "['’]"))
  :parse-rule "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)"
  :other-modes '(c-mode))
 
  :parse-rule "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)"
  :other-modes '(c-mode))
 
@@ -718,7 +747,7 @@ 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
  :mode 'makefile-mode
  :regexp "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*"
  :doc-spec '(("(make)Name Index" nil
-             "^[ \t]*`" "'"))
+             "^[ \t]*['`‘]" "['’]"))
  :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+")
 
 (info-lookup-maybe-add-help
  :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+")
 
 (info-lookup-maybe-add-help
@@ -733,15 +762,16 @@ Return nil if there is nothing appropriate in the buffer near point."
  :doc-spec   '(
                ;; "(automake)Macro Index" is autoconf macros used in
                ;; configure.ac, not Makefile.am, so don't have that here.
  :doc-spec   '(
                ;; "(automake)Macro Index" is autoconf macros used in
                ;; configure.ac, not Makefile.am, so don't have that here.
-               ("(automake)Variable Index" nil "^[ \t]*`" "'")
+               ("(automake)Variable Index" nil "^[ \t]*['`‘]" "['’]")
                ;; In automake 1.4 macros and variables were a combined node.
                ;; In automake 1.4 macros and variables were a combined node.
-               ("(automake)Macro and Variable Index" nil "^[ \t]*`" "'")
+               ("(automake)Macro and Variable Index" nil "^[ \t]*['`‘]"
+               "['’]")
                ;; Directives like "if" are in the "General Index".
                ;; Prefix "`" since the text for say `+=' isn't always an
                ;; @item etc and so not always at the start of a line.
                ;; Directives like "if" are in the "General Index".
                ;; Prefix "`" since the text for say `+=' isn't always an
                ;; @item etc and so not always at the start of a line.
-               ("(automake)General Index" nil "`" "'")
+               ("(automake)General Index" nil "['`‘]" "['’]")
                ;; In automake 1.3 there was just a single "Index" node.
                ;; In automake 1.3 there was just a single "Index" node.
-               ("(automake)Index" nil "`" "'"))
+               ("(automake)Index" nil "['`‘]" "['’]"))
  :other-modes '(makefile-mode))
 
 (info-lookup-maybe-add-help
  :other-modes '(makefile-mode))
 
 (info-lookup-maybe-add-help
@@ -752,7 +782,7 @@ Return nil if there is nothing appropriate in the buffer near point."
              (lambda (item)
                (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item)
                    (concat "@" (match-string 1 item))))
              (lambda (item)
                (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item)
                    (concat "@" (match-string 1 item))))
-             "`" "[' ]")))
+             "['`‘]" "['’ ]")))
 
 (info-lookup-maybe-add-help
  :mode 'm4-mode
 
 (info-lookup-maybe-add-help
  :mode 'm4-mode
@@ -798,7 +828,7 @@ Return nil if there is nothing appropriate in the buffer near point."
             ;; macros (eg. AC_PROG_CC).  Ensure this is after the autoconf
             ;; index, so as to prefer the autoconf docs.
             ("(automake)Macro and Variable Index" nil
             ;; macros (eg. AC_PROG_CC).  Ensure this is after the autoconf
             ;; index, so as to prefer the autoconf docs.
             ("(automake)Macro and Variable Index" nil
-             "^[ \t]*`" "'"))
+             "^[ \t]*['`‘]" "['’]"))
  ;; Autoconf symbols are M4 macros.  Thus use M4's parser.
  :parse-rule 'ignore
  :other-modes '(m4-mode))
  ;; Autoconf symbols are M4 macros.  Thus use M4's parser.
  :parse-rule 'ignore
  :other-modes '(m4-mode))
@@ -823,7 +853,7 @@ Return nil if there is nothing appropriate in the buffer near point."
                   ;; Built-in functions (matches to many entries).
                   ((string-match "^[a-z]+$" item)
                    item))))
                   ;; Built-in functions (matches to many entries).
                   ((string-match "^[a-z]+$" item)
                    item))))
-             "`" "\\([ \t]*([^)]*)\\)?'")))
+             "['`‘]" "\\([ \t]*([^)]*)\\)?['’]")))
 
 (info-lookup-maybe-add-help
  :mode 'perl-mode
 
 (info-lookup-maybe-add-help
  :mode 'perl-mode
@@ -858,17 +888,23 @@ Return nil if there is nothing appropriate in the buffer near point."
 (info-lookup-maybe-add-help
  :mode 'latex-mode
  :regexp "\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
 (info-lookup-maybe-add-help
  :mode 'latex-mode
  :regexp "\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
- :doc-spec '(("(latex)Command Index" nil
-             "`" "\\({[^}]*}\\)?'")))
+ :doc-spec `((,(if (Info-find-file "latex2e" t)
+                  ;; From http://home.gna.org/latexrefman
+                  "(latex2e)Command Index"
+                "(latex)Command Index")
+             ;; \frac{NUM}{DEN} etc can have more than one {xx} argument.
+             ;; \sqrt[ROOT]{num} and others can have square brackets.
+             nil "[`'‘]" "\\({[^}]*}|\\[[^]]*\\]\\)*['’]")))
+
 
 (info-lookup-maybe-add-help
  :mode 'emacs-lisp-mode
 
 (info-lookup-maybe-add-help
  :mode 'emacs-lisp-mode
- :regexp "[^][()`',\" \t\n]+"
+ :regexp "[^][()`'‘’,\" \t\n]+"
  :doc-spec '(;; Commands with key sequences appear in nodes as `foo' and
              ;; those without as `M-x foo'.
  :doc-spec '(;; Commands with key sequences appear in nodes as `foo' and
              ;; those without as `M-x foo'.
-             ("(emacs)Command Index"  nil "`\\(M-x[ \t\n]+\\)?" "'")
+             ("(emacs)Command Index"  nil "['`‘]\\(M-x[ \t\n]+\\)?" "['’]")
              ;; Variables normally appear in nodes as just `foo'.
              ;; Variables normally appear in nodes as just `foo'.
-             ("(emacs)Variable Index" nil "`" "'")
+             ("(emacs)Variable Index" nil "['`‘]" "['’]")
              ;; Almost all functions, variables, etc appear in nodes as
              ;; " -- Function: foo" etc.  A small number of aliases and
              ;; symbols appear only as `foo', and will miss out on exact
              ;; Almost all functions, variables, etc appear in nodes as
              ;; " -- Function: foo" etc.  A small number of aliases and
              ;; symbols appear only as `foo', and will miss out on exact
@@ -876,29 +912,31 @@ Return nil if there is nothing appropriate in the buffer near point."
              ;; for things that should go to Function: etc, and those latter
              ;; are much more important.  Perhaps this could change if some
              ;; sort of fallback match scheme existed.
              ;; for things that should go to Function: etc, and those latter
              ;; are much more important.  Perhaps this could change if some
              ;; sort of fallback match scheme existed.
-             ("(elisp)Index"          nil "^ -+ .*: " "\\( \\|$\\)")))
+             ("(elisp)Index"          nil "^ -+ .*: " "\\( \\|$\\)")
+             ("(cl)Function Index"    nil "^ -+ .*: " "\\( \\|$\\)")
+             ("(cl)Variable Index"    nil "^ -+ .*: " "\\( \\|$\\)")))
 
 ;; docstrings talk about elisp, so have apropos-mode follow emacs-lisp-mode
 (info-lookup-maybe-add-help
  :mode 'apropos-mode
 
 ;; docstrings talk about elisp, so have apropos-mode follow emacs-lisp-mode
 (info-lookup-maybe-add-help
  :mode 'apropos-mode
- :regexp "[^][()`',\" \t\n]+" ;; same as emacs-lisp-mode above
+ :regexp "[^][()`'‘’,\" \t\n]+" ;; same as emacs-lisp-mode above
  :other-modes '(emacs-lisp-mode))
 
 (info-lookup-maybe-add-help
  :mode 'lisp-interaction-mode
  :other-modes '(emacs-lisp-mode))
 
 (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
  :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
  :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
  :ignore-case t
  ;; Aubrey Jaffer's rendition from <URL:ftp://ftp-swiss.ai.mit.edu/pub/scm>
  :doc-spec '(("(r5rs)Index" nil
@@ -950,9 +988,9 @@ Return nil if there is nothing appropriate in the buffer near point."
  ;; bash has "." and ":" in its index, but those chars will probably never
  ;; work in info, so don't bother matching them in the regexp.
  :regexp "\\([a-zA-Z0-9_-]+\\|[!{}@*#?$]\\|\\[\\[?\\|]]?\\)"
  ;; bash has "." and ":" in its index, but those chars will probably never
  ;; work in info, so don't bother matching them in the regexp.
  :regexp "\\([a-zA-Z0-9_-]+\\|[!{}@*#?$]\\|\\[\\[?\\|]]?\\)"
- :doc-spec '(("(bash)Builtin Index"       nil "^`" "[ .']")
-             ("(bash)Reserved Word Index" nil "^`" "[ .']")
-             ("(bash)Variable Index"      nil "^`" "[ .']")
+ :doc-spec '(("(bash)Builtin Index"       nil "^['`‘]" "[ .'’]")
+             ("(bash)Reserved Word Index" nil "^['`‘]" "[ .'’]")
+             ("(bash)Variable Index"      nil "^['`‘]" "[ .'’]")
 
              ;; coreutils (version 4.5.10) doesn't have a separate program
              ;; index, so exclude extraneous stuff (most of it) by demanding
 
              ;; coreutils (version 4.5.10) doesn't have a separate program
              ;; index, so exclude extraneous stuff (most of it) by demanding
@@ -1000,18 +1038,18 @@ Return nil if there is nothing appropriate in the buffer near point."
                  item))
              ;; This gets functions in evaluated classes.  Other
              ;; possible patterns don't seem to work too well.
                  item))
              ;; This gets functions in evaluated classes.  Other
              ;; possible patterns don't seem to work too well.
-             "`" "(")))
+             "['`‘]" "(")))
 
 (info-lookup-maybe-add-help
  :mode 'Custom-mode
  :ignore-case t
 
 (info-lookup-maybe-add-help
  :mode 'Custom-mode
  :ignore-case t
- :regexp "[^][()`',:\" \t\n]+"
+ :regexp "[^][()`'‘’,:\" \t\n]+"
  :parse-rule 'info-lookup-guess-custom-symbol
  :other-modes '(emacs-lisp-mode))
 
 (info-lookup-maybe-add-help
  :mode 'help-mode
  :parse-rule 'info-lookup-guess-custom-symbol
  :other-modes '(emacs-lisp-mode))
 
 (info-lookup-maybe-add-help
  :mode 'help-mode
- :regexp "[^][()`',:\" \t\n]+"
+ :regexp "[^][()`'‘’,:\" \t\n]+"
  :other-modes '(emacs-lisp-mode))
 \f
 (provide 'info-look)
  :other-modes '(emacs-lisp-mode))
 \f
 (provide 'info-look)