[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

;;; tooltip-at-point-elisp.el --- elisp support for tooltip doc lookup

From: Kevin A. Burton (burtonator)
Subject: ;;; tooltip-at-point-elisp.el --- elisp support for tooltip doc lookup
Date: 18 Dec 2002 16:14:36 -0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2.90

Hash: SHA1

;;; tooltip-at-point-elisp.el --- elisp support for tooltip doc lookup

;; $Id: tooltip-at-point-elisp.el,v 1.4 2002/12/08 03:01:21 burton Exp $

;; Copyright (C) 2000-2003 Free Software Foundation, Inc.
;; Copyright (C) 2000-2003 Kevin A. Burton (address@hidden)

;; Author: Kevin A. Burton (address@hidden)
;; Maintainer: Kevin A. Burton (address@hidden)
;; Location:
;; Keywords: 
;; Version: 1.0.0

;; This file is [not yet] part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free Software
;; Foundation; either version 2 of the License, or any later version.
;; This program is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
;; details.
;; You should have received a copy of the GNU General Public License along with
;; this program; if not, write to the Free Software Foundation, Inc., 59 Temple
;; Place - Suite 330, Boston, MA 02111-1307, USA.

;;; Commentary:

;; This package provides tooltip-at-point functionality for Emacs Lisp.  It used
;; the describe-X functions and analyzes the current (point) to determine the
;; most appropriate documentation to display.
;; See tooltip-at-point.el for more information. 

;; NOTE: If you enjoy this software, please consider a donation to the EFF
;; (

;;; TODO:
;; - Support for all describe-X functions (including the EIEIO describe-class
;; and describe-method too)

;;; Code:

(defun tooltip-at-point-elisp--get-documentation-function(function)
  "Get a string of documentation for the given function."

  (let((inhibit-read-only t)
       (result nil))

      ;;FIXME: describe-function-1 only works if this is the *Help* buffer but
      ;;we don't want to overwrite this for temp lookups
      (set-buffer (get-buffer-create "*Help*"))
      (let((standard-output (current-buffer)))
        (prin1 function)
        ;; Use " is " instead of a colon so that
        ;; it is easier to get out the function name using forward-sexp.
        (princ " is ")
        (describe-function-1 function nil (interactive-p)))
      (setq result (tooltip-at-point-elisp--get-documentation "function" 
      (kill-buffer (current-buffer))

(defun tooltip-at-point-elisp--get-documentation(type documentation)
  "Output the symbol and type and documentation formated."

   (let((header (concat type ": ")))
     (add-text-properties 0
                          (length header)
                          '(face bold)
     (concat header documentation)))
(defun tooltip-at-point-elisp--get-documentation-variable(variable)
  "Get a string of documentation for the given variable."

      ;;this is a hack to prevent the help enter message from being generated
      (switch-to-buffer (get-buffer-create "*Help*"))

      (tooltip-at-point-elisp--get-documentation "variable"
                                           (describe-variable variable)))))
(defun tooltip-at-point-elisp-documentation()
  "Show documentation for the given symbol at point."

   (let((function (function-called-at-point))
        (variable (variable-at-point))
        (function-begin 0)
        (variable-begin 0))

     ;;determine which is closer.. the defun or the variable
     (when function
         (when (search-backward (pp function) nil t)
           (setq function-begin (match-beginning 0)))))

     (when variable
         (when (search-backward (pp variable) nil t)
           (setq variable-begin (match-beginning 0)))))

     ;;now see which way to get the documentation

     (if (and variable
              (> variable-begin function-begin))
         (tooltip-at-point (tooltip-at-point-elisp--get-documentation-variable 
       (if (and function
                (> function-begin variable-begin))
(tooltip-at-point-elisp--get-documentation-function function))
         (error "No function or variable at point"))))))

(defmacro tooltip-at-point-elisp-documentation--with-protected-help-buffer 
(&rest body)
  "Rename the current help buffer, create a *new* help buffer, execute the body,
then restore the old help buffer."
           ;;delete Help.original if it exists (shouldn't)
           (when(get-buffer "*Help.original*")
             (kill-buffer (get-buffer "*Help.original*")))
           (set-buffer (get-buffer-create "*Help*"))
           (rename-buffer "*Help.original*"))

       ;;now kill the EXISTING help buffers.
       (when(get-buffer "*Help*")
         (kill-buffer (get-buffer "*Help*")))

       (set-buffer (get-buffer-create "*Help.original*"))
       (rename-buffer "*Help*"))))

(define-key emacs-lisp-mode-map "\C-c?" 'tooltip-at-point-elisp-documentation)
(define-key lisp-interaction-mode-map "\C-c?" 

;;support for apropos mode
(define-key apropos-mode-map "\C-c?" 'tooltip-at-point-elisp-documentation)

;; we would also this in help mode because there are often references we should
;; find here as well.

(define-key help-mode-map "\C-c?" 'tooltip-at-point-elisp-documentation)

(provide 'tooltip-at-point-elisp)

;;; tooltip-at-point-elisp.el ends 

- -- 
Kevin A. Burton ( address@hidden, address@hidden, address@hidden )
             Location - San Francisco, CA, Cell - 415.595.9965
        Jabber - address@hidden,  Web -
        GPG fingerprint: 4D20 40A0 C734 307E C7B4  DCAA 0303 3AC5 BD9D 7C4D
         IRC - #infoanarchy | #p2p-hackers | #reptile

It is error alone which needs support of the government.  Truth can stand by
itself.  --Thomas Jefferson

Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Get my public key at:


reply via email to

[Prev in Thread] Current Thread [Next in Thread]