home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / hyperbole / hmous-info.el < prev    next >
Encoding:
Text File  |  1995-06-16  |  6.6 KB  |  213 lines

  1. ;;!emacs
  2. ;;
  3. ;; FILE:         hmous-info.el
  4. ;; SUMMARY:      Walks through Info networks using one key.
  5. ;; USAGE:        GNU Emacs Lisp Library
  6. ;; KEYWORDS:     docs, help, hypermedia, mouse
  7. ;;
  8. ;; AUTHOR:       Bob Weiner
  9. ;; ORIG-DATE:    04-Apr-89
  10. ;; LAST-MOD:     13-Jun-95 at 18:05:22 by Bob Weiner
  11. ;;
  12. ;; This file is for use with Hyperbole.
  13. ;;
  14. ;; Copyright (C) 1989, 1990, 1991  Free Software Foundation, Inc.
  15. ;; Available for use and distribution under the same terms as GNU Emacs.
  16. ;;
  17. ;;
  18. ;; DESCRIPTION:  
  19. ;;
  20. ;;  This code is machine independent.
  21. ;;
  22. ;;  To install:  See hui-mouse.el
  23. ;;
  24. ;; DESCRIP-END.
  25.  
  26. ;;;###autoload
  27. (defun smart-info ()
  28.   "Walks through Info documentation networks using one key or mouse key.
  29.  
  30. If key is pressed within:
  31.  (1) the first line of an Info Menu Entry or Cross Reference, the desired node
  32.        is found;
  33.  (2) the Up, Next, or Previous entries of a Node Header (first line),
  34.        the desired node is found;
  35.  (3) the File entry of a Node Header (first line),       
  36.        the 'Top' node within that file is found;
  37.  (4) at the end of the current node, the Next node is found (this will
  38.        descend subtrees if the function 'Info-global-next' is bound);
  39.  (5) anywhere else (e.g. at the end of a line), the current node entry is
  40.        scrolled up one windowful.
  41.  
  42. Returns t if key is pressed within an Info Node Header, Cross Reference,
  43. or a Menu; otherwise returns nil."
  44.  
  45.   (interactive)
  46.   (cond 
  47.     ;;
  48.     ;; If at end of node, go to next node
  49.     ;;
  50.     ((last-line-p)
  51.      (if (fboundp 'Info-global-next) (Info-global-next)
  52.        (Info-next)))
  53.     ((Info-handle-in-node-hdr))
  54.     ((Info-handle-in-note))
  55.     ((Info-handle-in-menu))
  56.     ((pos-visible-in-window-p (point-max))
  57.      (if (fboundp 'Info-global-next) (Info-global-next)
  58.        (Info-next)))
  59.     ;;
  60.     ;; If nothing else scroll forward a windowful.
  61.     ;;
  62.     ((scroll-up-eol))))
  63.  
  64. ;;;###autoload
  65. (defun smart-info-assist ()
  66.   "Walks through Info documentation networks using one assist-key or mouse assist-key.
  67.  
  68. If assist-key is pressed within:
  69.  (1) the first line of an Info Menu Entry or Cross Reference, the desired node
  70.        is found;
  71.  (2) the Up, Next, or Previous entries of a Node Header (first line),
  72.        the last node in the history list is found;
  73.  (3) the File entry of a Node Header (first line),       
  74.        the 'DIR' root-level node is found;
  75.  (4) at the end of the current node, the Previous node is found (this will
  76.        return from subtrees if the function 'Info-global-prev is bound);
  77.  (5) anywhere else (e.g. at the end of a line), the current node entry is
  78.        scrolled down one windowful.
  79.  
  80. Returns t if assist-key is pressed within an Info Node Header, Cross Reference,
  81. or a Menu; otherwise returns nil."
  82.  
  83.   (interactive)
  84.   (cond
  85.     ;;
  86.     ;; If at end or beginning of node, go to previous node
  87.     ;;
  88.     ((last-line-p)
  89.      (if (fboundp 'Info-global-prev) (Info-global-prev)
  90.        (Info-prev)))
  91.     ((Info-handle-in-node-hdr-assist))
  92.     ((Info-handle-in-note))
  93.     ((Info-handle-in-menu))
  94.     ((pos-visible-in-window-p (point-min))
  95.      (if (fboundp 'Info-global-prev) (Info-global-prev)
  96.        (Info-prev)))
  97.     ;;
  98.     ;; If anywhere else, scroll backward a windowful.
  99.     ;;
  100.     ((scroll-down-eol))))
  101.  
  102. (defun Info-handle-in-node-hdr ()
  103.   "If within an Info node header, move to <FILE>Top, <Up>, <Previous>, or
  104. <Next> node, depending on which label point is on, and return t.
  105. Otherwise, return nil."
  106.   ;;
  107.   ;; Test if on 1st line of node, i.e. node header
  108.   ;;
  109.   (if (not (first-line-p))
  110.       nil
  111.     (let ((nodename "Top") (filep nil))
  112.       (save-excursion
  113.     (if (and
  114.           (re-search-forward "[:, \t\n]" nil t)
  115.           (re-search-backward
  116.         "\\(File\\|Node\\|Up\\|Prev\\|Previous\\|Next\\):[ \t]" nil t))
  117.         (progn (setq filep (string-equal
  118.                  "file"
  119.                  (downcase (buffer-substring
  120.                          (match-beginning 1)
  121.                          (match-end 1)))))
  122.            (if (re-search-forward (concat ":[ \n]\\([^,\t\n"
  123.                           (if filep " ")
  124.                           "]*\\)") nil t)
  125.                (setq nodename (buffer-substring
  126.                     (match-beginning 1)
  127.                     (match-end 1)))))
  128.       (error "Node header not found.")))
  129.       (setq nodename
  130.         (cond ((= (aref nodename 0) ?\() nodename)
  131.           (filep (concat "(" nodename ")" "Top"))
  132.           (buffer-file-name (concat "(" buffer-file-name ")" nodename))
  133.           (t nodename)))
  134.       (Info-goto-node nodename nil t)
  135.       t)))
  136.  
  137. (defun Info-handle-in-node-hdr-assist ()
  138.   "If within an Info node header when the 'smart-info-assist' command is
  139. executed, when within the <FILE> header go to the DIR top-level node.  When
  140. within any other header (<Up>, <Previous>, or <Next>) go to last node from
  141. history list.  Return t if in Info node header.  Otherwise return nil."
  142.   ;;
  143.   ;; Test if on 1st line of node, i.e. node header
  144.   ;;
  145.   (if (not (first-line-p))
  146.       nil
  147.     (save-excursion
  148.       (if (and 
  149.         (re-search-forward "[:, \t\n]" nil t)
  150.         (re-search-backward
  151.           "\\(File\\|Node\\|Up\\|Prev\\|Previous\\|Next\\):[ \t]" nil t) )
  152.       ;; If in <FILE> hdr
  153.       (progn (if (string-equal
  154.                "file"
  155.                (downcase (buffer-substring
  156.                    (match-beginning 1)
  157.                    (match-end 1))))
  158.              (Info-directory)
  159.            (Info-last))
  160.          t)
  161.     (error "Node header not found.")
  162.     nil))))
  163.  
  164. ;;;###autoload
  165. (defun Info-handle-in-note ()
  166.   "Follows an Info cross-reference.
  167. If point is within the first line of an Info note (cross-reference), follows
  168. cross-reference and returns t; otherwise returns nil."
  169.   (let ((note-name) (opoint (point)))
  170.     (save-excursion
  171.       (skip-chars-forward "^:")
  172.       (if (and (re-search-backward
  173.         "\*\\(Ref\\|Note\\|See\\)\\([ \t\n]+\\|$\\)" nil t)
  174.            (looking-at "\*\\(Ref\\|Note\\|See\\)[ \t\n]+\\([^:]*\\):")
  175.            (<= (match-beginning 0) opoint)
  176.            (> (match-end 0) opoint))
  177.       ;; Remove newline and extra spaces from 'note-name'
  178.       (setq note-name (hypb:replace-match-string
  179.                "[ \n\t]+"
  180.                (buffer-substring
  181.                 (match-beginning 2) (match-end 2))
  182.                " "))))
  183.     (if note-name
  184.     (progn (Info-follow-reference note-name) t))))
  185.  
  186. (defun Info-handle-in-menu ()
  187.   "Displays node referred to by an Info Menu Entry.
  188. If point is within an Info menu entry, goes to node referenced by
  189. entry and returns t; otherwise returns nil."
  190.   ;;
  191.   ;; Test if there is a menu in this node
  192.   ;;
  193.   (let ((in-menu nil) (curr-point (point)))
  194.     (save-excursion
  195.       (goto-char (point-min))
  196.       (setq in-menu 
  197.         (and (search-forward "\n* menu:" nil t)
  198.          (< (point) curr-point))))
  199.     (if (not in-menu)
  200.     nil
  201.       (let ((node))
  202.     (save-excursion
  203.       (forward-char) ; Pass '*' char if point is in front of
  204.       (if (search-backward "\n*" nil t)
  205.           (progn (forward-char 2)
  206.              (setq node (Info-extract-menu-node-name)))))
  207.     (if (null node)
  208.         nil
  209.       (Info-goto-node node nil t)
  210.       t)))))
  211.  
  212. (provide 'hmous-info)
  213.