Merge branch 'master' into new_ui

db4
Slava Pestov 2009-01-05 07:58:52 -06:00
commit cb3102f9d1
15 changed files with 1016 additions and 319 deletions

View File

@ -1,10 +1,13 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: binary-search math.primes.list math.ranges sequences USING: binary-search kernel math.primes.list math.ranges sequences
prettyprint ; prettyprint ;
IN: benchmark.binary-search IN: benchmark.binary-search
: binary-search-benchmark ( -- ) : binary-search-benchmark ( -- )
1 1000000 [a,b] [ primes-under-million sorted-member? ] map length . ; 1 1000000 [a,b] [ primes-under-million sorted-member? ] map length . ;
! Force computation of the primes list before benchmarking the binary search
primes-under-million drop
MAIN: binary-search-benchmark MAIN: binary-search-benchmark

View File

@ -1,11 +1,12 @@
! 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.
USING: accessors arrays assocs classes.tuple combinators USING: accessors arrays assocs classes.tuple combinators
compiler.units continuations debugger definitions io io.pathnames compiler.units continuations debugger definitions help help.crossref
io.streams.string kernel lexer math math.order memoize namespaces help.markup help.topics io io.pathnames io.streams.string kernel lexer
parser prettyprint sequences sets sorting source-files strings summary make math math.order memoize namespaces parser prettyprint sequences
tools.vocabs vectors vocabs vocabs.parser words ; sets sorting source-files strings summary tools.crossref tools.vocabs
vectors vocabs vocabs.parser words ;
IN: fuel IN: fuel
@ -17,13 +18,13 @@ SYMBOL: fuel-status-stack
V{ } clone fuel-status-stack set-global V{ } clone fuel-status-stack set-global
SYMBOL: fuel-eval-result SYMBOL: fuel-eval-result
f clone fuel-eval-result set-global f fuel-eval-result set-global
SYMBOL: fuel-eval-output SYMBOL: fuel-eval-output
f clone fuel-eval-result set-global f fuel-eval-result set-global
SYMBOL: fuel-eval-res-flag SYMBOL: fuel-eval-res-flag
t clone fuel-eval-res-flag set-global t fuel-eval-res-flag set-global
: fuel-eval-restartable? ( -- ? ) : fuel-eval-restartable? ( -- ? )
fuel-eval-res-flag get-global ; inline fuel-eval-res-flag get-global ; inline
@ -56,6 +57,12 @@ GENERIC: fuel-pprint ( obj -- )
M: object fuel-pprint pprint ; inline M: object fuel-pprint pprint ; inline
: fuel-maybe-scape ( ch -- seq )
dup "\\\"?#()[]'`" member? [ CHAR: \ swap 2array ] [ 1array ] if ;
M: word fuel-pprint
name>> V{ } clone [ fuel-maybe-scape append ] reduce >string write ;
M: f fuel-pprint drop "nil" write ; inline M: f fuel-pprint drop "nil" write ; inline
M: integer fuel-pprint pprint ; inline M: integer fuel-pprint pprint ; inline
@ -99,20 +106,17 @@ M: source-file fuel-pprint path>> fuel-pprint ;
clone fuel-eval-result set-global ; inline clone fuel-eval-result set-global ; inline
: fuel-retort ( -- ) : fuel-retort ( -- )
error get error get fuel-eval-result get-global fuel-eval-output get-global
fuel-eval-result get-global
fuel-eval-output get-global
3array fuel-pprint flush nl "<~FUEL~>" write nl flush ; 3array fuel-pprint flush nl "<~FUEL~>" write nl flush ;
: fuel-forget-error ( -- ) f error set-global ; inline : fuel-forget-error ( -- ) f error set-global ; inline
: fuel-forget-result ( -- ) f fuel-eval-result set-global ; inline : fuel-forget-result ( -- ) f fuel-eval-result set-global ; inline
: fuel-forget-output ( -- ) f fuel-eval-output set-global ; inline : fuel-forget-output ( -- ) f fuel-eval-output set-global ; inline
: fuel-forget-status ( -- )
fuel-forget-error fuel-forget-result fuel-forget-output ; inline
: (fuel-begin-eval) ( -- ) : (fuel-begin-eval) ( -- )
fuel-push-status fuel-push-status fuel-forget-status ; inline
fuel-forget-error
fuel-forget-result
fuel-forget-output ;
: (fuel-end-eval) ( output -- ) : (fuel-end-eval) ( output -- )
fuel-eval-output set-global fuel-retort fuel-pop-status ; inline fuel-eval-output set-global fuel-retort fuel-pop-status ; inline
@ -138,14 +142,17 @@ M: source-file fuel-pprint path>> fuel-pprint ;
! Loading files ! Loading files
: fuel-run-file ( path -- ) run-file ; inline SYMBOL: :uses
: fuel-with-autouse ( quot -- ) : fuel-set-use-hook ( -- )
[ [ amended-use get clone :uses prefix fuel-eval-set-result ]
auto-use? on print-use-hook set ;
[ amended-use get clone fuel-eval-set-result ] print-use-hook set
call : fuel-run-file ( path -- )
] curry with-scope ; [ fuel-set-use-hook run-file ] curry with-scope ; inline
: fuel-with-autouse ( ... quot: ( ... -- ... ) -- ... )
[ auto-use? on fuel-set-use-hook call ] curry with-scope ; inline
: (fuel-get-uses) ( lines -- ) : (fuel-get-uses) ( lines -- )
[ parse-fresh drop ] curry with-compilation-unit ; inline [ parse-fresh drop ] curry with-compilation-unit ; inline
@ -177,13 +184,16 @@ M: source-file fuel-pprint path>> fuel-pprint ;
[ [ 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
@ -218,6 +228,86 @@ MEMO: (fuel-vocab-words) ( name -- seq )
: fuel-get-words ( prefix names -- ) : fuel-get-words ( prefix names -- )
(fuel-get-words) fuel-eval-set-result ; inline (fuel-get-words) fuel-eval-set-result ; inline
! Help support
MEMO: fuel-articles-seq ( -- seq )
articles get values ;
: fuel-find-articles ( title -- seq )
[ [ article-title ] dip = ] curry fuel-articles-seq swap filter ;
MEMO: fuel-find-article ( title -- article/f )
fuel-find-articles dup empty? [ drop f ] [ first ] if ;
MEMO: fuel-article-title ( name -- title/f )
articles get at [ article-title ] [ f ] if* ;
: fuel-get-article ( name -- )
article fuel-eval-set-result ;
: fuel-value-str ( word -- str )
[ pprint-short ] with-string-writer ; inline
: fuel-definition-str ( word -- str )
[ see ] with-string-writer ; inline
: fuel-methods-str ( word -- str )
methods dup empty? not [
[ [ see nl ] each ] with-string-writer
] [ drop f ] if ; inline
: fuel-related-words ( word -- seq )
dup "related" word-prop remove ; inline
: fuel-parent-topics ( word -- seq )
help-path [ dup article-title swap 2array ] map ; inline
: (fuel-word-help) ( word -- element )
dup \ article swap article-title rot
[
{
[ fuel-parent-topics [ \ $doc-path prefix , ] unless-empty ]
[ \ $vocabulary swap vocabulary>> 2array , ]
[ word-help % ]
[ fuel-related-words [ \ $related swap 2array , ] unless-empty ]
[ get-global [ \ $value swap fuel-value-str 2array , ] when* ]
[ \ $definition swap fuel-definition-str 2array , ]
[ fuel-methods-str [ \ $methods swap 2array , ] when* ]
} cleave
] { } make 3array ;
MEMO: fuel-find-word ( name -- word/f )
[ [ name>> ] dip = ] curry all-words swap filter
dup empty? not [ first ] [ drop f ] if ;
: fuel-word-help ( name -- )
fuel-find-word [ [ auto-use? on (fuel-word-help) ] with-scope ] [ f ] if*
fuel-eval-set-result ; inline
: (fuel-word-see) ( word -- elem )
[ name>> \ article swap ]
[ [ see ] with-string-writer \ $code swap 2array ] bi 3array ; inline
: fuel-word-see ( name -- )
fuel-find-word [ [ auto-use? on (fuel-word-see) ] with-scope ] [ f ] if*
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

View File

@ -1,4 +1,4 @@
USING: math.primes ; USING: math.primes memoize ;
IN: math.primes.list IN: math.primes.list
: primes-under-million ( -- seq ) 1000000 primes-upto ; MEMO: primes-under-million ( -- seq ) 1000000 primes-upto ;

View File

@ -1,56 +1,54 @@
FUEL, Factor's Ultimate Emacs Library FUEL, Factor's Ultimate Emacs Library -*- org -*-
------------------------------------- -------------------------------------
FUEL provides a complete environment for your Factor coding pleasure FUEL provides a complete environment for your Factor coding pleasure
inside Emacs, including source code edition and interaction with a inside Emacs, including source code edition and interaction with a
Factor listener instance running within Emacs. Factor listener instance running within Emacs.
FUEL was started by Jose A Ortega as an extension to Ed Cavazos' FUEL was started by Jose A Ortega as an extension to Eduardo Cavazos'
original factor.el code. original factor.el code. Eduardo is also responsible of naming the
beast.
Installation * Installation
------------
FUEL comes bundled with Factor's distribution. The folder misc/fuel FUEL comes bundled with Factor's distribution. The folder misc/fuel
contains Elisp code, and there's a fuel vocabulary in extras/fuel. contains Elisp code, and there's a fuel vocabulary in extras/fuel.
To install FUEL, either add this line to your Emacs initialisation: To install FUEL, either add this line to your Emacs initialisation:
(load-file "<path/to/factor/installation>/misc/fuel/fu.el") (load-file "<path/to/factor/installation>/misc/fuel/fu.el")
or or
(add-to-list load-path "<path/to/factor/installation>/fuel") (add-to-list load-path "<path/to/factor/installation>/fuel")
(require 'fuel) (require 'fuel)
If all you want is a major mode for editing Factor code with pretty If all you want is a major mode for editing Factor code with pretty
font colors and indentation, without running the factor listener font colors and indentation, without running the factor listener
inside Emacs, you can use instead: inside Emacs, you can use instead:
(add-to-list load-path "<path/to/factor/installation>/fuel") (add-to-list load-path "<path/to/factor/installation>/fuel")
(setq factor-mode-use-fuel nil) (setq factor-mode-use-fuel nil)
(require 'factor-mode) (require 'factor-mode)
Basic usage * Basic usage
-----------
If you're using the default factor binary and images locations inside If you're using the default factor binary and images locations inside
the Factor's source tree, that should be enough to start using FUEL. the Factor's source tree, that should be enough to start using FUEL.
Editing any file with the extension .factor will put you in Editing any file with the extension .factor will put you in
factor-mode; try C-hm for a summary of available commands. factor-mode; try C-hm for a summary of available commands.
To start the listener, try M-x run-factor. To start the listener, try M-x run-factor.
Many aspects of the environment can be customized: Many aspects of the environment can be customized:
M-x customize-group fuel will show you how many. M-x customize-group fuel will show you how many.
Quick key reference * Quick key reference
-------------------
(Triple chords ending in a single letter <x> accept also C-<x> (e.g. (Triple chords ending in a single letter <x> accept also C-<x> (e.g.
C-cC-eC-r is the same as C-cC-er)). C-cC-eC-r is the same as C-cC-er)).
* In factor source files: *** In factor source files:
- C-cz : switch to listener - C-cz : switch to listener
- C-co : cycle between code, tests and docs factor files - C-co : cycle between code, tests and docs factor files
@ -71,37 +69,46 @@ 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
* In the listener: *** In the listener:
- 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
- C-ck : run file - C-ck : run file
* In the debugger (it pops up upon eval/compilation errors): *** In the debugger (it pops up upon eval/compilation errors):
- g : go to error - g : go to error
- <digit> : invoke nth restart - <digit> : invoke nth restart
- w/e/l : invoke :warnings, :errors, :linkage - w/e/l : invoke :warnings, :errors, :linkage
- q : bury buffer - q : bury buffer
* In the Help browser: *** In the help browser:
- RET : help for word at point - h : help for word at point
- f/b : next/previous page - a : find words containing given substring (M-x fuel-apropos)
- ba : bookmark current page
- bb : display bookmarks
- bd : delete bookmark at point
- n/p : next/previous page
- SPC/S-SPC : scroll up/down - SPC/S-SPC : scroll up/down
- TAB/S-TAB : next/previous headline - TAB/S-TAB : next/previous link
- r : refresh page
- c : clean browsing history
- M-. : edit word at point in Emacs
- C-cz : switch to listener - C-cz : switch to listener
- q : bury buffer - q : bury buffer
* In crossref buffers *** In crossref buffers
- TAB/BACKTAB : navigate links - TAB/BACKTAB : navigate links
- RET/mouse click : follow link - RET/mouse click : follow link

View File

@ -1,6 +1,6 @@
;;; fuel-autodoc.el -- doc snippets in the echo area ;;; fuel-autodoc.el -- doc snippets in the echo area
;; 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 @@
;;; Code: ;;; Code:
(require 'fuel-eval) (require 'fuel-eval)
(require 'fuel-font-lock)
(require 'fuel-syntax) (require 'fuel-syntax)
(require 'fuel-base) (require 'fuel-base)
@ -30,34 +31,24 @@
:group 'fuel-autodoc :group 'fuel-autodoc
:type 'boolean) :type 'boolean)
;;; Autodoc mode: ;;; Eldoc function:
(defvar fuel-autodoc--font-lock-buffer (defvar fuel-autodoc--timeout 200)
(let ((buffer (get-buffer-create " *fuel help minibuffer messages*")))
(set-buffer buffer)
(fuel-font-lock--font-lock-setup)
buffer))
(defun fuel-autodoc--font-lock-str (str)
(set-buffer fuel-autodoc--font-lock-buffer)
(erase-buffer)
(insert str)
(let ((font-lock-verbose nil)) (font-lock-fontify-buffer))
(buffer-string))
(defun fuel-autodoc--word-synopsis (&optional word) (defun fuel-autodoc--word-synopsis (&optional word)
(let ((word (or word (fuel-syntax-symbol-at-point))) (let ((word (or word (fuel-syntax-symbol-at-point)))
(fuel-log--inhibit-p t)) (fuel-log--inhibit-p t))
(when word (when word
(let* ((cmd (if (fuel-syntax--in-using) (let* ((cmd (if (fuel-syntax--in-using)
`(:fuel* (,word fuel-vocab-summary) t t) `(:fuel* (,word fuel-vocab-summary) :in t)
`(:fuel* (((:quote ,word) synopsis :get)) t))) `(:fuel* (((:quote ,word) synopsis :get)) :in)))
(ret (fuel-eval--send/wait cmd 20)) (ret (fuel-eval--send/wait cmd fuel-autodoc--timeout))
(res (fuel-eval--retort-result ret))) (res (fuel-eval--retort-result ret)))
(when (and ret (not (fuel-eval--retort-error ret)) (stringp res)) (when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
(if fuel-autodoc-minibuffer-font-lock (if fuel-autodoc-minibuffer-font-lock
(fuel-autodoc--font-lock-str res) (fuel-font-lock--factor-str res)
res)))))) res))))))
(make-variable-buffer-local (make-variable-buffer-local
@ -68,6 +59,9 @@
(funcall fuel-autodoc--fallback-function)) (funcall fuel-autodoc--fallback-function))
(fuel-autodoc--word-synopsis))) (fuel-autodoc--word-synopsis)))
;;; Autodoc mode:
(make-variable-buffer-local (make-variable-buffer-local
(defvar fuel-autodoc-mode-string " A" (defvar fuel-autodoc-mode-string " A"
"Modeline indicator for fuel-autodoc-mode")) "Modeline indicator for fuel-autodoc-mode"))

View File

@ -23,12 +23,6 @@
;;; Customization: ;;; Customization:
(fuel-font-lock--defface fuel-font-lock-debug-missing-vocab
'font-lock-warning-face fuel-debug "missing vocabulary names")
(fuel-font-lock--defface fuel-font-lock-debug-unneeded-vocab
'font-lock-warning-face fuel-debug "unneeded vocabulary names")
(fuel-font-lock--defface fuel-font-lock-debug-uses-header (fuel-font-lock--defface fuel-font-lock-debug-uses-header
'bold fuel-debug "headers in Uses buffers") 'bold fuel-debug "headers in Uses buffers")
@ -53,26 +47,6 @@
(forward-line)) (forward-line))
(reverse lines)))))) (reverse lines))))))
(defun fuel-debug--highlight-names (names ref face)
(dolist (n names)
(when (not (member n ref))
(put-text-property 0 (length n) 'font-lock-face face n))))
(defun fuel-debug--uses-new-uses (file uses)
(pop-to-buffer (find-file-noselect file))
(goto-char (point-min))
(if (re-search-forward "^USING: " nil t)
(let ((begin (point))
(end (or (and (re-search-forward "\\_<;\\_>") (point)) (point))))
(kill-region begin end))
(re-search-forward "^IN: " nil t)
(beginning-of-line)
(open-line 2)
(insert "USING: "))
(let ((start (point)))
(insert (mapconcat 'substring-no-properties uses " ") " ;")
(fill-region start (point) nil)))
(defun fuel-debug--uses-filter (restarts) (defun fuel-debug--uses-filter (restarts)
(let ((result) (i 1) (rn 0)) (let ((result) (i 1) (rn 0))
(dolist (r restarts (reverse result)) (dolist (r restarts (reverse result))
@ -87,9 +61,6 @@
(fuel-popup--define fuel-debug--uses-buffer (fuel-popup--define fuel-debug--uses-buffer
"*fuel uses*" 'fuel-debug-uses-mode) "*fuel uses*" 'fuel-debug-uses-mode)
(make-variable-buffer-local
(defvar fuel-debug--uses nil))
(make-variable-buffer-local (make-variable-buffer-local
(defvar fuel-debug--uses-file nil)) (defvar fuel-debug--uses-file nil))
@ -122,27 +93,15 @@
(fuel-popup--display (fuel-debug--uses-buffer)))) (fuel-popup--display (fuel-debug--uses-buffer))))
(defun fuel-debug--uses-cont (retort) (defun fuel-debug--uses-cont (retort)
(let ((uses (fuel-eval--retort-result retort)) (let ((uses (fuel-debug--uses retort))
(err (fuel-eval--retort-error retort))) (err (fuel-eval--retort-error retort)))
(if uses (fuel-debug--uses-display uses) (if uses (fuel-debug--uses-display uses)
(fuel-debug--uses-display-err retort)))) (fuel-debug--uses-display-err retort))))
(defun fuel-debug--insert-vlist (title vlist)
(goto-char (point-max))
(insert title "\n\n ")
(let ((i 0) (step 5))
(dolist (v vlist)
(setq i (1+ i))
(insert v)
(insert (if (zerop (mod i step)) "\n " " ")))
(unless (zerop (mod i step)) (newline))
(newline)))
(defun fuel-debug--uses-display (uses) (defun fuel-debug--uses-display (uses)
(let* ((inhibit-read-only t) (let* ((inhibit-read-only t)
(old (with-current-buffer (find-file-noselect fuel-debug--uses-file) (old (with-current-buffer (find-file-noselect fuel-debug--uses-file)
(fuel-syntax--usings))) (sort (fuel-syntax--find-usings t) 'string<)))
(old (sort old 'string<))
(new (sort uses 'string<))) (new (sort uses 'string<)))
(erase-buffer) (erase-buffer)
(fuel-debug--uses-insert-title) (fuel-debug--uses-insert-title)
@ -177,14 +136,15 @@
(defun fuel-debug--uses-update-usings () (defun fuel-debug--uses-update-usings ()
(interactive) (interactive)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t)
(when (and fuel-debug--uses-file fuel-debug--uses) (file fuel-debug--uses-file)
(fuel-debug--uses-new-uses fuel-debug--uses-file fuel-debug--uses) (uses fuel-debug--uses))
(message "USING: updated!") (when (and uses file)
(with-current-buffer (fuel-debug--uses-buffer)
(insert "\nDone!") (insert "\nDone!")
(fuel-debug--uses-clean) (fuel-debug--uses-clean)
(bury-buffer))))) (fuel-popup--quit)
(fuel-debug--replace-usings file uses)
(message "USING: updated!"))))
(defun fuel-debug--uses-restart (n) (defun fuel-debug--uses-restart (n)
(when (and (> n 0) (<= n (length fuel-debug--uses-restarts))) (when (and (> n 0) (<= n (length fuel-debug--uses-restarts)))

View File

@ -31,6 +31,12 @@
:group 'fuel-debug :group 'fuel-debug
:type 'hook) :type 'hook)
(defcustom fuel-debug-confirm-restarts-p t
"Whether to ask for confimation before executing a restart in
the debugger."
:group 'fuel-debug
:type 'boolean)
(defcustom fuel-debug-show-short-help t (defcustom fuel-debug-show-short-help t
"Whether to show short help on available keys in debugger." "Whether to show short help on available keys in debugger."
:group 'fuel-debug :group 'fuel-debug
@ -43,7 +49,9 @@
(column variable-name "column numbers in errors/warnings") (column variable-name "column numbers in errors/warnings")
(info comment "information headers") (info comment "information headers")
(restart-number warning "restart numbers") (restart-number warning "restart numbers")
(restart-name function-name "restart names"))) (restart-name function-name "restart names")
(missing-vocab warning"missing vocabulary names")
(unneeded-vocab warning "unneeded vocabulary names")))
;;; Font lock and other pattern matching: ;;; Font lock and other pattern matching:
@ -92,6 +100,9 @@
(make-variable-buffer-local (make-variable-buffer-local
(defvar fuel-debug--file nil)) (defvar fuel-debug--file nil))
(make-variable-buffer-local
(defvar fuel-debug--uses nil))
(defun fuel-debug--prepare-compilation (file msg) (defun fuel-debug--prepare-compilation (file msg)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(with-current-buffer (fuel-debug--buffer) (with-current-buffer (fuel-debug--buffer)
@ -114,6 +125,7 @@
(fuel-debug--display-restarts err) (fuel-debug--display-restarts err)
(delete-blank-lines) (delete-blank-lines)
(newline)) (newline))
(fuel-debug--display-uses ret)
(let ((hstr (fuel-debug--help-string err fuel-debug--file))) (let ((hstr (fuel-debug--help-string err fuel-debug--file)))
(if fuel-debug-show-short-help (if fuel-debug-show-short-help
(insert "-----------\n" hstr "\n") (insert "-----------\n" hstr "\n")
@ -124,6 +136,46 @@
(when (and err (not no-pop)) (fuel-popup--display)) (when (and err (not no-pop)) (fuel-popup--display))
(not err)))) (not err))))
(defun fuel-debug--uses (ret)
(let ((uses (fuel-eval--retort-result ret)))
(and (eq :uses (car uses))
(cdr uses))))
(defun fuel-debug--insert-vlist (title vlist)
(goto-char (point-max))
(insert title "\n\n ")
(let ((i 0) (step 5))
(dolist (v vlist)
(setq i (1+ i))
(insert v)
(insert (if (zerop (mod i step)) "\n " " ")))
(unless (zerop (mod i step)) (newline))
(newline)))
(defun fuel-debug--highlight-names (names ref face)
(dolist (n names)
(when (not (member n ref))
(put-text-property 0 (length n) 'font-lock-face face n))))
(defun fuel-debug--insert-uses (uses)
(let* ((file (or file fuel-debug--file))
(old (with-current-buffer (find-file-noselect file)
(sort (fuel-syntax--find-usings t) 'string<)))
(new (sort uses 'string<)))
(when (not (equalp old new))
(fuel-debug--highlight-names old new 'fuel-font-lock-debug-unneeded-vocab)
(newline)
(fuel-debug--insert-vlist "Correct vocabulary list:" new)
new)))
(defun fuel-debug--display-uses (ret)
(when (setq fuel-debug--uses (fuel-debug--uses ret))
(newline)
(fuel-debug--highlight-names fuel-debug--uses
nil 'fuel-font-lock-debug-missing-vocab)
(fuel-debug--insert-vlist "Missing vocabularies:" fuel-debug--uses)
(newline)))
(defun fuel-debug--display-output (ret) (defun fuel-debug--display-output (ret)
(let* ((last (fuel-eval--retort-output fuel-debug--last-ret)) (let* ((last (fuel-eval--retort-output fuel-debug--last-ret))
(current (fuel-eval--retort-output ret)) (current (fuel-eval--retort-output ret))
@ -149,7 +201,7 @@
(newline)))) (newline))))
(defun fuel-debug--help-string (err &optional file) (defun fuel-debug--help-string (err &optional file)
(format "Press %s%s%sq bury buffer" (format "Press %s%s%s%sq bury buffer"
(if (or file (fuel-eval--error-file err)) "g go to file, " "") (if (or file (fuel-eval--error-file err)) "g go to file, " "")
(let ((rsn (length (fuel-eval--error-restarts err)))) (let ((rsn (length (fuel-eval--error-restarts err))))
(cond ((zerop rsn) "") (cond ((zerop rsn) "")
@ -160,7 +212,8 @@
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(when (search-forward (car ci) nil t) (when (search-forward (car ci) nil t)
(setq str (format "%c %s, %s" (cdr ci) (car ci) str)))))))) (setq str (format "%c %s, %s" (cdr ci) (car ci) str))))))
(if (and (not err) fuel-debug--uses) "u to update USING:, " "")))
(defun fuel-debug--buffer-file () (defun fuel-debug--buffer-file ()
(with-current-buffer (fuel-debug--buffer) (with-current-buffer (fuel-debug--buffer)
@ -229,6 +282,31 @@
(fuel-eval--send/wait `(:fuel ((:factor ,info)))) "") (fuel-eval--send/wait `(:fuel ((:factor ,info)))) "")
(error "Sorry, no %s info available" info)))) (error "Sorry, no %s info available" info))))
(defun fuel-debug--replace-usings (file uses)
(pop-to-buffer (find-file-noselect file))
(goto-char (point-min))
(if (re-search-forward "^USING: " nil t)
(let ((begin (point))
(end (or (and (re-search-forward "\\_<;\\_>") (point)) (point))))
(kill-region begin end))
(re-search-forward "^IN: " nil t)
(beginning-of-line)
(open-line 2)
(insert "USING: "))
(let ((start (point)))
(insert (mapconcat 'substring-no-properties uses " ") " ;")
(fill-region start (point) nil)))
(defun fuel-debug-update-usings ()
(interactive)
(when (and fuel-debug--file fuel-debug--uses)
(let* ((file fuel-debug--file)
(old (with-current-buffer (find-file-noselect file)
(fuel-syntax--find-usings t)))
(uses (sort (append fuel-debug--uses old) 'string<)))
(fuel-popup--quit)
(fuel-debug--replace-usings file uses))))
;;; Fuel Debug mode: ;;; Fuel Debug mode:
@ -239,9 +317,11 @@
(define-key map "\C-c\C-c" 'fuel-debug-goto-error) (define-key map "\C-c\C-c" 'fuel-debug-goto-error)
(define-key map "n" 'next-line) (define-key map "n" 'next-line)
(define-key map "p" 'previous-line) (define-key map "p" 'previous-line)
(define-key map "u" 'fuel-debug-update-usings)
(dotimes (n 9) (dotimes (n 9)
(define-key map (vector (+ ?1 n)) (define-key map (vector (+ ?1 n))
`(lambda () (interactive) (fuel-debug-exec-restart ,(1+ n) t)))) `(lambda () (interactive)
(fuel-debug-exec-restart ,(1+ n) fuel-debug-confirm-restarts-p))))
(dolist (ci fuel-debug--compiler-info-alist) (dolist (ci fuel-debug--compiler-info-alist)
(define-key map (vector (cdr ci)) (define-key map (vector (cdr ci))
`(lambda () (interactive) (fuel-debug-show--compiler-info ,(car ci))))) `(lambda () (interactive) (fuel-debug-show--compiler-info ,(car ci)))))

View File

@ -67,7 +67,7 @@
(cons :array (mapcar 'factor lst))) (cons :array (mapcar 'factor lst)))
(defsubst factor--fuel-in (in) (defsubst factor--fuel-in (in)
(cond ((null in) :in) (cond ((or (eq in :in) (null in)) :in)
((eq in 'f) 'f) ((eq in 'f) 'f)
((eq in 't) "fuel-scratchpad") ((eq in 't) "fuel-scratchpad")
((stringp in) in) ((stringp in) in)

View File

@ -1,6 +1,6 @@
;;; fuel-font-lock.el -- font lock for factor code ;;; fuel-font-lock.el -- font lock for factor code
;; 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>
@ -99,5 +99,24 @@
fuel-syntax--syntactic-keywords)))))) fuel-syntax--syntactic-keywords))))))
;;; Fontify strings as Factor code:
(defvar fuel-font-lock--font-lock-buffer
(let ((buffer (get-buffer-create " *fuel font lock*")))
(set-buffer buffer)
(set-syntax-table fuel-syntax--syntax-table)
(fuel-font-lock--font-lock-setup)
buffer))
(defun fuel-font-lock--factor-str (str)
(save-current-buffer
(set-buffer fuel-font-lock--font-lock-buffer)
(erase-buffer)
(insert str)
(let ((font-lock-verbose nil)) (font-lock-fontify-buffer))
(buffer-string)))
(provide 'fuel-font-lock) (provide 'fuel-font-lock)
;;; fuel-font-lock.el ends here ;;; fuel-font-lock.el ends here

View File

@ -1,6 +1,6 @@
;;; fuel-help.el -- accessing Factor's help system ;;; fuel-help.el -- accessing Factor's help system
;; 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,12 +15,16 @@
;;; Code: ;;; Code:
(require 'fuel-eval) (require 'fuel-eval)
(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)
(require 'fuel-base) (require 'fuel-base)
(require 'button)
;;; Customization: ;;; Customization:
@ -33,37 +37,35 @@
:type 'boolean :type 'boolean
:group 'fuel-help) :group 'fuel-help)
(defcustom fuel-help-use-minibuffer t
"When enabled, use the minibuffer for short help messages."
:type 'boolean
:group 'fuel-help)
(defcustom fuel-help-mode-hook nil
"Hook run by `factor-help-mode'."
:type 'hook
:group 'fuel-help)
(defcustom fuel-help-history-cache-size 50 (defcustom fuel-help-history-cache-size 50
"Maximum number of pages to keep in the help browser cache." "Maximum number of pages to keep in the help browser cache."
:type 'integer :type 'integer
:group 'fuel-help) :group 'fuel-help)
(fuel-font-lock--defface fuel-font-lock-help-headlines (defcustom fuel-help-bookmarks nil
'bold fuel-hep "headlines in help buffers") "Bookmars. Maintain this list using the help browser."
:type 'list
:group 'fuel-help)
;;; Help browser history: ;;; Help browser history:
(defvar fuel-help--history (defun fuel-help--make-history ()
(list nil ; current (list nil ; current
(make-ring fuel-help-history-cache-size) ; previous (make-ring fuel-help-history-cache-size) ; previous
(make-ring fuel-help-history-cache-size))) ; next (make-ring fuel-help-history-cache-size))) ; next
(defun fuel-help--history-push (term) (defsubst fuel-help--history-current ()
(when (and (car fuel-help--history) (car fuel-help--history))
(not (string= (caar fuel-help--history) (car term))))
(ring-insert (nth 1 fuel-help--history) (car fuel-help--history))) (defun fuel-help--history-push (link)
(setcar fuel-help--history term)) (unless (equal link (car fuel-help--history))
(let ((next (fuel-help--history-next)))
(unless (equal link next)
(when next (fuel-help--history-previous))
(ring-insert (nth 1 fuel-help--history) (car fuel-help--history))
(setcar fuel-help--history link))))
link)
(defun fuel-help--history-next () (defun fuel-help--history-next ()
(when (not (ring-empty-p (nth 2 fuel-help--history))) (when (not (ring-empty-p (nth 2 fuel-help--history)))
@ -77,6 +79,25 @@
(ring-insert (nth 2 fuel-help--history) (car fuel-help--history))) (ring-insert (nth 2 fuel-help--history) (car fuel-help--history)))
(setcar fuel-help--history (ring-remove (nth 1 fuel-help--history) 0)))) (setcar fuel-help--history (ring-remove (nth 1 fuel-help--history) 0))))
(defvar fuel-help--history (fuel-help--make-history))
;;; Page cache:
(defun fuel-help--history-current-content ()
(fuel-help--cache-get (car fuel-help--history)))
(defvar fuel-help--cache (make-hash-table :weakness 'key :test 'equal))
(defsubst fuel-help--cache-get (name)
(gethash name fuel-help--cache))
(defsubst fuel-help--cache-insert (name str)
(puthash name str fuel-help--cache))
(defsubst fuel-help--cache-clear ()
(clrhash fuel-help--cache))
;;; Fuel help buffer and internals: ;;; Fuel help buffer and internals:
@ -86,121 +107,158 @@
(defvar fuel-help--prompt-history nil) (defvar fuel-help--prompt-history nil)
(defun fuel-help--show-help (&optional see word) (make-local-variable
(let* ((def (or word (fuel-syntax-symbol-at-point))) (defvar fuel-help--buffer-link nil))
(defun fuel-help--read-word (see)
(let* ((def (fuel-syntax-symbol-at-point))
(prompt (format "See%s help on%s: " (if see " short" "") (prompt (format "See%s help on%s: " (if see " short" "")
(if def (format " (%s)" def) ""))) (if def (format " (%s)" def) "")))
(ask (or (not (memq major-mode '(factor-mode fuel-help-mode))) (ask (or (not (memq major-mode '(factor-mode fuel-help-mode)))
(not def) (not def)
fuel-help-always-ask)) fuel-help-always-ask)))
(def (if ask (fuel-completion--read-word prompt (if ask (fuel-completion--read-word prompt
def def
'fuel-help--prompt-history 'fuel-help--prompt-history
t) t)
def)) def)))
(cmd `(:fuel* ((:quote ,def) ,(if see 'see 'help)) t)))
(defun fuel-help--word-help (&optional see word)
(let ((def (or word (fuel-help--read-word see))))
(when def
(let ((cmd `(:fuel* (,def ,(if see 'fuel-word-see 'fuel-word-help))
"fuel" t)))
(message "Looking up '%s' ..." def) (message "Looking up '%s' ..." def)
(fuel-eval--send cmd `(lambda (r) (fuel-help--show-help-cont ,def r))))) (let* ((ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(defun fuel-help--show-help-cont (def ret) (if (not res)
(let ((out (fuel-eval--retort-output ret)))
(if (or (fuel-eval--retort-error ret) (empty-string-p out))
(message "No help for '%s'" def) (message "No help for '%s'" def)
(fuel-help--insert-contents def out)))) (fuel-help--insert-contents (list def def 'word) res)))))))
(defun fuel-help--insert-contents (def str &optional nopush) (defun fuel-help--get-article (name label)
(message "Retrieving article ...")
(let* ((cmd `(:fuel* ((,name fuel-get-article)) "fuel" t))
(ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(if (not res)
(message "Article '%s' not found" label)
(fuel-help--insert-contents (list name label 'article) res)
(message ""))))
(defun fuel-help--get-vocab (name)
(message "Retrieving vocabulary help ...")
(let* ((cmd `(:fuel* ((,name fuel-vocab-help)) "fuel" (,name)))
(ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(if (not res)
(message "No help available for vocabulary '%s'" name)
(fuel-help--insert-contents (list name name 'vocab) res)
(message ""))))
(defun fuel-help--follow-link (link label type &optional no-cache)
(let* ((llink (list link label type))
(cached (and (not no-cache) (fuel-help--cache-get llink))))
(if (not cached)
(let ((fuel-help-always-ask nil))
(cond ((eq type 'word) (fuel-help--word-help nil link))
((eq type 'article) (fuel-help--get-article link label))
((eq type 'vocab) (fuel-help--get-vocab link))
((eq type 'bookmarks) (fuel-help-display-bookmarks))
(t (error "Links of type %s not yet implemented" type))))
(fuel-help--insert-contents llink cached))))
(defun fuel-help--insert-contents (key content)
(let ((hb (fuel-help--buffer)) (let ((hb (fuel-help--buffer))
(inhibit-read-only t) (inhibit-read-only t)
(font-lock-verbose nil)) (font-lock-verbose nil))
(set-buffer hb) (set-buffer hb)
(erase-buffer) (erase-buffer)
(insert str) (if (stringp content)
(unless nopush (insert content)
(goto-char (point-min)) (fuel-markup--print content)
(when (re-search-forward (format "^%s" def) nil t) (fuel-markup--insert-newline)
(beginning-of-line) (fuel-help--cache-insert key (buffer-string)))
(kill-region (point-min) (point)) (fuel-help--history-push key)
(fuel-help--history-push (cons def (buffer-string))))) (setq fuel-help--buffer-link key)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(fuel-popup--display) (fuel-popup--display)
(goto-char (point-min)) (goto-char (point-min))
(message "%s" def))) (message "")))
;;; Help mode font lock: ;;; Bookmarks:
(defconst fuel-help--headlines (defun fuel-help-bookmark-page ()
(regexp-opt '("Class description" "Add current help page to bookmarks."
"Definition" (interactive)
"Errors" (let ((link fuel-help--buffer-link))
"Examples" (unless link (error "No link associated to this page"))
"Generic word contract" (add-to-list 'fuel-help-bookmarks link)
"Inputs and outputs" (customize-save-variable 'fuel-help-bookmarks fuel-help-bookmarks)
"Methods" (message "Bookmark '%s' saved" (cadr link))))
"Notes"
"Parent topics:"
"See also"
"Syntax"
"Variable description"
"Variable value"
"Vocabulary"
"Warning"
"Word description")
t))
(defconst fuel-help--headlines-regexp (format "^%s" fuel-help--headlines)) (defun fuel-help-delete-bookmark ()
"Delete link at point from bookmarks."
(defconst fuel-help--font-lock-keywords (interactive)
`(,@fuel-font-lock--font-lock-keywords (let ((link (fuel-markup--link-at-point)))
(,fuel-help--headlines-regexp . 'fuel-font-lock-help-headlines))) (unless link (error "No link at point"))
(unless (member link fuel-help-bookmarks)
(error "'%s' is not bookmarked" (cadr link)))
(customize-save-variable 'fuel-help-bookmarks
(remove link fuel-help-bookmarks))
(message "Bookmark '%s' delete" (cadr link))
(fuel-help-display-bookmarks)))
(defun fuel-help-display-bookmarks ()
"Display bookmarked pages."
(interactive)
(let ((links (mapcar (lambda (l) (cons '$subsection l)) fuel-help-bookmarks)))
(unless links (error "No links to display"))
(fuel-help--insert-contents '("bookmarks" "Bookmars" bookmarks)
`(article "Bookmarks" ,links))))
;;; Interactive help commands: ;;; Interactive help commands:
(defun fuel-help-short (&optional arg) (defun fuel-help-short ()
"See a help summary of symbol at point. "See help summary of symbol at point."
By default, the information is shown in the minibuffer. When (interactive)
called with a prefix argument, the information is displayed in a (fuel-help--word-help t))
separate help buffer."
(interactive "P")
(if (if fuel-help-use-minibuffer (not arg) arg)
(fuel-help--word-synopsis)
(fuel-help--show-help t)))
(defun fuel-help () (defun fuel-help ()
"Show extended help about the symbol at point, using a help "Show extended help about the symbol at point, using a help
buffer." buffer."
(interactive) (interactive)
(fuel-help--show-help)) (fuel-help--word-help))
(defun fuel-help-next () (defun fuel-help-next ()
"Go to next page in help browser." "Go to next page in help browser."
(interactive) (interactive)
(let ((item (fuel-help--history-next)) (let ((item (fuel-help--history-next)))
(fuel-help-always-ask nil)) (unless item (error "No next page"))
(unless item (apply 'fuel-help--follow-link item)))
(error "No next page"))
(fuel-help--insert-contents (car item) (cdr item) t)))
(defun fuel-help-previous () (defun fuel-help-previous ()
"Go to next page in help browser." "Go to previous page in help browser."
(interactive) (interactive)
(let ((item (fuel-help--history-previous)) (let ((item (fuel-help--history-previous)))
(fuel-help-always-ask nil)) (unless item (error "No previous page"))
(unless item (apply 'fuel-help--follow-link item)))
(error "No previous page"))
(fuel-help--insert-contents (car item) (cdr item) t)))
(defun fuel-help-next-headline (&optional count) (defun fuel-help-refresh ()
(interactive "P") "Refresh the contents of current page."
(end-of-line) (interactive)
(when (re-search-forward fuel-help--headlines-regexp nil t (or count 1)) (when fuel-help--buffer-link
(beginning-of-line))) (apply 'fuel-help--follow-link (append fuel-help--buffer-link '(t)))))
(defun fuel-help-previous-headline (&optional count) (defun fuel-help-clean-history ()
(interactive "P") "Clean up the help browser cache of visited pages."
(re-search-backward fuel-help--headlines-regexp nil t count)) (interactive)
(when (y-or-n-p "Clean browsing history? ")
(fuel-help--cache-clear)
(setq fuel-help--history (fuel-help--make-history))
(fuel-help-refresh))
(message ""))
;;;; Help mode map: ;;;; Help mode map:
@ -208,15 +266,16 @@ buffer."
(defvar fuel-help-mode-map (defvar fuel-help-mode-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(suppress-keymap map) (suppress-keymap map)
(define-key map "\C-m" 'fuel-help) (set-keymap-parent map button-buffer-map)
(define-key map "b" 'fuel-help-previous) (define-key map "a" 'fuel-apropos)
(define-key map "f" 'fuel-help-next) (define-key map "ba" 'fuel-help-bookmark-page)
(define-key map "l" 'fuel-help-previous) (define-key map "bb" 'fuel-help-display-bookmarks)
(define-key map "p" 'fuel-help-previous) (define-key map "bd" 'fuel-help-delete-bookmark)
(define-key map "c" 'fuel-help-clean-history)
(define-key map "h" 'fuel-help)
(define-key map "n" 'fuel-help-next) (define-key map "n" 'fuel-help-next)
(define-key map (kbd "TAB") 'fuel-help-next-headline) (define-key map "p" 'fuel-help-previous)
(define-key map (kbd "S-TAB") 'fuel-help-previous-headline) (define-key map "r" 'fuel-help-refresh)
(define-key map [(backtab)] 'fuel-help-previous-headline)
(define-key map (kbd "SPC") 'scroll-up) (define-key map (kbd "SPC") 'scroll-up)
(define-key map (kbd "S-SPC") 'scroll-down) (define-key map (kbd "S-SPC") 'scroll-down)
(define-key map "\M-." 'fuel-edit-word-at-point) (define-key map "\M-." 'fuel-edit-word-at-point)
@ -234,16 +293,10 @@ buffer."
(kill-all-local-variables) (kill-all-local-variables)
(buffer-disable-undo) (buffer-disable-undo)
(use-local-map fuel-help-mode-map) (use-local-map fuel-help-mode-map)
(set-syntax-table fuel-syntax--syntax-table)
(setq mode-name "FUEL Help") (setq mode-name "FUEL Help")
(setq major-mode 'fuel-help-mode) (setq major-mode 'fuel-help-mode)
(setq fuel-markup--follow-link-function 'fuel-help--follow-link)
(fuel-font-lock--font-lock-setup fuel-help--font-lock-keywords t)
(setq fuel-autodoc-mode-string "")
(fuel-autodoc-mode)
(run-mode-hooks 'fuel-help-mode-hook)
(setq buffer-read-only t)) (setq buffer-read-only t))

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)

479
misc/fuel/fuel-markup.el Normal file
View File

@ -0,0 +1,479 @@
;;; fuel-markup.el -- printing factor help markup
;; Copyright (C) 2009 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: Thu Jan 01, 2009 21:43
;;; Comentary:
;; Utilities for printing Factor's help markup.
;;; Code:
(require 'fuel-eval)
(require 'fuel-font-lock)
(require 'fuel-base)
(require 'button)
(require 'table)
;;; Customization:
(fuel-font-lock--defface fuel-font-lock-markup-title
'bold fuel-help "article titles in help buffers")
(fuel-font-lock--defface fuel-font-lock-markup-heading
'bold fuel-help "headlines in help buffers")
(fuel-font-lock--defface fuel-font-lock-markup-link
'link fuel-help "links to topics in help buffers")
(fuel-font-lock--defface fuel-font-lock-markup-emphasis
'italic fuel-help "emphasized words in help buffers")
(fuel-font-lock--defface fuel-font-lock-markup-strong
'link fuel-help "bold words in help buffers")
;;; Links:
(make-variable-buffer-local
(defvar fuel-markup--follow-link-function 'fuel-markup--echo-link))
(define-button-type 'fuel-markup--button
'action 'fuel-markup--follow-link
'face 'fuel-font-lock-markup-link
'follow-link t)
(defun fuel-markup--follow-link (button)
(when fuel-markup--follow-link-function
(funcall fuel-markup--follow-link-function
(button-get button 'markup-link)
(button-get button 'markup-label)
(button-get button 'markup-link-type))))
(defun fuel-markup--echo-link (link label type)
(message "Link %s pointing to %s named %s" label type link))
(defun fuel-markup--insert-button (label link type)
(let ((label (format "%s" label))
(link (format "%s" link)))
(insert-text-button label
:type 'fuel-markup--button
'markup-link link
'markup-label label
'markup-link-type type
'help-echo (format "%s (%s)" label type))))
(defun fuel-markup--article-title (name)
(fuel-eval--retort-result
(fuel-eval--send/wait `(:fuel* ((,name fuel-article-title :get)) "fuel"))))
(defun fuel-markup--link-at-point ()
(let ((button (condition-case nil (forward-button 0) (error nil))))
(when button
(list (button-get button 'markup-link)
(button-get button 'markup-label)
(button-get button 'markup-link-type)))))
;;; Markup printers:
(defconst fuel-markup--printers
'(($class-description . fuel-markup--class-description)
($code . fuel-markup--code)
($command . fuel-markup--command)
($contract . fuel-markup--contract)
($curious . fuel-markup--curious)
($definition . fuel-markup--definition)
($description . fuel-markup--description)
($doc-path . fuel-markup--doc-path)
($emphasis . fuel-markup--emphasis)
($error-description . fuel-markup--error-description)
($errors . fuel-markup--errors)
($example . fuel-markup--example)
($examples . fuel-markup--examples)
($heading . fuel-markup--heading)
($index . fuel-markup--index)
($instance . fuel-markup--instance)
($io-error . fuel-markup--io-error)
($link . fuel-markup--link)
($links . fuel-markup--links)
($list . fuel-markup--list)
($low-level-note . fuel-markup--low-level-note)
($markup-example . fuel-markup--markup-example)
($maybe . fuel-markup--maybe)
($methods . fuel-markup--methods)
($nl . fuel-markup--newline)
($notes . fuel-markup--notes)
($parsing-note . fuel-markup--parsing-note)
($predicate . fuel-markup--predicate)
($prettyprinting-note . fuel-markup--prettyprinting-note)
($quotation . fuel-markup--quotation)
($references . fuel-markup--references)
($related . fuel-markup--related)
($see . fuel-markup--see)
($see-also . fuel-markup--see-also)
($shuffle . fuel-markup--shuffle)
($side-effects . fuel-markup--side-effects)
($slot . fuel-markup--snippet)
($snippet . fuel-markup--snippet)
($strong . fuel-markup--strong)
($subheading . fuel-markup--subheading)
($subsection . fuel-markup--subsection)
($synopsis . fuel-markup--synopsis)
($syntax . fuel-markup--syntax)
($table . fuel-markup--table)
($unchecked-example . fuel-markup--example)
($value . fuel-markup--value)
($values . fuel-markup--values)
($values-x/y . fuel-markup--values-x/y)
($var-description . fuel-markup--var-description)
($vocab-link . fuel-markup--vocab-link)
($vocab-links . fuel-markup--vocab-links)
($vocab-subsection . fuel-markup--vocab-subsection)
($vocabulary . fuel-markup--vocabulary)
($warning . fuel-markup--warning)
(article . fuel-markup--article)))
(make-variable-buffer-local
(defvar fuel-markup--maybe-nl nil))
(defun fuel-markup--print (e)
(cond ((null e))
((stringp e) (fuel-markup--insert-string e))
((and (listp e) (symbolp (car e))
(assoc (car e) fuel-markup--printers))
(funcall (cdr (assoc (car e) fuel-markup--printers)) e))
((and (symbolp e)
(assoc e fuel-markup--printers))
(funcall (cdr (assoc e fuel-markup--printers)) e))
((listp e) (mapc 'fuel-markup--print e))
((symbolp e) (fuel-markup--print (list '$link e)))
(t (insert (format "\n%S\n" e)))))
(defun fuel-markup--print-str (e)
(with-temp-buffer
(fuel-markup--print e)
(buffer-string)))
(defun fuel-markup--maybe-nl ()
(setq fuel-markup--maybe-nl (point)))
(defun fuel-markup--insert-newline (&optional justification)
(fill-region (save-excursion (beginning-of-line) (point))
(point)
(or justification 'left))
(newline))
(defsubst fuel-markup--insert-nl-if-nb (&optional no-fill)
(unless (eq (save-excursion (beginning-of-line) (point)) (point))
(if no-fill (newline) (fuel-markup--insert-newline))))
(defsubst fuel-markup--put-face (txt face)
(put-text-property 0 (length txt) 'font-lock-face face txt)
txt)
(defun fuel-markup--insert-heading (txt &optional no-nl)
(fuel-markup--insert-nl-if-nb)
(unless (bobp) (newline))
(fuel-markup--put-face txt 'fuel-font-lock-markup-heading)
(fuel-markup--insert-string txt)
(unless no-nl (newline)))
(defun fuel-markup--insert-string (str)
(when fuel-markup--maybe-nl
(newline 2)
(setq fuel-markup--maybe-nl nil))
(insert str))
(defun fuel-markup--article (e)
(setq fuel-markup--maybe-nl nil)
(insert (fuel-markup--put-face (cadr e) 'fuel-font-lock-markup-title))
(newline 2)
(fuel-markup--print (car (cddr e))))
(defun fuel-markup--heading (e)
(fuel-markup--insert-heading (cadr e)))
(defun fuel-markup--subheading (e)
(fuel-markup--insert-heading (cadr e)))
(defun fuel-markup--subsection (e)
(fuel-markup--insert-nl-if-nb)
(insert " - ")
(fuel-markup--link (cons '$link (cdr e)))
(fuel-markup--maybe-nl))
(defun fuel-markup--vocab-subsection (e)
(fuel-markup--insert-nl-if-nb)
(insert " - ")
(fuel-markup--vocab-link (cons '$vocab-link (cdr e)))
(fuel-markup--maybe-nl))
(defun fuel-markup--newline (e)
(fuel-markup--insert-newline)
(newline))
(defun fuel-markup--doc-path (e)
(fuel-markup--insert-heading "Related topics")
(insert " ")
(dolist (art (cdr e))
(fuel-markup--insert-button (car art) (cadr art) 'article)
(insert ", "))
(delete-backward-char 2)
(fuel-markup--insert-newline 'left))
(defun fuel-markup--emphasis (e)
(when (stringp (cadr e))
(fuel-markup--put-face (cadr e) 'fuel-font-lock-markup-emphasis)
(insert (cadr e))))
(defun fuel-markup--strong (e)
(when (stringp (cadr e))
(fuel-markup--put-face (cadr e) 'fuel-font-lock-markup-strong)
(insert (cadr e))))
(defun fuel-markup--snippet (e)
(let ((snip (format "%s" (cdr e))))
(insert (fuel-font-lock--factor-str snip))))
(defun fuel-markup--code (e)
(fuel-markup--insert-nl-if-nb)
(newline)
(dolist (snip (cdr e))
(if (stringp snip)
(insert (fuel-font-lock--factor-str snip))
(fuel-markup--print snip))
(newline))
(newline))
(defun fuel-markup--command (e)
(fuel-markup--snippet (list '$snippet (nth 3 e))))
(defun fuel-markup--syntax (e)
(fuel-markup--insert-heading "Syntax")
(fuel-markup--print (cons '$code (cdr e)))
(newline))
(defun fuel-markup--examples (e)
(fuel-markup--insert-heading "Examples")
(dolist (ex (cdr e))
(fuel-markup--print ex)
(newline)))
(defun fuel-markup--example (e)
(fuel-markup--snippet (list '$snippet (cadr e))))
(defun fuel-markup--markup-example (e)
(fuel-markup--snippet (cons '$snippet (cadr e))))
(defun fuel-markup--link (e)
(let* ((link (nth 1 e))
(type (or (nth 3 e) (if (symbolp link) 'word 'article)))
(label (or (nth 2 e)
(and (eq type 'article)
(fuel-markup--article-title link))
link)))
(fuel-markup--insert-button label link type)))
(defun fuel-markup--links (e)
(dolist (link (cdr e))
(fuel-markup--link (list '$link link))
(insert ", "))
(delete-backward-char 2))
(defun fuel-markup--index-quotation (q)
(cond ((null q) null)
((listp q) (vconcat (mapcar 'fuel-markup--index-quotation q)))
(t q)))
(defun fuel-markup--index (e)
(let* ((q (fuel-markup--index-quotation (cadr e)))
(cmd `(:fuel* ((,q fuel-index)) "fuel"
("builtins" "help" "help.topics" "classes"
"classes.builtin" "classes.tuple"
"classes.singleton" "classes.union"
"classes.intersection" "classes.predicate")))
(subs (fuel-eval--retort-result (fuel-eval--send/wait cmd 200))))
(when subs
(fuel-markup--print subs))))
(defun fuel-markup--vocab-link (e)
(fuel-markup--insert-button (cadr e) (cadr e) 'vocab))
(defun fuel-markup--vocab-links (e)
(dolist (link (cdr e))
(insert " ")
(fuel-markup--vocab-link (list '$vocab-link link))
(insert " ")))
(defun fuel-markup--vocabulary (e)
(fuel-markup--insert-heading "Vocabulary: " t)
(fuel-markup--vocab-link (cons '$vocab-link (cdr e)))
(newline))
(defun fuel-markup--list (e)
(fuel-markup--insert-nl-if-nb)
(dolist (elt (cdr e))
(insert " - ")
(fuel-markup--print elt)
(fuel-markup--insert-newline)))
(defun fuel-markup--table (e)
(fuel-markup--insert-newline)
(newline)
(let ((start (point))
(col-delim "<~end-of-col~>")
(col-no (length (cadr e))))
(dolist (row (cdr e))
(dolist (col row)
(fuel-markup--print col)
(insert col-delim)))
(table-capture start (point)
col-delim nil nil
(/ (- (window-width) 10) col-no) col-no))
(goto-char (point-max))
(table-recognize -1)
(newline))
(defun fuel-markup--instance (e)
(insert " an instance of ")
(fuel-markup--print (cadr e)))
(defun fuel-markup--maybe (e)
(fuel-markup--instance (cons '$instance (cdr e)))
(insert " or f "))
(defun fuel-markup--values (e)
(fuel-markup--insert-heading "Inputs and outputs")
(dolist (val (cdr e))
(insert " " (car val) " - ")
(fuel-markup--print (cdr val))
(newline)))
(defun fuel-markup--predicate (e)
(fuel-markup--values '($values ("object" object) ("?" "a boolean")))
(let ((word (make-symbol (substring (format "%s" (cadr e)) 0 -1))))
(fuel-markup--description
`($description "Tests if the object is an instance of the "
($link ,word) " class."))))
(defun fuel-markup--side-effects (e)
(fuel-markup--insert-heading "Side effects")
(insert "Modifies ")
(fuel-markup--print (cdr e))
(fuel-markup--insert-newline))
(defun fuel-markup--definition (e)
(fuel-markup--insert-heading "Definition")
(fuel-markup--code (cons '$code (cdr e))))
(defun fuel-markup--methods (e)
(fuel-markup--insert-heading "Methods")
(fuel-markup--code (cons '$code (cdr e))))
(defun fuel-markup--value (e)
(fuel-markup--insert-heading "Variable value")
(insert "Current value in global namespace: ")
(fuel-markup--snippet (cons '$snippet (cdr e)))
(newline))
(defun fuel-markup--values-x/y (e)
(fuel-markup--values '($values ("x" "number") ("y" "number"))))
(defun fuel-markup--curious (e)
(fuel-markup--insert-heading "For the curious...")
(fuel-markup--print (cdr e)))
(defun fuel-markup--references (e)
(fuel-markup--insert-heading "References")
(dolist (ref (cdr e))
(if (listp ref)
(fuel-markup--print ref)
(fuel-markup--subsection (list '$subsection ref)))))
(defun fuel-markup--see-also (e)
(fuel-markup--insert-heading "See also")
(fuel-markup--links (cons '$links (cdr e))))
(defun fuel-markup--related (e)
(fuel-markup--insert-heading "See also")
(fuel-markup--links (cons '$links (cadr e))))
(defun fuel-markup--shuffle (e)
(insert "\nShuffle word. Re-arranges the stack "
"according to the stack effect pattern.")
(fuel-markup--insert-newline))
(defun fuel-markup--low-level-note (e)
(fuel-markup--print '($notes "Calling this word directly is not necessary "
"in most cases. "
"Higher-level words call it automatically.")))
(defun fuel-markup--parsing-note (e)
(fuel-markup--insert-nl-if-nb)
(insert "This word should only be called from parsing words.")
(fuel-markup--insert-newline))
(defun fuel-markup--io-error (e)
(fuel-markup--errors '($errors "Throws an error if the I/O operation fails.")))
(defun fuel-markup--prettyprinting-note (e)
(fuel-markup--print '($notes ("This word should only be called within the "
($link with-pprint) " combinator."))))
(defun fuel-markup--elem-with-heading (elem heading)
(fuel-markup--insert-heading heading)
(fuel-markup--print (cdr elem))
(fuel-markup--insert-newline))
(defun fuel-markup--quotation (e)
(insert "a ")
(fuel-markup--link (list '$link 'quotation 'quotation 'word))
(insert " with stack effect ")
(fuel-markup--snippet (list '$snippet (nth 1 e))))
(defun fuel-markup--warning (e)
(fuel-markup--elem-with-heading e "Warning"))
(defun fuel-markup--description (e)
(fuel-markup--elem-with-heading e "Word description"))
(defun fuel-markup--class-description (e)
(fuel-markup--elem-with-heading e "Class description"))
(defun fuel-markup--error-description (e)
(fuel-markup--elem-with-heading e "Error description"))
(defun fuel-markup--var-description (e)
(fuel-markup--elem-with-heading e "Variable description"))
(defun fuel-markup--contract (e)
(fuel-markup--elem-with-heading e "Generic word contract"))
(defun fuel-markup--errors (e)
(fuel-markup--elem-with-heading e "Errors"))
(defun fuel-markup--notes (e)
(fuel-markup--elem-with-heading e "Notes"))
(defun fuel-markup--see (e)
(let* ((word (nth 1 e))
(cmd (and word `(:fuel* (,(format "%s" word) fuel-word-see) "fuel" t)))
(res (and cmd
(fuel-eval--retort-result (fuel-eval--send/wait cmd 100)))))
(if res
(fuel-markup--code (list '$code res))
(fuel-markup--snippet (list '$snippet word)))))
(defun fuel-markup--synopsis (e)
(insert (format " %S " e)))
(provide 'fuel-markup)
;;; fuel-markup.el ends here

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

@ -157,19 +157,26 @@
table)) table))
(defconst fuel-syntax--syntactic-keywords (defconst fuel-syntax--syntactic-keywords
`(("\\_<\\(#?!\\) .*\\(\n\\)" (1 "<") (2 ">")) `(;; Comments:
("\\_<\\(#?!\\)\\(\n\\)" (1 "<") (2 ">")) ("\\_<\\(#?!\\) .*\\(\n\\|$\\)" (1 "<") (2 ">"))
("\\_<\\(#?!\\)\\(\n\\|$\\)" (1 "<") (2 ">"))
;; CHARs:
("CHAR: \\(.\\)\\( \\|$\\)" (1 "w"))
;; Let and lambda:
("\\_<\\(!(\\) .* \\()\\)" (1 "<") (2 ">")) ("\\_<\\(!(\\) .* \\()\\)" (1 "<") (2 ">"))
("\\(\\[\\)\\(let\\|wlet\\|let\\*\\)\\( \\|$\\)" (1 "(]")) ("\\(\\[\\)\\(let\\|wlet\\|let\\*\\)\\( \\|$\\)" (1 "(]"))
("\\(\\[\\)\\(|\\) +[^|]* \\(|\\)" (1 "(]") (2 "(|") (3 ")|")) ("\\(\\[\\)\\(|\\) +[^|]* \\(|\\)" (1 "(]") (2 "(|") (3 ")|"))
(" \\(|\\) " (1 "(|")) (" \\(|\\) " (1 "(|"))
(" \\(|\\)$" (1 ")")) (" \\(|\\)$" (1 ")"))
("CHAR: \\(\"\\)\\( \\|$\\)" (1 "w")) ;; Opening brace words:
(,(format "\\_<%s\\({\\)\\_>" (regexp-opt fuel-syntax--bracers)) (1 "(}")) (,(format "\\_<%s\\({\\)\\_>" (regexp-opt fuel-syntax--bracers)) (1 "(}"))
("\\_<\\({\\)\\_>" (1 "(}")) ("\\_<\\({\\)\\_>" (1 "(}"))
("\\_<\\(}\\)\\_>" (1 "){")) ("\\_<\\(}\\)\\_>" (1 "){"))
;; Parenthesis:
("\\_<\\((\\)\\_>" (1 "()")) ("\\_<\\((\\)\\_>" (1 "()"))
("\\_<\\()\\)\\_>" (1 ")(")) ("\\_<\\()\\)\\_>" (1 ")("))
;; Quotations:
("\\_<'\\(\\[\\)\\_>" (1 "(]")) ; fried
("\\_<\\(\\[\\)\\_>" (1 "(]")) ("\\_<\\(\\[\\)\\_>" (1 "(]"))
("\\_<\\(\\]\\)\\_>" (1 ")[")))) ("\\_<\\(\\]\\)\\_>" (1 ")["))))
@ -294,21 +301,9 @@
(funcall fuel-syntax--current-vocab-function)) (funcall fuel-syntax--current-vocab-function))
(defun fuel-syntax--find-in () (defun fuel-syntax--find-in ()
(let* ((vocab)
(ip
(save-excursion (save-excursion
(when (re-search-backward fuel-syntax--current-vocab-regex nil t) (when (re-search-backward fuel-syntax--current-vocab-regex nil t)
(setq vocab (match-string-no-properties 1)) (match-string-no-properties 1))))
(point)))))
(when ip
(let ((pp (save-excursion
(when (re-search-backward fuel-syntax--sub-vocab-regex ip t)
(point)))))
(when (and pp (> pp ip))
(let ((sub (match-string-no-properties 1)))
(unless (save-excursion (search-backward (format "%s>" sub) pp t))
(setq vocab (format "%s.%s" vocab (downcase sub))))))))
vocab))
(make-variable-buffer-local (make-variable-buffer-local
(defvar fuel-syntax--usings-function 'fuel-syntax--find-usings)) (defvar fuel-syntax--usings-function 'fuel-syntax--find-usings))
@ -316,13 +311,19 @@
(defsubst fuel-syntax--usings () (defsubst fuel-syntax--usings ()
(funcall fuel-syntax--usings-function)) (funcall fuel-syntax--usings-function))
(defun fuel-syntax--find-usings () (defun fuel-syntax--find-usings (&optional no-private)
(save-excursion (save-excursion
(let ((usings)) (let ((usings))
(goto-char (point-max)) (goto-char (point-max))
(while (re-search-backward fuel-syntax--using-lines-regex nil t) (while (re-search-backward fuel-syntax--using-lines-regex nil t)
(dolist (u (split-string (match-string-no-properties 1) nil t)) (dolist (u (split-string (match-string-no-properties 1) nil t))
(push u usings))) (push u usings)))
(goto-char (point-min))
(when (and (not no-private)
(re-search-forward "\\_<<PRIVATE\\_>" nil t)
(re-search-forward "\\_<PRIVATE>\\_>" nil t))
(goto-char (point-max))
(push (concat (fuel-syntax--find-in) ".private") usings))
usings))) usings)))

View File

@ -1,6 +1,6 @@
;;; fuel-xref.el -- showing cross-reference info ;;; fuel-xref.el -- showing cross-reference info
;; 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>
@ -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:
@ -138,7 +142,6 @@ cursor at the first ocurrence of the used word."
(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 "q" 'bury-buffer)
map)) map))
(defun fuel-xref-mode () (defun fuel-xref-mode ()