gnu-emacs-sources
[Top][All Lists]
Advanced

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

;;; tooltip-at-point-jde.el --- tooltip support for the JDE and jde-doci


From: Kevin A. Burton (burtonator)
Subject: ;;; tooltip-at-point-jde.el --- tooltip support for the JDE and jde-docindex
Date: 18 Dec 2002 16:15:53 -0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2.90

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


;;; tooltip-at-point-jde.el --- tooltip support for the JDE and jde-docindex

;; $Id: tooltip-at-point-jde.el,v 1.5 2002/12/09 13:56:15 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: http://relativity.yi.org
;; 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:
;;
;; Provides tooltip-at-point support for Java and JDE.  Provides documentation
;; lookup and method completion.

;; NOTE: If you enjoy this software, please consider a donation to the EFF
;; (http://www.eff.org)

;;; TODO:

;;; Code:

(require 'jde)
(require 'jde-docindex)

(defun tooltip-at-point-jde()
  "Pop up a tooltip at the current point for the javadoc documentation."
  (interactive)

  (if (tap--jde-completion-p)
      (jde-complete-at-point-tooltip)
    (when (tap--jde-docindex-p)
      (let((token (tooltip-at-point--jde-docindex-find-token))
           (header nil))

        (setq header token)
        
        (add-text-properties 0 (length header)
                             '(face bold) header)

        (tooltip-at-point (concat header
                                  "\n"
                                  (jde-docindex-get-documentation token)))))))

(defun tooltip-at-point--jde-docindex-find-token()
  "Use the best method to find the documentation token.  This should throw an
error if nothing was found."
  (interactive)

  (let((class nil)
       (search nil))

    (setq search (match-string-no-properties 0))

    (when (or (null search)
              (string-equal "" search))
      (error "No class name at point"))
    
    (setq class (tooltip-at-point--jde-resolve-class search))
    
    (when (null class)
        (error "Class not found in docindex: %s" search))

    class))

(defun tap--jde-docindex-p()
  "Return non-nil if we should use jde-docindex at the current point."

  (save-excursion
    (let((case-fold-search nil))
      
      (when (re-search-backward " [A-Z]" (point-at-bol) t)
        (goto-char (1- (match-end 0))))
      
      (looking-at "\\([A-Z]+[a-z]+\\)*"))))
  
(defun tap--jde-completion-p()
  "Return non-nil if we should use method completion at the current point."

  ;;use completion if there is nothing on the entire line
  (if (string-match "^[ \t]*$" (buffer-substring (point-at-bol)
                                                 (point-at-eol)))
      t ;;true if there is nothing on the line
    (save-excursion
      (let((point (point)))

        (when (re-search-backward "\\.[a-zA-Z]*" (point-at-bol) t)
          (equal (match-end 0) point))))))

(defun tooltip-at-point--jde-resolve-class(class)
  "When given a class name (String, Long, etc) resolve it to a full class
 (example java.lang.String, java.lang.Long) based on what we have in
`jde-docindex-token-class-alist'"

  (let((imports (jde-import-get-imports))
       (index 0)
       (import nil)
       (match nil))

    (while (and (null match)
                (< index (length imports)))

      (setq import (nth index imports))

      ;;test for explicit import
      (when (and (string-match (concat class "$") import)
                 (assoc import jde-docindex-token-class-alist))
        ;;we found an explicit import
        (setq match import))

      (setq index (1+ index))

      ;;test for import by package...
      (when (and (null match)
                 (string-match (concat "\\.\\*$") import))
        (let((package (substring import 0 (match-beginning 0)))
             (fqcn nil))
          ;;now that we have the package of the current import see if we have a
          ;;package.class imprt

          (setq fqcn (concat package "." class))
          
          (when (assoc fqcn jde-docindex-token-class-alist)
            (setq match fqcn))))

      ;;test for implicit java.lang imports
      (when (and (null match)
                 (assoc (concat "java.lang." class) 
jde-docindex-token-class-alist))
        (setq match (concat "java.lang." class))))

    match))

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

(provide 'tooltip-at-point-jde)

;;; tooltip-at-point-jde.el ends here

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

Copyright, like patents, benefits only those who can enforce it.



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Get my public key at: http://relativity.yi.org/pgpkey.txt

iD8DBQE+AQ+5AwM6xb2dfE0RAlCTAJ9EX2Igmgd7BbWCekFyC0kXaaqXNQCggvni
WD2IMZ7mzKdMarIGFLNs8iM=
=7E8y
-----END PGP SIGNATURE-----



reply via email to

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