2008-12-20 19:43:28 -05:00
|
|
|
|
;;; fuel-xref.el -- showing cross-reference info
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
|
|
|
|
|
;; See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
|
|
|
|
|
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
|
|
|
|
|
;; Keywords: languages, fuel, factor
|
|
|
|
|
;; Start date: Sat Dec 20, 2008 22:00
|
|
|
|
|
|
|
|
|
|
;;; Comentary:
|
|
|
|
|
|
|
|
|
|
;; A mode and utilities for showing cross-reference information.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(require 'fuel-eval)
|
|
|
|
|
(require 'fuel-popup)
|
|
|
|
|
(require 'fuel-font-lock)
|
2008-12-20 19:43:28 -05:00
|
|
|
|
(require 'fuel-base)
|
|
|
|
|
|
|
|
|
|
(require 'button)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Customization:
|
|
|
|
|
|
|
|
|
|
(defgroup fuel-xref nil
|
|
|
|
|
"FUEL's cross-referencing engine."
|
|
|
|
|
:group 'fuel)
|
|
|
|
|
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(fuel-font-lock--defface fuel-font-lock-xref-link
|
|
|
|
|
'link fuel-xref "highlighting links in cross-reference buffers")
|
|
|
|
|
|
|
|
|
|
(fuel-font-lock--defface fuel-font-lock-xref-vocab
|
|
|
|
|
'italic fuel-xref "vocabulary names in cross-reference buffers")
|
|
|
|
|
|
2008-12-20 19:43:28 -05:00
|
|
|
|
|
|
|
|
|
;;; Buttons:
|
|
|
|
|
|
|
|
|
|
(define-button-type 'fuel-xref--button-type
|
|
|
|
|
'action 'fuel-xref--follow-link
|
|
|
|
|
'follow-link t
|
2008-12-21 11:33:53 -05:00
|
|
|
|
'face 'fuel-font-lock-xref-link)
|
2008-12-20 19:43:28 -05:00
|
|
|
|
|
|
|
|
|
(defun fuel-xref--follow-link (button)
|
|
|
|
|
(let ((file (button-get button 'file))
|
|
|
|
|
(line (button-get button 'line)))
|
|
|
|
|
(when (not file)
|
|
|
|
|
(error "No file for this ref"))
|
|
|
|
|
(when (not (file-readable-p file))
|
|
|
|
|
(error "File '%s' is not readable" file))
|
|
|
|
|
(find-file-other-window file)
|
|
|
|
|
(when (numberp line) (goto-line line))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; The xref buffer:
|
|
|
|
|
|
2008-12-21 10:04:39 -05:00
|
|
|
|
(fuel-popup--define fuel-xref--buffer
|
|
|
|
|
"*fuel xref*" 'fuel-xref-mode)
|
2008-12-20 19:43:28 -05:00
|
|
|
|
|
|
|
|
|
(defvar fuel-xref--help-string "(Press RET or click to follow crossrefs)")
|
|
|
|
|
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(defun fuel-xref--title (word cc count)
|
|
|
|
|
(cond ((zerop count) (format "No known words %s '%s'." cc word))
|
|
|
|
|
((= 1 count) (format "1 word %s '%s':" cc word))
|
|
|
|
|
(t (format "%s words %s '%s':" count cc word))))
|
|
|
|
|
|
|
|
|
|
(defun fuel-xref--fill-buffer (word cc refs)
|
|
|
|
|
(let ((inhibit-read-only t)
|
|
|
|
|
(count 0))
|
2008-12-21 10:04:39 -05:00
|
|
|
|
(with-current-buffer (fuel-xref--buffer)
|
2008-12-20 19:43:28 -05:00
|
|
|
|
(erase-buffer)
|
|
|
|
|
(dolist (ref refs)
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(when (and (stringp (first ref))
|
|
|
|
|
(stringp (third ref))
|
|
|
|
|
(numberp (fourth ref)))
|
2008-12-20 19:43:28 -05:00
|
|
|
|
(insert " ")
|
|
|
|
|
(insert-text-button (first ref)
|
|
|
|
|
:type 'fuel-xref--button-type
|
|
|
|
|
'help-echo (format "File: %s (%s)"
|
|
|
|
|
(second ref)
|
|
|
|
|
(third ref))
|
2008-12-21 11:33:53 -05:00
|
|
|
|
'file (third ref)
|
|
|
|
|
'line (fourth ref))
|
|
|
|
|
(when (stringp (second ref))
|
|
|
|
|
(insert (format " (in %s)" (second ref))))
|
|
|
|
|
(setq count (1+ count))
|
2008-12-20 19:43:28 -05:00
|
|
|
|
(newline)))
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(insert (fuel-xref--title word (if cc "using" "used by") count) "\n\n")
|
|
|
|
|
(when (> count 0)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(insert "\n" fuel-xref--help-string "\n"))
|
2008-12-21 10:04:39 -05:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(current-buffer))))
|
2008-12-20 19:43:28 -05:00
|
|
|
|
|
|
|
|
|
(defun fuel-xref--show-callers (word)
|
|
|
|
|
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref))))
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
|
|
|
|
|
(set-buffer (fuel-xref--fill-buffer word t res))
|
2008-12-21 10:04:39 -05:00
|
|
|
|
(fuel-popup--display)))
|
2008-12-20 19:43:28 -05:00
|
|
|
|
|
|
|
|
|
(defun fuel-xref--show-callees (word)
|
|
|
|
|
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref))))
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
|
|
|
|
|
(set-buffer (fuel-xref--fill-buffer word nil res))
|
2008-12-21 10:04:39 -05:00
|
|
|
|
(fuel-popup--display)))
|
2008-12-20 19:43:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Xref mode:
|
|
|
|
|
|
|
|
|
|
(defvar fuel-xref-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(suppress-keymap map)
|
|
|
|
|
(set-keymap-parent map button-buffer-map)
|
|
|
|
|
(define-key map "q" 'bury-buffer)
|
|
|
|
|
map))
|
|
|
|
|
|
|
|
|
|
(defun fuel-xref-mode ()
|
|
|
|
|
"Mode for displaying FUEL cross-reference information.
|
|
|
|
|
\\{fuel-xref-mode-map}"
|
|
|
|
|
(interactive)
|
|
|
|
|
(kill-all-local-variables)
|
|
|
|
|
(buffer-disable-undo)
|
|
|
|
|
(use-local-map fuel-xref-mode-map)
|
|
|
|
|
(setq mode-name "FUEL Xref")
|
|
|
|
|
(setq major-mode 'fuel-xref-mode)
|
2008-12-21 11:33:53 -05:00
|
|
|
|
(font-lock-add-keywords nil '(("(in \\(.+\\))" 1 'fuel-font-lock-xref-vocab)))
|
2008-12-20 19:43:28 -05:00
|
|
|
|
(setq buffer-read-only t))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'fuel-xref)
|
|
|
|
|
;;; fuel-xref.el ends here
|