]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: Cross-reference for vocabs (uses/usage).
authorJose A. Ortega Ruiz <jao@gnu.org>
Thu, 22 Jan 2009 20:13:38 +0000 (21:13 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Thu, 22 Jan 2009 20:13:38 +0000 (21:13 +0100)
extra/fuel/fuel.factor
extra/fuel/xref/xref.factor
misc/fuel/README
misc/fuel/fuel-completion.el
misc/fuel/fuel-edit.el
misc/fuel/fuel-refactor.el
misc/fuel/fuel-xref.el

index d4bff7678d2bb5fbb28a570dff954e7a2f3ce5e2..2bf8f1b98d36df37ec124185f2a1592b7c68412e 100644 (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 ;
index 56a2ac5803a1d280ba35dab0ef85afd6ae17774c..5f5e28d1d288719c801d26ed71c59580d551b820 100644 (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 ;
index da70952ec05bd905121bb46b61828ef48036ee98..759f26c1b2efd116a7e5b742db11600b2b50eb4e 100644 (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
index 6f08e0c4cdffc881c0a47c0a4e901c06394def84..e6ec8b2dc93e5d04ef5c16a5f85fc905e55b436c 100644 (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>
              (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))))
index 0037c6718a661f07523593f328a91bfc0728c91a..e5f0ffd26fcc08bfe270d9fd546ec157a9396d3f 100644 (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))
index 738d6fff4703103f836a7f62c40747ba147f6c0e..f44234ae1b62c64829fb820bfa4dd8fa12d94a7c 100644 (file)
@@ -164,6 +164,11 @@ word."
         (save-excursion (font-lock-fontify-region start (point)))
         (indent-region start (point))))))
 
+\f
+;;; Rename word:
+
+
+
 \f
 ;;; Extract vocab:
 
index d98c0b0a69f91297d402093fbb280fc38c0e25a1..cae7923bee145e833a5e1d904560abec14a3d443 100644 (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")))
+
 \f
 ;;; 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."