2009-02-12 03:19:31 -05:00
|
|
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-05-04 07:44:17 -04:00
|
|
|
USING: parser lexer kernel namespaces sequences definitions
|
|
|
|
io.files io.backend io.pathnames io summary continuations
|
|
|
|
tools.crossref vocabs.hierarchy prettyprint source-files
|
2009-07-06 05:55:23 -04:00
|
|
|
source-files.errors assocs vocabs.loader splitting
|
2009-05-14 17:54:16 -04:00
|
|
|
accessors debugger help.topics ;
|
2009-07-06 05:55:23 -04:00
|
|
|
FROM: vocabs => vocab-name >vocab-link ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: editors
|
|
|
|
|
|
|
|
TUPLE: no-edit-hook ;
|
|
|
|
|
2007-11-25 04:33:46 -05:00
|
|
|
M: no-edit-hook summary
|
|
|
|
drop "You must load one of the below vocabularies before using editor integration:" ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
SYMBOL: edit-hook
|
|
|
|
|
2007-11-25 04:33:46 -05:00
|
|
|
: available-editors ( -- seq )
|
2009-07-06 05:55:23 -04:00
|
|
|
"editors" child-vocabs no-roots no-prefixes [ vocab-name ] map ;
|
2007-11-25 04:33:46 -05:00
|
|
|
|
|
|
|
: editor-restarts ( -- alist )
|
|
|
|
available-editors
|
2008-04-04 05:12:25 -04:00
|
|
|
[ [ "Load " prepend ] keep ] { } map>assoc ;
|
2007-11-25 04:33:46 -05:00
|
|
|
|
|
|
|
: no-edit-hook ( -- )
|
2008-04-13 16:06:27 -04:00
|
|
|
\ no-edit-hook new
|
2007-11-25 04:33:46 -05:00
|
|
|
editor-restarts throw-restarts
|
|
|
|
require ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: edit-location ( file line -- )
|
2008-11-29 14:29:19 -05:00
|
|
|
[ (normalize-path) ] dip edit-hook get-global
|
2009-03-17 03:19:50 -04:00
|
|
|
[ call( file line -- ) ] [ no-edit-hook edit-location ] if* ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-02-12 03:19:31 -05:00
|
|
|
ERROR: cannot-find-source definition ;
|
|
|
|
|
|
|
|
M: cannot-find-source error.
|
|
|
|
"Cannot find source for ``" write
|
|
|
|
definition>> pprint-short
|
|
|
|
"''" print ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: edit ( defspec -- )
|
2009-02-12 03:19:31 -05:00
|
|
|
dup where
|
|
|
|
[ first2 edit-location ]
|
|
|
|
[ dup word-link? [ name>> edit ] [ cannot-find-source ] if ]
|
|
|
|
?if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-24 18:40:28 -05:00
|
|
|
: edit-vocab ( name -- )
|
2009-02-12 03:19:31 -05:00
|
|
|
>vocab-link edit ;
|
2008-02-24 18:40:28 -05:00
|
|
|
|
2009-08-04 22:01:21 -04:00
|
|
|
: edit-error ( error -- )
|
2008-11-24 13:29:24 -05:00
|
|
|
[ error-file ] [ error-line ] bi
|
2008-06-25 04:25:08 -04:00
|
|
|
2dup and [ edit-location ] [ 2drop ] if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-11-24 13:29:24 -05:00
|
|
|
: :edit ( -- )
|
2009-08-04 22:01:21 -04:00
|
|
|
error get edit-error ;
|
2009-04-09 00:05:45 -04:00
|
|
|
|
2008-06-08 16:32:55 -04:00
|
|
|
: edit-each ( seq -- )
|
2008-04-04 05:12:25 -04:00
|
|
|
[
|
|
|
|
[ "Editing " write . ]
|
|
|
|
[
|
|
|
|
"RETURN moves on to the next usage, C+d stops." print
|
|
|
|
flush
|
|
|
|
edit
|
|
|
|
readln
|
|
|
|
] bi
|
2007-09-20 18:09:08 -04:00
|
|
|
] all? drop ;
|
2008-06-08 16:32:55 -04:00
|
|
|
|
|
|
|
: fix ( word -- )
|
|
|
|
[ "Fixing " write pprint " and all usages..." print nl ]
|
|
|
|
[ [ smart-usage ] keep prefix ] bi
|
|
|
|
edit-each ;
|