factor/extra/editors/editors.factor

53 lines
1.5 KiB
Factor
Raw Normal View History

2008-03-26 15:55:04 -04:00
! Copyright (C) 2005, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: parser kernel namespaces sequences definitions io.files
inspector continuations tools.crossref tools.vocabs
2008-03-26 15:55:04 -04:00
io prettyprint source-files assocs vocabs vocabs.loader
io.backend splitting classes.tuple ;
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 )
2008-03-13 04:35:54 -04:00
"editors" all-child-vocabs-seq [ vocab-name ] map ;
: editor-restarts ( -- alist )
available-editors
[ "Load " over append swap ] { } map>assoc ;
: no-edit-hook ( -- )
\ no-edit-hook construct-empty
editor-restarts throw-restarts
require ;
2007-09-20 18:09:08 -04:00
: edit-location ( file line -- )
>r (normalize-path) "\\\\?\\" ?head drop r>
2008-03-27 19:00:55 -04:00
edit-hook get [ call ] [ no-edit-hook edit-location ] if* ;
2007-09-20 18:09:08 -04:00
: edit ( defspec -- )
where [ first2 edit-location ] when* ;
2008-02-24 18:40:28 -05:00
: edit-vocab ( name -- )
vocab-source-path 1 edit-location ;
2007-09-20 18:09:08 -04:00
: :edit ( -- )
error get delegates [ parse-error? ] find-last nip [
dup parse-error-file source-file-path
2007-09-20 18:09:08 -04:00
swap parse-error-line edit-location
] when* ;
: fix ( word -- )
"Fixing " write dup pprint " and all usages..." print nl
dup usage swap prefix [
2007-09-20 18:09:08 -04:00
"Editing " write dup .
"RETURN moves on to the next usage, C+d stops." print
flush
edit
readln
] all? drop ;