FUEL: New command: fuel-apropos.

db4
Jose A. Ortega Ruiz 2009-01-04 02:36:58 +01:00
parent 9832429b94
commit c13a6efe97
6 changed files with 52 additions and 32 deletions

View File

@ -5,8 +5,8 @@ USING: accessors arrays assocs classes.tuple combinators
compiler.units continuations debugger definitions help help.crossref compiler.units continuations debugger definitions help help.crossref
help.markup help.topics io io.pathnames io.streams.string kernel lexer help.markup help.topics io io.pathnames io.streams.string kernel lexer
make math math.order memoize namespaces parser prettyprint sequences make math math.order memoize namespaces parser prettyprint sequences
sets sorting source-files strings summary tools.vocabs vectors vocabs sets sorting source-files strings summary tools.crossref tools.vocabs
vocabs.parser words ; vectors vocabs vocabs.parser words ;
IN: fuel IN: fuel
@ -151,7 +151,7 @@ SYMBOL: :uses
: fuel-run-file ( path -- ) : fuel-run-file ( path -- )
[ fuel-set-use-hook run-file ] curry with-scope ; inline [ fuel-set-use-hook run-file ] curry with-scope ; inline
: fuel-with-autouse ( quot -- ) : fuel-with-autouse ( ... quot: ( ... -- ... ) -- ... )
[ auto-use? on fuel-set-use-hook call ] curry with-scope ; inline [ auto-use? on fuel-set-use-hook call ] curry with-scope ; inline
: (fuel-get-uses) ( lines -- ) : (fuel-get-uses) ( lines -- )
@ -184,13 +184,16 @@ SYMBOL: :uses
[ [ first ] dip first <=> ] sort ; inline [ [ first ] dip first <=> ] sort ; inline
: fuel-format-xrefs ( seq -- seq' ) : fuel-format-xrefs ( seq -- seq' )
[ word? ] filter [ fuel-word>xref ] map fuel-sort-xrefs ; [ word? ] filter [ fuel-word>xref ] map ; inline
: fuel-callers-xref ( word -- ) : fuel-callers-xref ( word -- )
usage fuel-format-xrefs fuel-eval-set-result ; inline usage fuel-format-xrefs fuel-sort-xrefs fuel-eval-set-result ; inline
: fuel-callees-xref ( word -- ) : fuel-callees-xref ( word -- )
uses fuel-format-xrefs fuel-eval-set-result ; inline uses fuel-format-xrefs fuel-sort-xrefs fuel-eval-set-result ; inline
: fuel-apropos-xref ( str -- )
words-matching fuel-format-xrefs fuel-eval-set-result ; inline
! Completion support ! Completion support
@ -273,23 +276,6 @@ MEMO: fuel-article-title ( name -- title/f )
} cleave } cleave
] { } make 3array ; ] { } make 3array ;
: (fuel-vocab-help) ( name -- element )
\ article swap dup >vocab-link
[
[ summary [ , ] [ "No summary available" , ] if* ]
[ drop \ $nl , ]
[ vocab-help article [ content>> % ] when* ] tri
] { } make 3array ;
: fuel-vocab-help ( name -- )
(fuel-vocab-help) fuel-eval-set-result ; inline
: (fuel-index) ( seq -- seq )
[ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ;
: fuel-index ( quot -- )
call (fuel-index) fuel-eval-set-result ; inline
MEMO: fuel-find-word ( name -- word/f ) MEMO: fuel-find-word ( name -- word/f )
[ [ name>> ] dip = ] curry all-words swap filter [ [ name>> ] dip = ] curry all-words swap filter
dup empty? not [ first ] [ drop f ] if ; dup empty? not [ first ] [ drop f ] if ;
@ -306,6 +292,23 @@ MEMO: fuel-find-word ( name -- word/f )
fuel-find-word [ [ auto-use? on (fuel-word-see) ] with-scope ] [ f ] if* fuel-find-word [ [ auto-use? on (fuel-word-see) ] with-scope ] [ f ] if*
fuel-eval-set-result ; inline fuel-eval-set-result ; inline
: (fuel-vocab-help) ( name -- element )
\ article swap dup >vocab-link
[
[ summary [ , ] [ "No summary available" , ] if* ]
[ drop \ $nl , ]
[ vocab-help article [ content>> % ] when* ] tri
] { } make 3array ;
: fuel-vocab-help ( name -- )
(fuel-vocab-help) fuel-eval-set-result ; inline
: (fuel-index) ( seq -- seq )
[ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ;
: fuel-index ( quot: ( -- seq ) -- )
call (fuel-index) fuel-eval-set-result ; inline
! -run=fuel support ! -run=fuel support
: fuel-startup ( -- ) "listener" run-file ; inline : fuel-startup ( -- ) "listener" run-file ; inline

View File

@ -71,6 +71,7 @@ C-cC-eC-r is the same as C-cC-er)).
- C-cC-dd : help for word at point - C-cC-dd : help for word at point
- C-cC-ds : short help word at point - C-cC-ds : short help word at point
- C-cC-de : show stack effect of current sexp (with prefix, region) - C-cC-de : show stack effect of current sexp (with prefix, region)
- C-cC-dp : find words containing given substring (M-x fuel-apropos)
- C-cM-<, C-cC-d< : show callers of word at point - 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 callees of word at point
@ -80,6 +81,7 @@ C-cC-eC-r is the same as C-cC-er)).
- TAB : complete word at point - TAB : complete word at point
- M-. : edit word at point in Emacs - M-. : edit word at point in Emacs
- C-ca : toggle autodoc mode - C-ca : toggle autodoc mode
- C-cp : find words containing given substring (M-x fuel-apropos)
- C-cs : toggle stack mode - C-cs : toggle stack mode
- C-cv : edit vocabulary - C-cv : edit vocabulary
- C-ch : help for word at point - C-ch : help for word at point
@ -95,6 +97,7 @@ C-cC-eC-r is the same as C-cC-er)).
* In the Help browser: * In the Help browser:
- h : help for word at point - h : help for word at point
- a : find words containing given substring (M-x fuel-apropos)
- f/b : next/previous page - f/b : next/previous page
- SPC/S-SPC : scroll up/down - SPC/S-SPC : scroll up/down
- TAB/S-TAB : next/previous link - TAB/S-TAB : next/previous link

View File

@ -17,6 +17,7 @@
(require 'fuel-eval) (require 'fuel-eval)
(require 'fuel-markup) (require 'fuel-markup)
(require 'fuel-autodoc) (require 'fuel-autodoc)
(require 'fuel-xref)
(require 'fuel-completion) (require 'fuel-completion)
(require 'fuel-font-lock) (require 'fuel-font-lock)
(require 'fuel-popup) (require 'fuel-popup)
@ -214,6 +215,7 @@ buffer."
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(suppress-keymap map) (suppress-keymap map)
(set-keymap-parent map button-buffer-map) (set-keymap-parent map button-buffer-map)
(define-key map "a" 'fuel-apropos)
(define-key map "b" 'fuel-help-previous) (define-key map "b" 'fuel-help-previous)
(define-key map "c" 'fuel-help-clean-history) (define-key map "c" 'fuel-help-clean-history)
(define-key map "f" 'fuel-help-next) (define-key map "f" 'fuel-help-next)

View File

@ -1,6 +1,6 @@
;;; fuel-listener.el --- starting the fuel listener ;;; fuel-listener.el --- starting the fuel listener
;; Copyright (C) 2008 Jose Antonio Ortega Ruiz ;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
;; See http://factorcode.org/license.txt for BSD license. ;; See http://factorcode.org/license.txt for BSD license.
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org> ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
@ -15,6 +15,7 @@
(require 'fuel-stack) (require 'fuel-stack)
(require 'fuel-completion) (require 'fuel-completion)
(require 'fuel-xref)
(require 'fuel-eval) (require 'fuel-eval)
(require 'fuel-connection) (require 'fuel-connection)
(require 'fuel-syntax) (require 'fuel-syntax)
@ -169,6 +170,7 @@ buffer."
(define-key fuel-listener-mode-map "\C-ca" 'fuel-autodoc-mode) (define-key fuel-listener-mode-map "\C-ca" 'fuel-autodoc-mode)
(define-key fuel-listener-mode-map "\C-ch" 'fuel-help) (define-key fuel-listener-mode-map "\C-ch" 'fuel-help)
(define-key fuel-listener-mode-map "\C-cs" 'fuel-stack-mode) (define-key fuel-listener-mode-map "\C-cs" 'fuel-stack-mode)
(define-key fuel-listener-mode-map "\C-cp" 'fuel-apropos)
(define-key fuel-listener-mode-map "\M-." 'fuel-edit-word-at-point) (define-key fuel-listener-mode-map "\M-." 'fuel-edit-word-at-point)
(define-key fuel-listener-mode-map "\C-cv" 'fuel-edit-vocabulary) (define-key fuel-listener-mode-map "\C-cv" 'fuel-edit-vocabulary)
(define-key fuel-listener-mode-map "\C-c\C-v" 'fuel-edit-vocabulary) (define-key fuel-listener-mode-map "\C-c\C-v" 'fuel-edit-vocabulary)

View File

@ -1,6 +1,6 @@
;;; fuel-mode.el -- Minor mode enabling FUEL niceties ;;; fuel-mode.el -- Minor mode enabling FUEL niceties
;; Copyright (C) 2008 Jose Antonio Ortega Ruiz ;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
;; See http://factorcode.org/license.txt for BSD license. ;; See http://factorcode.org/license.txt for BSD license.
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org> ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
@ -224,6 +224,11 @@ With prefix argument, ask for word."
(message "Looking up %s's callees ..." word) (message "Looking up %s's callees ..." word)
(fuel-xref--show-callees word)))) (fuel-xref--show-callees word))))
(defun fuel-apropos (str)
"Show a list of words containing the given substring."
(interactive "MFind words containing: ")
(message "Looking up %s's references ..." str)
(fuel-xref--apropos str))
;;; Minor mode definition: ;;; Minor mode definition:
@ -289,6 +294,7 @@ interacting with a factor listener is at your disposal.
(fuel-mode--key ?d ?> 'fuel-show-callees) (fuel-mode--key ?d ?> 'fuel-show-callees)
(fuel-mode--key ?d ?< 'fuel-show-callers) (fuel-mode--key ?d ?< 'fuel-show-callers)
(fuel-mode--key ?d ?a 'fuel-autodoc-mode) (fuel-mode--key ?d ?a 'fuel-autodoc-mode)
(fuel-mode--key ?d ?p 'fuel-apropos)
(fuel-mode--key ?d ?d 'fuel-help) (fuel-mode--key ?d ?d 'fuel-help)
(fuel-mode--key ?d ?e 'fuel-stack-effect-sexp) (fuel-mode--key ?d ?e 'fuel-stack-effect-sexp)
(fuel-mode--key ?d ?s 'fuel-help-short) (fuel-mode--key ?d ?s 'fuel-help-short)

View File

@ -75,11 +75,10 @@ cursor at the first ocurrence of the used word."
(defvar fuel-xref--help-string "(Press RET or click to follow crossrefs)") (defvar fuel-xref--help-string "(Press RET or click to follow crossrefs)")
(defun fuel-xref--title (word cc count) (defun fuel-xref--title (word cc count)
(let ((cc (if cc "using" "used by"))) (put-text-property 0 (length word) 'font-lock-face 'bold word)
(put-text-property 0 (length word) 'font-lock-face 'bold word) (cond ((zerop count) (format "No known words %s %s" cc word))
(cond ((zerop count) (format "No known words %s %s" cc word)) ((= 1 count) (format "1 word %s %s:" cc word))
((= 1 count) (format "1 word %s %s:" cc word)) (t (format "%s words %s %s:" count cc word))))
(t (format "%s words %s %s:" count cc word)))))
(defun fuel-xref--insert-ref (ref) (defun fuel-xref--insert-ref (ref)
(when (and (stringp (first ref)) (when (and (stringp (first ref))
@ -124,12 +123,17 @@ cursor at the first ocurrence of the used word."
(defun fuel-xref--show-callers (word) (defun fuel-xref--show-callers (word)
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref)))) (let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) (res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
(fuel-xref--fill-and-display word t res))) (fuel-xref--fill-and-display word "using" res)))
(defun fuel-xref--show-callees (word) (defun fuel-xref--show-callees (word)
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref)))) (let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) (res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
(fuel-xref--fill-and-display word nil res))) (fuel-xref--fill-and-display word "used by" res)))
(defun fuel-xref--apropos (str)
(let* ((cmd `(:fuel* ((,str fuel-apropos-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
(fuel-xref--fill-and-display str "containing" res)))
;;; Xref mode: ;;; Xref mode: