factor/basis/editors/editors.factor

93 lines
2.3 KiB
Factor
Raw Normal View History

! Copyright (C) 2005, 2009 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs continuations debugger definitions
help.topics io io.backend io.files io.pathnames kernel lexer
namespaces parser prettyprint sequences source-files
source-files.errors splitting strings summary tools.crossref
vocabs vocabs.files vocabs.hierarchy vocabs.loader
vocabs.metadata ;
FROM: vocabs => vocab-name >vocab-link ;
2007-09-20 18:09:08 -04:00
IN: editors
TUPLE: no-edit-hook ;
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
: available-editors ( -- seq )
2011-10-14 15:31:06 -04:00
"editors" child-vocab-names ;
: editor-restarts ( -- alist )
available-editors
[ [ "Load " prepend ] keep ] { } map>assoc ;
: no-edit-hook ( -- )
\ no-edit-hook new
editor-restarts throw-restarts
require ;
2007-09-20 18:09:08 -04:00
: edit-location ( file line -- )
[ absolute-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
ERROR: cannot-find-source definition ;
M: cannot-find-source error.
"Cannot find source for ``" write
definition>> pprint-short
"''" print ;
GENERIC: edit ( object -- )
2007-09-20 18:09:08 -04:00
M: object edit
dup where [ first2 edit-location ] [ cannot-find-source ] ?if ;
M: link edit name>> edit ;
M: string edit
2011-10-24 06:37:47 -04:00
dup lookup-vocab [ edit ] [ cannot-find-source ] ?if ;
2008-02-24 18:40:28 -05:00
: edit-error ( error -- )
2008-11-24 13:29:24 -05:00
[ error-file ] [ error-line ] bi
over [ 1 or edit-location ] [ 2drop ] if ;
2007-09-20 18:09:08 -04:00
2008-11-24 13:29:24 -05:00
: :edit ( -- )
error get edit-error ;
2008-06-08 16:32:55 -04:00
: edit-each ( seq -- )
[
[ "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 ;
: edit-docs ( vocab -- )
vocab-docs-path 1 edit-location ;
: edit-tests ( vocab -- )
vocab-tests-file 1 edit-location ;
: edit-platforms ( vocab -- )
dup vocab-platforms-path vocab-append-path 1 edit-location ;
: edit-authors ( vocab -- )
dup vocab-authors-path vocab-append-path 1 edit-location ;
: edit-tags ( vocab -- )
dup vocab-tags-path vocab-append-path 1 edit-location ;
: edit-summary ( vocab -- )
dup vocab-summary-path vocab-append-path 1 edit-location ;