home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / LaTeXinfo.shar.2 / get-node.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  2.3 KB  |  77 lines

  1. (define-key help-map "g" 'get-latexinfo-node)
  2.  
  3. (defun get-latexinfo-node (string)
  4.   (interactive "sDescribe Latexinfo Topic: ")
  5.   (let* ((info-file-name
  6.       (save-excursion
  7.         (set-buffer "*info*")
  8.         (buffer-file-name)))
  9.      (index-file-name
  10.       (concat
  11.        (substring info-file-name 0 (- (length info-file-name) 2))
  12.        "dex")))
  13.     (if (and (file-exists-p index-file-name)
  14.          (file-exists-p info-file-name))
  15.     (get-node index-file-name info-file-name string)
  16.       (error "File(s) not found! \n  %s \n  %s"
  17.          index-file-name info-file-name
  18.          ))))
  19.  
  20. (require 'info)
  21. ;;(autoload 'Info-find-node "info" )
  22.  
  23. (defun get-node (index-file manual-file string)
  24.   (interactive "fIndex File Name; \nfManual File Name; \nsTopic: ")
  25.     (let ((byte) (index-buffer))
  26.       (save-excursion
  27.     (find-file index-file)
  28.     (setq index-buffer (current-buffer))
  29.     (goto-char (point-min))
  30.     (binary-search-forward string)
  31.           (setq byte (read (current-buffer))))
  32.       (setq manual-file
  33.         (expand-file-name manual-file))
  34.       (find-file manual-file)
  35.       (save-excursion
  36.     (widen)
  37.     (goto-char byte)
  38.     ;; Find beginning of node.
  39.     (search-backward "\n\^_")
  40.     (forward-line 2)
  41.     ;; Get nodename spelled as it is in the node.
  42.     (re-search-forward "Node:[ \t]*")
  43.     (setq Info-current-node
  44.           (buffer-substring (point)
  45.                 (progn
  46.                   (skip-chars-forward "^,\t\n")
  47.                   (point)))))
  48.       (message "Node: %s File: %s"
  49.         Info-current-node manual-file)
  50.    (Info-find-node manual-file Info-current-node)
  51.    (bury-buffer index-buffer)
  52.    (goto-char byte)))
  53.  
  54. (defvar *binary-search-limit* 300
  55.   "The point of diminuishing returns for a binary-search.")
  56.  
  57. (defun binary-search-forward (string)
  58.   "Search for the string STRING in the current buffer using a binary search"
  59.   (setq string (concat "\"" string "\""))
  60.   (if (< (point-max) *binary-search-limit*)
  61.           (re-search-forward (concat "^" (regexp-quote string)))
  62.       (setq string (concat string " "))
  63.       (let* ((hi (point-max))
  64.          (lo (point-min))
  65.          (mid (/ (+ hi lo) 2))
  66.          (len (length string)))
  67.     (while (>= (- hi lo) *binary-search-limit*)
  68.       (goto-char mid)
  69.       (forward-line 1)
  70.       (if (string< (buffer-substring (point) (+ (point) len)) string)
  71.           (setq lo mid)
  72.         (setq hi mid))
  73.       (setq mid (/ (+ hi lo) 2)))
  74.     (goto-char lo)
  75.     (re-search-forward (concat "^" (regexp-quote string))))))
  76.  
  77.