FUEL: Cross-reference for vocabs (uses/usage).

db4
Jose A. Ortega Ruiz 2009-01-22 21:13:38 +01:00
parent d3cbb62851
commit a654fac19e
7 changed files with 78 additions and 18 deletions

View File

@ -80,6 +80,10 @@ PRIVATE>
: fuel-vocab-xref ( vocab -- ) vocab-xref fuel-eval-set-result ;
: fuel-vocab-uses-xref ( vocab -- ) vocab-uses-xref fuel-eval-set-result ;
: fuel-vocab-usage-xref ( vocab -- ) vocab-usage-xref fuel-eval-set-result ;
! Help support
: fuel-get-article ( name -- ) article fuel-eval-set-result ;

View File

@ -18,6 +18,9 @@ IN: fuel.xref
: word>xref ( word -- xref )
[ name>> ] [ vocabulary>> ] [ where normalize-loc ] tri 4array ;
: vocab>xref ( vocab -- xref )
dup dup >vocab-link where normalize-loc 4array ;
: sort-xrefs ( seq -- seq' )
[ [ first ] dip first <=> ] sort ; inline
@ -50,6 +53,10 @@ PRIVATE>
: vocab-location ( vocab -- loc ) >vocab-link where get-loc ;
: vocab-uses-xref ( vocab -- seq ) vocab-uses [ vocab>xref ] map ;
: vocab-usage-xref ( vocab -- seq ) vocab-usage [ vocab>xref ] map ;
: doc-location ( word -- loc ) props>> "help-loc" swap at get-loc ;
: article-location ( name -- loc ) article loc>> get-loc ;

View File

@ -113,8 +113,10 @@ beast.
- C-cC-dp : find words containing given substring (M-x fuel-apropos)
- C-cC-dv : show words in current file (with prefix, ask for vocab)
- C-cM-<, C-cC-d< : show callers of word at point
- C-cM->, C-cC-d> : show callees of word at point
- C-cM-<, C-cC-d< : show callers of word or vocabulary at point
(M-x fuel-show-callers, M-x fuel-vocab-usage)
- C-cM->, C-cC-d> : show callees of word or vocabulary at point
(M-x fuel-show-callees, M-x fuel-vocab-uses)
- C-cC-xs : extract innermost sexp (up to point) as a separate word
- C-cC-xr : extract region as a separate word

View File

@ -1,6 +1,6 @@
;;; fuel-completion.el -- completion utilities
;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
;; See http://factorcode.org/license.txt for BSD license.
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
@ -32,6 +32,10 @@
(fuel-eval--send/wait '(:fuel* (fuel-get-vocabs) "fuel" (:array)))))))
fuel-completion--vocabs)
(defun fuel-completion--read-vocab (&optional reload init-input history)
(let ((vocabs (fuel-completion--vocabs reload)))
(completing-read "Vocab name: " vocabs nil nil init-input history)))
(defsubst fuel-completion--vocab-list (prefix)
(fuel-eval--retort-result
(fuel-eval--send/wait `(:fuel* (,prefix fuel-get-vocabs/prefix) t t))))

View File

@ -45,7 +45,7 @@
(defun fuel-edit--looking-at-vocab ()
(save-excursion
(fuel-syntax--beginning-of-defun)
(looking-at "USING:\\|USE:")))
(looking-at "USING:\\|USE:\\|IN:")))
(defun fuel-edit--try-edit (ret)
(let* ((err (fuel-eval--retort-error ret))

View File

@ -164,6 +164,11 @@ word."
(save-excursion (font-lock-fontify-region start (point)))
(indent-region start (point))))))
;;; Rename word:
;;; Extract vocab:

View File

@ -83,11 +83,11 @@ cursor at the first ocurrence of the used word."
(defvar fuel-xref--help-string
"(Press RET or click to follow crossrefs, or h for help on word at point)")
(defun fuel-xref--title (word cc count)
(defun fuel-xref--title (word cc count thing)
(put-text-property 0 (length word) 'font-lock-face 'bold word)
(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))))
(cond ((zerop count) (format "No known %s %s %s" thing cc word))
((= 1 count) (format "1 %s %s %s:" thing cc word))
(t (format "%s %ss %s %s:" count thing cc word))))
(defun fuel-xref--insert-ref (ref &optional no-vocab)
(when (and (stringp (first ref))
@ -106,7 +106,7 @@ cursor at the first ocurrence of the used word."
(newline)
t))
(defun fuel-xref--fill-buffer (word cc refs &optional no-vocab app)
(defun fuel-xref--fill-buffer (word cc refs &optional no-vocab app thing)
(let ((inhibit-read-only t)
(count 0))
(with-current-buffer (fuel-xref--buffer)
@ -118,13 +118,13 @@ cursor at the first ocurrence of the used word."
(newline)
(goto-char start)
(save-excursion
(insert (fuel-xref--title word cc count) "\n\n"))
(insert (fuel-xref--title word cc count (or thing "word")) "\n\n"))
count))))
(defun fuel-xref--fill-and-display (word cc refs &optional no-vocab)
(let ((count (fuel-xref--fill-buffer word cc refs no-vocab)))
(defun fuel-xref--fill-and-display (word cc refs &optional no-vocab thing)
(let ((count (fuel-xref--fill-buffer word cc refs no-vocab nil (or thing "word"))))
(if (zerop count)
(error (fuel-xref--title word cc 0))
(error (fuel-xref--title word cc 0 (or thing "word")))
(message "")
(fuel-popup--display (fuel-xref--buffer)))))
@ -160,13 +160,25 @@ cursor at the first ocurrence of the used word."
(fuel-popup--display (fuel-xref--buffer))
(goto-char (point-min)))
(defun fuel-xref--show-vocab-usage (vocab)
(let* ((cmd `(:fuel* ((,vocab fuel-vocab-usage-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
(with-current-buffer (fuel-xref--buffer) (setq fuel-xref--word nil))
(fuel-xref--fill-and-display vocab "using" res t "vocab")))
(defun fuel-xref--show-vocab-uses (vocab)
(let* ((cmd `(:fuel* ((,vocab fuel-vocab-uses-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
(with-current-buffer (fuel-xref--buffer) (setq fuel-xref--word nil))
(fuel-xref--fill-and-display vocab "used by" res t "vocab")))
;;; User commands:
(defvar fuel-xref--word-history nil)
(defun fuel-show-callers (&optional arg)
"Show a list of callers of word at point.
"Show a list of callers of word or vocabulary at point.
With prefix argument, ask for word."
(interactive "P")
(let ((word (if arg (fuel-completion--read-word "Find callers for: "
@ -174,11 +186,14 @@ With prefix argument, ask for word."
fuel-xref--word-history)
(fuel-syntax-symbol-at-point))))
(when word
(message "Looking up %s's callers ..." word)
(fuel-xref--show-callers word))))
(message "Looking up %s's users ..." word)
(if (and (not arg)
(fuel-edit--looking-at-vocab))
(fuel-xref--show-vocab-usage word)
(fuel-xref--show-callers word)))))
(defun fuel-show-callees (&optional arg)
"Show a list of callers of word at point.
"Show a list of callers of word or vocabulary at point.
With prefix argument, ask for word."
(interactive "P")
(let ((word (if arg (fuel-completion--read-word "Find callees for: "
@ -187,7 +202,30 @@ With prefix argument, ask for word."
(fuel-syntax-symbol-at-point))))
(when word
(message "Looking up %s's callees ..." word)
(fuel-xref--show-callees word))))
(if (and (not arg)
(fuel-edit--looking-at-vocab))
(fuel-xref--show-vocab-uses word)
(fuel-xref--show-callees word)))))
(defvar fuel-xref--vocab-history nil)
(defun fuel-vocab-uses (&optional arg)
"Show a list of vocabularies used by a given one.
With prefix argument, force reload of vocabulary list."
(interactive "P")
(let ((vocab (fuel-completion--read-vocab arg
(fuel-syntax-symbol-at-point)
fuel-xref--vocab-history)))
(fuel-xref--show-vocab-uses vocab)))
(defun fuel-vocab-usage (&optional arg)
"Show a list of vocabularies that use a given one.
With prefix argument, force reload of vocabulary list."
(interactive "P")
(let ((vocab (fuel-completion--read-vocab arg
(fuel-syntax-symbol-at-point)
fuel-xref--vocab-history)))
(fuel-xref--show-vocab-usage vocab)))
(defun fuel-apropos (str)
"Show a list of words containing the given substring."