home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / help-lucid-emacs / text0148.txt < prev    next >
Encoding:
Text File  |  1993-07-14  |  34.2 KB  |  1,008 lines

  1.  
  2. I've added a popup-submenu and the Info-mode-hook for the
  3. Info-bookmark- commands to the info.el from lemacs-19.4. 
  4. You need the file info-bookmark.el from Karl Fogel and 
  5. Ken Olstad too. I've posted it a couple of hours before 
  6. this one. 
  7. I don't know if somone else is working at this time at the
  8. info.el for the lemacs. But I think somone should change the
  9. file (I hope he will take this one) and add the capability
  10. to extend the Info mode with hooks, that we can add new
  11. popup menu items, functions and so on without changing
  12. the info.el (Or is there a posibility that I've not seen ?). 
  13.  
  14.  
  15. - - - cut here - - -
  16. ;; Info package for Emacs  -- could use a "create node" feature.
  17. ;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
  18.  
  19. ;; 1993, Heiko Muenkel: I've added a popup-submenu and the
  20. ;; Info-bookmark- commands for the Info-mode-hook. You need
  21. ;; also the file info-bookmark.el from Karl Fogel and Ken Olstad.
  22.  
  23. ;; This file is part of GNU Emacs.
  24.  
  25. ;; GNU Emacs is free software; you can redistribute it and/or modify
  26. ;; it under the terms of the GNU General Public License as published by
  27. ;; the Free Software Foundation; either version 2, or (at your option)
  28. ;; any later version.
  29.  
  30. ;; GNU Emacs is distributed in the hope that it will be useful,
  31. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  33. ;; GNU General Public License for more details.
  34.  
  35. ;; You should have received a copy of the GNU General Public License
  36. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  37. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  38.  
  39. (provide 'info)
  40. (require 'info-bookmark)
  41.  
  42. (defvar Info-history nil
  43.   "List of info nodes user has visited.
  44. Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
  45.  
  46. (defvar Info-enable-edit nil
  47.   "Non-nil means the \\[Info-edit] command in Info can edit the current node.")
  48.  
  49. (defvar Info-enable-active-nodes t
  50.   "Non-nil allows Info to execute Lisp code associated with nodes.
  51. The Lisp code is executed when the node is selected.")
  52.  
  53. (defvar Info-directory-list nil
  54.   "List of directories to search for Info documentation files.")
  55.  
  56. (defvar Info-current-file nil
  57.   "Info file that Info is now looking at, or nil.")
  58.  
  59. (defvar Info-current-subfile nil
  60.   "Info subfile that is actually in the *info* buffer now,
  61. or nil if current info file is not split into subfiles.")
  62.  
  63. (defvar Info-current-node nil
  64.   "Name of node that Info is now looking at, or nil.")
  65.  
  66. (defvar Info-tag-table-marker (make-marker)
  67.   "Marker pointing at beginning of current Info file's tag table.
  68. Marker points nowhere if file has no tag table.")
  69.  
  70. (defun info ()
  71.   "Enter Info, the documentation browser."
  72.   (interactive)
  73.   (if (get-buffer "*info*")
  74.       (switch-to-buffer "*info*")
  75.     (Info-directory)))
  76.  
  77. ;; Go to an info node specified as separate filename and nodename.
  78. ;; no-going-back is non-nil if recovering from an error in this function;
  79. ;; it says do not attempt further (recursive) error recovery.
  80. (defun Info-find-node (filename nodename &optional no-going-back)
  81.   ;; Convert filename to lower case if not found as specified.
  82.   ;; Expand it.
  83.   (if filename
  84.       (let (temp found)
  85.     (setq filename (substitute-in-file-name filename))
  86.     (if (not (string-match "^\\./" filename))
  87.         (let ((dirs Info-directory-list))
  88.           ;; Search the directory list for file FILENAME.
  89.           (while (and dirs (not found))
  90.         (setq found
  91.               (expand-file-name filename (car dirs)))
  92.         (if (not (file-exists-p found))
  93.             (setq found nil))
  94.         ;; Also try (downcase FILENAME) in each directory.
  95.         (or found
  96.             (progn
  97.               (setq found
  98.                 (expand-file-name (downcase filename)
  99.                           (car dirs)))
  100.               (if (not (file-exists-p found))
  101.               (setq found nil))))
  102.         (setq dirs (cdr dirs))))
  103.       ;; FILENAME starts with `./'; just look in current directory.
  104.       (if (file-exists-p (expand-file-name filename))
  105.           (setq found (file-exists-p (expand-file-name filename)))))
  106.     (if found
  107.         (setq filename found)
  108.       (error "Info file %s does not exist" filename))))
  109.   ;; Record the node we are leaving.
  110.   (if (and Info-current-file (not no-going-back))
  111.       (setq Info-history
  112.         (cons (list Info-current-file Info-current-node (point))
  113.           Info-history)))
  114.   ;; Go into info buffer.
  115.   (switch-to-buffer "*info*")
  116.   (or (eq major-mode 'Info-mode)
  117.       (Info-mode))
  118.   (widen)
  119.   (setq Info-current-node nil)
  120.   (unwind-protect
  121.       (progn
  122.     ;; Switch files if necessary
  123.     (or (null filename)
  124.         (equal Info-current-file filename)
  125.         (let ((buffer-read-only nil))
  126.           (setq Info-current-file nil
  127.             Info-current-subfile nil
  128.             buffer-file-name nil)
  129.           (erase-buffer)
  130.           (insert-file-contents filename t)
  131.           (set-buffer-modified-p nil)
  132.           (setq default-directory (file-name-directory filename))
  133.           ;; See whether file has a tag table.  Record the location if yes.
  134.           (set-marker Info-tag-table-marker nil)
  135.           (goto-char (point-max))
  136.           (forward-line -8)
  137.           (or (equal nodename "*")
  138.           (not (search-forward "\^_\nEnd tag table\n" nil t))
  139.           (let (pos)
  140.             ;; We have a tag table.  Find its beginning.
  141.             ;; Is this an indirect file?
  142.             (search-backward "\nTag table:\n")
  143.             (setq pos (point))
  144.             (if (save-excursion
  145.               (forward-line 2)
  146.               (looking-at "(Indirect)\n"))
  147.             ;; It is indirect.  Copy it to another buffer
  148.             ;; and record that the tag table is in that buffer.
  149.             (save-excursion
  150.               (let ((buf (current-buffer)))
  151.                 (set-buffer (get-buffer-create " *info tag table*"))
  152.                 (setq case-fold-search t)
  153.                 (erase-buffer)
  154.                 (insert-buffer-substring buf)
  155.                 (set-marker Info-tag-table-marker
  156.                     (match-end 0))))
  157.              (set-marker Info-tag-table-marker pos))))
  158.           (setq Info-current-file
  159.             (file-name-sans-versions buffer-file-name))))
  160.     (if (equal nodename "*")
  161.         (progn (setq Info-current-node nodename)
  162.            (Info-set-mode-line))
  163.       ;; Search file for a suitable node.
  164.       ;; First get advice from tag table if file has one.
  165.       ;; Also, if this is an indirect info file,
  166.       ;; read the proper subfile into this buffer.
  167.       (let ((guesspos (point-min)))
  168.         (if (marker-position Info-tag-table-marker)
  169.         (save-excursion
  170.           (set-buffer (marker-buffer Info-tag-table-marker))
  171.           (goto-char Info-tag-table-marker)
  172.           (if (search-forward (concat "Node: " nodename "\177") nil t)
  173.               (progn
  174.             (setq guesspos (read (current-buffer)))
  175.             ;; If this is an indirect file,
  176.             ;; determine which file really holds this node
  177.             ;; and read it in.
  178.             (if (not (eq (current-buffer) (get-buffer "*info*")))
  179.                 (setq guesspos
  180.                   (Info-read-subfile guesspos))))
  181.             (error "No such node: \"%s\"" nodename))))
  182.         (goto-char (max (point-min) (- guesspos 1000))))
  183.       ;; Now search from our advised position (or from beg of buffer)
  184.       ;; to find the actual node.
  185.       (let ((regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n]")))
  186.         (catch 'foo
  187.           (while (search-forward "\n\^_" nil t)
  188.         (forward-line 1)
  189.         (let ((beg (point)))
  190.           (forward-line 1)
  191.           (if (re-search-backward regexp beg t)
  192.               (throw 'foo t))))
  193.           (error "No such node: %s" nodename)))
  194.       (Info-select-node)))
  195.     ;; If we did not finish finding the specified node,
  196.     ;; go back to the previous one.
  197.     (or Info-current-node no-going-back
  198.     (let ((hist (car Info-history)))
  199.       (setq Info-history (cdr Info-history))
  200.       (Info-find-node (nth 0 hist) (nth 1 hist) t)
  201.       (goto-char (nth 2 hist)))))
  202.   (goto-char (point-min)))
  203.  
  204. (defun Info-read-subfile (nodepos)
  205.   (set-buffer (marker-buffer Info-tag-table-marker))
  206.   (goto-char (point-min))
  207.   (search-forward "\n\^_")
  208.   (let (lastfilepos
  209.     lastfilename)
  210.     (forward-line 2)
  211.     (catch 'foo
  212.       (while (not (looking-at "\^_"))
  213.     (if (not (eolp))
  214.         (let ((beg (point))
  215.           thisfilepos thisfilename)
  216.           (search-forward ": ")
  217.           (setq thisfilename  (buffer-substring beg (- (point) 2)))
  218.           (setq thisfilepos (read (current-buffer)))
  219.           ;; read in version 19 stops at the end of number.
  220.           ;; Advance to the next line.
  221.           (forward-line 1)
  222.           (if (> thisfilepos nodepos)
  223.           (throw 'foo t))
  224.           (setq lastfilename thisfilename)
  225.           (setq lastfilepos thisfilepos)))))
  226.     (set-buffer (get-buffer "*info*"))
  227.     (or (equal Info-current-subfile lastfilename)
  228.     (let ((buffer-read-only nil))
  229.       (setq buffer-file-name nil)
  230.       (widen)
  231.       (erase-buffer)
  232.       (insert-file-contents lastfilename)
  233.       (set-buffer-modified-p nil)
  234.       (setq Info-current-subfile lastfilename)))
  235.     (goto-char (point-min))
  236.     (search-forward "\n\^_")
  237.     (+ (- nodepos lastfilepos) (point))))
  238.  
  239. ;; Select the info node that point is in.
  240. (defun Info-select-node ()
  241.   (save-excursion
  242.    ;; Find beginning of node.
  243.    (search-backward "\n\^_")
  244.    (forward-line 2)
  245.    ;; Get nodename spelled as it is in the node.
  246.    (re-search-forward "Node:[ \t]*")
  247.    (setq Info-current-node
  248.      (buffer-substring (point)
  249.                (progn
  250.                 (skip-chars-forward "^,\t\n")
  251.                 (point))))
  252.    (Info-set-mode-line)
  253.    ;; Find the end of it, and narrow.
  254.    (beginning-of-line)
  255.    (let (active-expression)
  256.      (narrow-to-region (point)
  257.                (if (re-search-forward "\n[\^_\f]" nil t)
  258.                (prog1
  259.                 (1- (point))
  260.                 (if (looking-at "[\n\^_\f]*execute: ")
  261.                 (progn
  262.                   (goto-char (match-end 0))
  263.                   (setq active-expression
  264.                     (read (current-buffer))))))
  265.              (point-max)))
  266.      (if Info-enable-active-nodes (eval active-expression))
  267.      (Info-fontify-node)
  268.      )))
  269.  
  270. (defun Info-set-mode-line ()
  271.   (setq mode-line-buffer-identification
  272.     (concat
  273.      "Info:  ("
  274.      (if Info-current-file
  275.          (file-name-nondirectory Info-current-file)
  276.        "")
  277.      ")"
  278.      (or Info-current-node ""))))
  279.  
  280. ;; Go to an info node specified with a filename-and-nodename string
  281. ;; of the sort that is found in pointers in nodes.
  282.  
  283. (defun Info-goto-node (nodename)
  284.   "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME."
  285.   (interactive "sGoto node: ")
  286.   (let (filename)
  287.     (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
  288.           nodename)
  289.     (setq filename (if (= (match-beginning 1) (match-end 1))
  290.                ""
  291.              (substring nodename (match-beginning 2) (match-end 2)))
  292.       nodename (substring nodename (match-beginning 3) (match-end 3)))
  293.     (let ((trim (string-match "\\s *\\'" filename)))
  294.       (if trim (setq filename (substring filename 0 trim))))
  295.     (let ((trim (string-match "\\s *\\'" nodename)))
  296.       (if trim (setq nodename (substring nodename 0 trim))))
  297.     (Info-find-node (if (equal filename "") nil filename)
  298.             (if (equal nodename "") "Top" nodename))))
  299.  
  300. (defvar Info-last-search nil
  301.   "Default regexp for Info S command to search for.")
  302.  
  303. (defun Info-search (regexp)
  304.   "Search for REGEXP, starting from point, and select node it's found in."
  305.   (interactive "sSearch (regexp): ")
  306.   (if (equal regexp "")
  307.       (setq regexp Info-last-search)
  308.     (setq Info-last-search regexp))
  309.   (let ((found ()) current
  310.     (onode Info-current-node)
  311.     (ofile Info-current-file)
  312.     (opoint (point))
  313.     (osubfile Info-current-subfile))
  314.     (save-excursion
  315.       (save-restriction
  316.     (widen)
  317.     (if (null Info-current-subfile)
  318.         (progn (re-search-forward regexp) (setq found (point)))
  319.       (condition-case err
  320.           (progn (re-search-forward regexp) (setq found (point)))
  321.         (search-failed nil)))))
  322.     (if (not found) ;can only happen in subfile case -- else would have erred
  323.     (unwind-protect
  324.         (let ((list ()))
  325.           (set-buffer (marker-buffer Info-tag-table-marker))
  326.           (goto-char (point-min))
  327.           (search-forward "\n\^_\nIndirect:")
  328.           (save-restriction
  329.         (narrow-to-region (point)
  330.                   (progn (search-forward "\n\^_")
  331.                      (1- (point))))
  332.         (goto-char (point-min))
  333.         (search-forward (concat "\n" osubfile ": "))
  334.         (beginning-of-line)
  335.         (while (not (eobp))
  336.           (re-search-forward "\\(^.*\\): [0-9]+$")
  337.           (goto-char (+ (match-end 1) 2))
  338.           (setq list (cons (cons (read (current-buffer))
  339.                      (buffer-substring (match-beginning 1)
  340.                                (match-end 1)))
  341.                    list))
  342.           (goto-char (1+ (match-end 0))))
  343.         (setq list (nreverse list)
  344.               current (car (car list))
  345.               list (cdr list)))
  346.           (while list
  347.         (message "Searching subfile %s..." (cdr (car list)))
  348.         (Info-read-subfile (car (car list)))
  349.         (setq list (cdr list))
  350.         (goto-char (point-min))
  351.         (if (re-search-forward regexp nil t)
  352.             (setq found (point) list ())))
  353.           (if found
  354.           (message "")
  355.         (signal 'search-failed (list regexp))))
  356.       (if (not found)
  357.           (progn (Info-read-subfile opoint)
  358.              (goto-char opoint)
  359.              (Info-select-node)))))
  360.     (widen)
  361.     (goto-char found)
  362.     (Info-select-node)
  363.     (or (and (equal onode Info-current-node)
  364.          (equal ofile Info-current-file))
  365.     (setq Info-history (cons (list ofile onode opoint)
  366.                  Info-history)))))
  367.  
  368. (defun Info-extract-pointer (name &optional errorname)
  369.   (save-excursion
  370.    (goto-char (point-min))
  371.    (forward-line 1)
  372.    (if (re-search-backward (concat name ":") nil t)
  373.        nil
  374.      (error (concat "Node has no " (capitalize (or errorname name)))))
  375.    (goto-char (match-end 0))
  376.    (Info-following-node-name)))
  377.  
  378. (defun Info-following-node-name (&optional allowedchars)
  379.   (skip-chars-forward " \t")
  380.   (buffer-substring
  381.    (point)
  382.    (progn
  383.      (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
  384.        (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
  385.        (if (looking-at "(")
  386.        (skip-chars-forward "^)")))
  387.      (skip-chars-backward " ")
  388.      (point))))
  389.  
  390. (defun Info-next ()
  391.   "Go to the next node of this node."
  392.   (interactive)
  393.   (Info-goto-node (Info-extract-pointer "next")))
  394.  
  395. (defun Info-prev ()
  396.   "Go to the previous node of this node."
  397.   (interactive)
  398.   (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
  399.  
  400. (defun Info-up ()
  401.   "Go to the superior node of this node."
  402.   (interactive)
  403.   (Info-goto-node (Info-extract-pointer "up")))
  404.  
  405. (defun Info-last ()
  406.   "Go back to the last node visited."
  407.   (interactive)
  408.   (or Info-history
  409.       (error "This is the first Info node you looked at"))
  410.   (let (filename nodename opoint)
  411.     (setq filename (car (car Info-history)))
  412.     (setq nodename (car (cdr (car Info-history))))
  413.     (setq opoint (car (cdr (cdr (car Info-history)))))
  414.     (setq Info-history (cdr Info-history))
  415.     (Info-find-node filename nodename)
  416.     (setq Info-history (cdr Info-history))
  417.     (goto-char opoint)))
  418.  
  419. (defun Info-directory ()
  420.   "Go to the Info directory node."
  421.   (interactive)
  422.   (Info-find-node "dir" "top"))
  423.  
  424. (defun Info-follow-reference (footnotename)
  425.   "Follow cross reference named NAME to the node it refers to.
  426. NAME may be an abbreviation of the reference name."
  427.   (interactive
  428.    (let ((completion-ignore-case t)
  429.      completions default (start-point (point)) str i)
  430.      (save-excursion
  431.        (goto-char (point-min))
  432.        (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
  433.      (setq str (buffer-substring
  434.             (match-beginning 1)
  435.             (1- (point))))
  436.      ;; See if this one should be the default.
  437.      (and (null default)
  438.           (< (match-beginning 0) start-point)
  439.           (<= start-point (point))
  440.           (setq default t))
  441.      (setq i 0)
  442.      (while (setq i (string-match "[ \n\t]+" str i))
  443.        (setq str (concat (substring str 0 i) " "
  444.                  (substring str (match-end 0))))
  445.        (setq i (1+ i)))
  446.      ;; Record as a completion and perhaps as default.
  447.      (if (eq default t) (setq default str))
  448.      (setq completions
  449.            (cons (cons str nil)
  450.              completions))))
  451.      (if completions
  452.      (list (completing-read (if default
  453.                     (concat "Follow reference named: ("
  454.                         default ") ")
  455.                   "Follow reference named: ")
  456.                 completions nil t))
  457.        (error "No cross-references in this node"))))
  458.   (let (target beg i (str (concat "\\*note " footnotename)))
  459.     (while (setq i (string-match " " str i))
  460.       (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
  461.       (setq i (+ i 6)))
  462.     (save-excursion
  463.       (goto-char (point-min))
  464.       (or (re-search-forward str nil t)
  465.       (error "No cross-reference named %s" footnotename))
  466.       (goto-char (+ (match-beginning 0) 5))
  467.       (setq target (Info-extract-menu-node-name "Bad format cross reference")))
  468.     (while (setq i (string-match "[ \t\n]+" target i))
  469.       (setq target (concat (substring target 0 i) " "
  470.                (substring target (match-end 0))))
  471.       (setq i (+ i 1)))
  472.     (Info-goto-node target)))
  473.  
  474. (defun Info-extract-menu-node-name (&optional errmessage)
  475.   (skip-chars-forward " \t\n")
  476.   (let ((beg (point))
  477.     str i)
  478.     (skip-chars-forward "^:")
  479.     (forward-char 1)
  480.     (setq str
  481.       (if (looking-at ":")
  482.           (buffer-substring beg (1- (point)))
  483.         (Info-following-node-name "^.,\t\n")))
  484.     (while (setq i (string-match "\n" str i))
  485.       (aset str i ?\ ))
  486.     str))
  487.  
  488. (defun Info-menu (menu-item)
  489.   "Go to node for menu item named (or abbreviated) NAME.
  490. Completion is allowed, and the menu item point is on is the default."
  491.   (interactive
  492.    (let ((completions '())
  493.      ;; If point is within a menu item, use that item as the default
  494.      (default nil)
  495.      (p (point))
  496.      (last nil))
  497.      (save-excursion
  498.        (goto-char (point-min))
  499.        (if (not (search-forward "\n* menu:" nil t))
  500.        (error "No menu in this node"))
  501.        (while (re-search-forward
  502.         "\n\\* \\([^:\t\n]*\\):" nil t)
  503.      (if (and (null default)
  504.           (prog1 (if last (< last p) nil)
  505.             (setq last (match-beginning 0)))
  506.           (<= p last))
  507.          (setq default (car (car completions))))
  508.      (setq completions (cons (cons (buffer-substring
  509.                      (match-beginning 1)
  510.                      (match-end 1))
  511.                        (match-beginning 1))
  512.                  completions)))
  513.        (if (and (null default) last
  514.         (< last p)
  515.         (<= p (progn (end-of-line) (point))))
  516.        (setq default (car (car completions)))))
  517.      (let ((item nil))
  518.        (while (null item)
  519.      (setq item (let ((completion-ignore-case t))
  520.               (completing-read (if default
  521.                        (format "Menu item (default %s): "
  522.                            default)
  523.                        "Menu item: ")
  524.                        completions nil t)))
  525.      ;; we rely on the bug (which RMS won't change for his own reasons)
  526.      ;; that ;; completing-read accepts an input of "" even when the
  527.      ;; require-match argument is true and "" is not a valid possibility
  528.      (if (string= item "")
  529.          (if default
  530.          (setq item default)
  531.              ;; ask again
  532.              (setq item nil))))
  533.        (list item))))
  534.   (Info-goto-node (Info-extract-menu-item menu-item)))
  535.   
  536. (defun Info-extract-menu-item (menu-item)
  537.   (save-excursion
  538.     (goto-char (point-min))
  539.     (or (search-forward "\n* menu:" nil t)
  540.     (error "No menu in this node"))
  541.     (or (search-forward (concat "\n* " menu-item ":") nil t)
  542.     (search-forward (concat "\n* " menu-item) nil t)
  543.     (error "No such item in menu"))
  544.     (beginning-of-line)
  545.     (forward-char 2)
  546.     (Info-extract-menu-node-name)))
  547.  
  548. (defun Info-extract-menu-counting (count)
  549.   (save-excursion
  550.     (goto-char (point-min))
  551.     (or (search-forward "\n* menu:" nil t)
  552.     (error "No menu in this node"))
  553.     (or (search-forward "\n* " nil t count)
  554.     (error "Too few items in menu"))
  555.     (Info-extract-menu-node-name)))
  556.  
  557. (defun Info-first-menu-item ()
  558.   "Go to the node of the first menu item."
  559.   (interactive)
  560.   (Info-goto-node (Info-extract-menu-counting 1)))
  561.  
  562. (defun Info-second-menu-item ()
  563.   "Go to the node of the second menu item."
  564.   (interactive)
  565.   (Info-goto-node (Info-extract-menu-counting 2)))
  566.  
  567. (defun Info-third-menu-item ()
  568.   "Go to the node of the third menu item."
  569.   (interactive)
  570.   (Info-goto-node (Info-extract-menu-counting 3)))
  571.  
  572. (defun Info-fourth-menu-item ()
  573.   "Go to the node of the fourth menu item."
  574.   (interactive)
  575.   (Info-goto-node (Info-extract-menu-counting 4)))
  576.  
  577. (defun Info-fifth-menu-item ()
  578.   "Go to the node of the fifth menu item."
  579.   (interactive)
  580.   (Info-goto-node (Info-extract-menu-counting 5)))
  581.  
  582. (defun Info-exit ()
  583.   "Exit Info by selecting some other buffer."
  584.   (interactive)
  585.   (switch-to-buffer (prog1 (other-buffer (current-buffer))
  586.                (bury-buffer (current-buffer)))))
  587.  
  588. (defun Info-undefined ()
  589.   "Make command be undefined in Info."
  590.   (interactive)
  591.   (ding))
  592.  
  593. (defun Info-help ()
  594.   "Enter the Info tutorial."
  595.   (interactive)
  596.   (Info-find-node "info"
  597.           (if (< (window-height) 23)
  598.               "Help-Small-Screen"
  599.             "Help")))
  600.  
  601. (defun Info-summary ()
  602.   "Display a brief summary of all Info commands."
  603.   (interactive)
  604.   (save-window-excursion
  605.     (switch-to-buffer "*Help*")
  606.     (erase-buffer)
  607.     (insert (documentation 'Info-mode))
  608.     (goto-char (point-min))
  609.     (let (ch flag
  610.       (event (allocate-event)))
  611.       (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
  612.             (message (if flag "Type Space to see more"
  613.                    "Type Space to return to Info"))
  614.             (setq ch (event-to-character (next-command-event event)))
  615.             (if (/= ?\  ch)
  616.             (progn (setq unread-command-event event) nil)
  617.               flag))
  618.     (scroll-up)))))
  619.  
  620. (defun Info-get-token (pos start all &optional errorstring)
  621.   "Return the token around POS,
  622. POS must be somewhere inside the token
  623. START is a regular expression which will match the
  624.     beginning of the tokens delimited string
  625. ALL is a regular expression with a single
  626.     parenthized subpattern which is the token to be
  627.     returned. E.g. '{\(.*\)}' would return any string
  628.     enclosed in braces around POS.
  629. SIG optional fourth argument, controls action on no match
  630.     nil: return nil
  631.     t: beep
  632.     a string: signal an error, using that string."
  633.   (save-excursion
  634.     (goto-char pos)
  635.     (re-search-backward start (max (point-min) (- pos 200)) 'yes)
  636.     (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
  637.         (not (and (<= (match-beginning 0) pos)
  638.               (> (match-end 0) pos)))))
  639.     (if (and (<= (match-beginning 0) pos)
  640.          (> (match-end 0) pos))
  641.     (buffer-substring (match-beginning 1) (match-end 1))
  642.       (cond ((null errorstring)
  643.          nil)
  644.         ((eq errorstring t)
  645.          (beep)
  646.          nil)
  647.         (t
  648.          (error "No %s around position %d" errorstring pos))))))
  649.  
  650. (defun Info-follow-nearest-node (event)
  651.   "Follow a node reference near point.  Like M, F, N, P or U command.
  652. At end of the node's text, moves to the next node."
  653.   (interactive "@e")
  654.   (mouse-set-point event)
  655.   (let (node)
  656.     (cond
  657.      ((setq node (Info-get-token (point) "\\*note " "\\*note \\([^:]*\\):" t))
  658.       (Info-follow-reference node))
  659.      ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::" t))
  660.       (Info-goto-node node))
  661.      ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):" t))
  662.       (Info-menu node))
  663.      ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)" t))
  664.       (Info-goto-node node))
  665.      ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)" t))
  666.       (Info-goto-node node))
  667.      ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)" t))
  668.       (Info-goto-node "Top"))
  669.      ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)" t))
  670.       (Info-goto-node node))
  671.      ((save-excursion (forward-line 1) (eobp))
  672.       (Info-next)))
  673.     ))
  674.  
  675. (defvar Info-mode-map nil
  676.   "Keymap containing Info commands.")
  677. (if Info-mode-map
  678.     nil
  679.   (setq Info-mode-map (make-keymap))
  680.   (suppress-keymap Info-mode-map)
  681.   (define-key Info-mode-map "." 'beginning-of-buffer)
  682.   (define-key Info-mode-map " " 'scroll-up)
  683.   (define-key Info-mode-map "1" 'Info-first-menu-item)
  684.   (define-key Info-mode-map "2" 'Info-second-menu-item)
  685.   (define-key Info-mode-map "3" 'Info-third-menu-item)
  686.   (define-key Info-mode-map "4" 'Info-fourth-menu-item)
  687.   (define-key Info-mode-map "5" 'Info-fifth-menu-item)
  688.   (define-key Info-mode-map "6" 'undefined)
  689.   (define-key Info-mode-map "7" 'undefined)
  690.   (define-key Info-mode-map "8" 'undefined)
  691.   (define-key Info-mode-map "9" 'undefined)
  692.   (define-key Info-mode-map "0" 'undefined)
  693.   (define-key Info-mode-map "?" 'Info-summary)
  694.   (define-key Info-mode-map "b" 'beginning-of-buffer)
  695.   (define-key Info-mode-map "d" 'Info-directory)
  696.   (define-key Info-mode-map "e" 'Info-edit)
  697.   (define-key Info-mode-map "f" 'Info-follow-reference)
  698.   (define-key Info-mode-map "g" 'Info-goto-node)
  699.   (define-key Info-mode-map "h" 'Info-help)
  700.   (define-key Info-mode-map "l" 'Info-last)
  701.   (define-key Info-mode-map "m" 'Info-menu)
  702.   (define-key Info-mode-map "n" 'Info-next)
  703.   (define-key Info-mode-map "p" 'Info-prev)
  704.   (define-key Info-mode-map "q" 'Info-exit)
  705.   (define-key Info-mode-map "s" 'Info-search)
  706.   (define-key Info-mode-map "u" 'Info-up)
  707.   (define-key Info-mode-map "\177" 'scroll-down)
  708.  
  709.   ;;(define-key Info-mode-map 'button1 'mouse-scroll-up-full)
  710.   ;;(define-key Info-mode-map 'button2 'Info-follow-nearest-node)
  711.   ;;(define-key Info-mode-map 'button3 'mouse-scroll-down-full)
  712.  
  713.   (define-key Info-mode-map 'button2 'Info-follow-indicated-node)
  714.   (define-key Info-mode-map 'button3 'Info-select-node-menu)
  715.   )
  716.  
  717. ;; Info mode is suitable only for specially formatted data.
  718. (put 'info-mode 'mode-class 'special)
  719.  
  720. (defun Info-mode ()
  721.   "Info mode provides commands for browsing through the Info documentation tree.
  722. Documentation in Info is divided into \"nodes\", each of which
  723. discusses one topic and contains references to other nodes
  724. which discuss related topics.  Info has commands to follow
  725. the references and show you other nodes.
  726.  
  727. h    Invoke the Info tutorial.
  728.  
  729. Selecting other nodes:
  730. n    Move to the \"next\" node of this node.
  731. p    Move to the \"previous\" node of this node.
  732. u    Move \"up\" from this node.
  733. m    Pick menu item specified by name (or abbreviation).
  734.     Picking a menu item causes another node to be selected.
  735. f    Follow a cross reference.  Reads name of reference.
  736. l    Move to the last node you were at.
  737.  
  738. Moving within a node:
  739. Space    scroll forward a full screen.     DEL  scroll backward.
  740. b    Go to beginning of node.
  741.  
  742. Mouse commands:
  743. Left Button    Set point
  744. Middle Button    Click on a highlighted node reference to go to it
  745. Right Button    Pop up a menu of applicable Info commands
  746.  
  747. Advanced commands:
  748. q    Quit Info: reselect previously selected buffer.
  749. e    Edit contents of selected node.
  750. 1    Pick first item in node's menu.
  751. 2, 3, 4, 5   Pick second ... fifth item in node's menu.
  752. g    Move to node specified by name.
  753.     You may include a filename as well, as (FILENAME)NODENAME.
  754. s    Search through this Info file for specified regexp,
  755.     and select the node in which the next occurrence is found."
  756.   (kill-all-local-variables)
  757.   (setq major-mode 'Info-mode)
  758.   (setq mode-name "Info")
  759.   (use-local-map Info-mode-map)
  760.   (set-syntax-table text-mode-syntax-table)
  761.   (setq local-abbrev-table text-mode-abbrev-table)
  762.   (setq case-fold-search t)
  763.   (setq buffer-read-only t)
  764.   (make-local-variable 'Info-current-file)
  765.   (make-local-variable 'Info-current-subfile)
  766.   (make-local-variable 'Info-current-node)
  767.   (make-local-variable 'Info-tag-table-marker)
  768.   (make-local-variable 'Info-history)
  769.   (Info-set-mode-line)
  770.   (run-hooks 'Info-mode-hook))
  771.  
  772. (defvar Info-edit-map nil
  773.   "Local keymap used within `e' command of Info.")
  774. (if Info-edit-map
  775.     nil
  776.   (setq Info-edit-map (make-sparse-keymap))
  777.   (set-keymap-parent Info-edit-map text-mode-map)
  778.   (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
  779.  
  780. ;; Info-edit mode is suitable only for specially formatted data.
  781. (put 'info-edit-mode 'mode-class 'special)
  782.  
  783. (defun Info-edit-mode ()
  784.   "Major mode for editing the contents of an Info node.
  785. Like text mode with the addition of Info-cease-edit
  786. which returns to Info mode for browsing.
  787. \\{Info-edit-map}"
  788.   )
  789.  
  790. (defun Info-edit ()
  791.   "Edit the contents of this Info node.
  792. Allowed only if variable Info-enable-edit is non-nil."
  793.   (interactive)
  794.   (or Info-enable-edit
  795.       (error "Editing info nodes is not enabled"))
  796.   (use-local-map Info-edit-map)
  797.   (setq major-mode 'Info-edit-mode)
  798.   (setq mode-name "Info Edit")
  799.   (kill-local-variable 'mode-line-buffer-identification)
  800.   (setq buffer-read-only nil)
  801.   ;; Make mode line update.
  802.   (set-buffer-modified-p (buffer-modified-p))
  803.   (message (substitute-command-keys
  804.          "Editing: Type \\[Info-cease-edit] to return to info")))
  805.  
  806. (defun Info-cease-edit ()
  807.   "Finish editing Info node; switch back to Info proper."
  808.   (interactive)
  809.   ;; Do this first, so nothing has changed if user C-g's at query.
  810.   (and (buffer-modified-p)
  811.        (y-or-n-p "Save the file? ")
  812.        (save-buffer))
  813.   (use-local-map Info-mode-map)
  814.   (setq major-mode 'Info-mode)
  815.   (setq mode-name "Info")
  816.   (Info-set-mode-line)
  817.   (setq buffer-read-only t)
  818.   ;; Make mode line update.
  819.   (set-buffer-modified-p (buffer-modified-p))
  820.   (and (marker-position Info-tag-table-marker)
  821.        (buffer-modified-p)
  822.        (message "Tags may have changed.  Use Info-tagify if necessary")))
  823.  
  824.  
  825. ;;; fontification and mousability
  826.  
  827. (defvar Info-fontify t)
  828.  
  829. (defvar Info-faces-initted nil)
  830. (defun Info-init-faces ()
  831.   (if Info-faces-initted
  832.       nil
  833.     (or (find-face 'info-node) (make-face 'info-node))
  834.     (or (find-face 'info-xref) (make-face 'info-xref))
  835.     (or (face-differs-from-default-p 'info-node (selected-screen))
  836.     (copy-face 'bold-italic 'info-node (selected-screen)))
  837.     (or (face-differs-from-default-p 'info-xref (selected-screen))
  838.     (copy-face 'bold 'info-xref (selected-screen)))
  839.     (setq Info-faces-initted t)))
  840.  
  841. (defun Info-fontify-node ()
  842.   (Info-init-faces)
  843.   (if Info-fontify
  844.       (save-excursion
  845.     (map-extents (function (lambda (x y)
  846.                  (if (eq (extent-data x) 'info)
  847.                      (delete-extent x))))
  848.              (current-buffer) (point-min) (point-max) nil)
  849.     (let ((case-fold-search t)
  850.           extent)
  851.       (goto-char (point-min))
  852.       (if (looking-at "^File: [^,: \t]+,?[ \t]+")
  853.           (progn
  854.         (goto-char (match-end 0))
  855.         (while
  856.             (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
  857.           (goto-char (match-end 0))
  858.           (setq extent (make-extent (match-beginning 1) (match-end 1)))
  859.           (set-extent-face extent 'info-xref)
  860.           (set-extent-data extent 'info)
  861.           (set-extent-attribute extent 'highlight))))
  862.       (goto-char (point-min))
  863.       (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
  864.         (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
  865.         nil
  866.           (setq extent (make-extent (match-beginning 0) (match-end 1)))
  867.           (set-extent-face extent 'info-xref)
  868.           (set-extent-data extent 'info)
  869.           (set-extent-attribute extent 'highlight)))
  870.       (goto-char (point-min))
  871.       (if (search-forward "\n* menu:" nil t)
  872.           (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
  873.         (setq extent (make-extent (match-beginning 0) (match-end 1)))
  874.         (set-extent-face extent 'info-node)
  875.         (set-extent-data extent 'info)
  876.         (set-extent-attribute extent 'highlight)))))))
  877.  
  878. (defun Info-indicated-node (event)
  879.   (save-window-excursion
  880.     (save-excursion
  881.       (mouse-set-point event)
  882.       (let* ((buffer (window-buffer (event-window event)))
  883.          (p (event-point event))
  884.          (extent (and p (extent-at p buffer 'highlight)))
  885.          (text (and extent
  886.             (save-excursion
  887.               (set-buffer buffer)
  888.               (buffer-substring
  889.                (extent-start-position extent)
  890.                (extent-end-position extent)))))
  891.          (case-fold-search t)
  892.          i)
  893.     (cond ((null extent)
  894.            nil)
  895.           ((string-match "\\`\\*note[ \n\t]*\\([^:]*\\):?\\'" text)
  896.            ;; it's a cross-reference
  897.            (setq text (substring text (match-beginning 1) (match-end 1)))
  898.            (while (setq i (string-match "[ \n\t]+" text i))
  899.          (setq text (concat (substring text 0 i) " "
  900.                     (substring text (match-end 0))))
  901.          (setq i (1+ i)))
  902.            (list 'Info-follow-reference text))
  903.           ((and (save-excursion (goto-char (extent-start-position extent))
  904.                     (= ?\n (preceding-char)))
  905.             (string-match "\\`\\* \\([^:\t\n]+\\):?\\'" text))
  906.            ;; it's a menu entry
  907.            (setq text (substring text (match-beginning 1) (match-end 1)))
  908.            (list 'Info-menu text))
  909.           (t
  910.            ;; otherwise, it must be a node-name in the first line
  911.            (list 'Info-goto-node text)))))))
  912.  
  913.  
  914. (defun Info-follow-indicated-node (event)
  915.   "Follow the crossreference or menu item at the click-location."
  916.   (interactive "e")
  917.   (mouse-set-point event)
  918.   (eval (or (Info-indicated-node event)
  919.         (error "click on a cross-reference to follow"))))
  920.  
  921.  
  922. (defun Info-select-node-menu (event)
  923.   "Pops up a menu of applicable Info commands."
  924.   (interactive "e")
  925.   (select-window (event-window event))
  926.   (let ((case-fold-search t)
  927.     up-p prev-p next-p menu
  928.     i text xrefs subnodes in)
  929.     (save-excursion
  930.       (goto-char (point-min))
  931.       (if (looking-at ".*\\bNext:") (setq next-p t))
  932.       (if (looking-at ".*\\bPrev:") (setq prev-p t))
  933.       (if (looking-at ".*Up:") (setq up-p t))
  934.       (setq menu (nconc (list "Info" "Info Commands:" "----")
  935.             (if (setq in (Info-indicated-node event))
  936.                 (list (vector (car (cdr in)) in t)))
  937.             (list
  938.              ["Goto Info Top-level" Info-directory t]
  939.              (vector "Next Node" 'Info-next next-p)
  940.              (vector "Previous Node" 'Info-prev prev-p)
  941.              (vector "Parent Node (Up)" 'Info-up up-p)
  942.              ["Goto Node..." Info-goto-node t]
  943.              ["Goto Last Visited Node" Info-last t]
  944.              "----"
  945.              '("Bookmark"
  946.                ["Set bookmark..." Info-bookmark-set t]
  947.                ["Jump bookmark..." Info-bookmark-jump t]
  948.                ["Delete bookmark..." Info-bookmark-delete t]
  949.                ["Reset bookmark list..." Info-bookmark-revert t]
  950.                ["Write bookmark list..." Info-bookmark-write t]
  951.                ["Load bookmark list..." Info-bookmark-load t]
  952.                )
  953.              )))
  954.       (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
  955.     (setq text (buffer-substring (match-beginning 1) (match-end 1)))
  956.     (while (setq i (string-match "[ \n\t]+" text i))
  957.       (setq text (concat (substring text 0 i) " "
  958.                  (substring text (match-end 0))))
  959.       (setq i (1+ i)))
  960.     (setq xrefs (cons text xrefs)))
  961.       (setq xrefs (nreverse xrefs))
  962.       (goto-char (point-min))
  963.       (if (search-forward "\n* menu:" nil t)
  964.       (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
  965.         (setq text (buffer-substring (match-beginning 1) (match-end 1)))
  966.         (setq subnodes (cons text subnodes))))
  967.       (setq subnodes (nreverse subnodes)))
  968.     (if (or xrefs subnodes)
  969.     (nconc menu (list "-----")))
  970.     (if xrefs
  971.     (nconc menu
  972.            (list
  973.         (apply 'list "Cross-References"
  974.                (mapcar '(lambda (xref)
  975.                   (vector xref
  976.                       (list 'Info-follow-reference xref)
  977.                       t))
  978.                    xrefs)))))
  979.     (if subnodes
  980.     (nconc menu
  981.            (list
  982.         (apply 'list "Sub-Nodes"
  983.                (mapcar '(lambda (node)
  984.                   (vector node (list 'Info-menu node) t))
  985.                    subnodes)))))
  986.     (popup-menu menu)))
  987. - - - cut here - - -
  988.  
  989.  
  990. Heiko
  991.  
  992.  
  993. PS: I think this file (or somethink similar) and the file 
  994.     info-bookmark.el should be in the next lemacs versions,
  995.     because they serve very helpfull features for the Info
  996.     mode, that I've missed in the past.
  997. --
  998. ________________________________________________________________________________
  999.  
  1000. Dipl.-Ing. Heiko Muenkel           Universitaet Hannover
  1001.                    Institut fuer Theoretische Nachrichtentechnik
  1002.                    und Informationsverarbeitung
  1003. muenkel@tnt.uni-hannover.de        Appelstrasse 9A
  1004. fax:    +49-511-762-5333           D-3000 Hannover 1
  1005. phone:  +49-511-762-5323           Germany
  1006. ________________________________________________________________________________
  1007.  
  1008.