]> gitweb.factorcode.org Git - factor.git/blob - basis/editors/editors.factor
Rename vocab to lookup-vocab
[factor.git] / basis / editors / editors.factor
1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs continuations debugger definitions
4 help.topics io io.backend io.files io.pathnames kernel lexer
5 namespaces parser prettyprint sequences source-files
6 source-files.errors splitting strings summary tools.crossref
7 vocabs vocabs.files vocabs.hierarchy vocabs.loader
8 vocabs.metadata ;
9 FROM: vocabs => vocab-name >vocab-link ;
10 IN: editors
11
12 TUPLE: no-edit-hook ;
13
14 M: no-edit-hook summary
15     drop "You must load one of the below vocabularies before using editor integration:" ;
16
17 SYMBOL: edit-hook
18
19 : available-editors ( -- seq )
20     "editors" child-vocab-names ;
21
22 : editor-restarts ( -- alist )
23     available-editors
24     [ [ "Load " prepend ] keep ] { } map>assoc ;
25
26 : no-edit-hook ( -- )
27     \ no-edit-hook new
28     editor-restarts throw-restarts
29     require ;
30
31 : edit-location ( file line -- )
32     [ absolute-path ] dip edit-hook get-global
33     [ call( file line -- ) ] [ no-edit-hook edit-location ] if* ;
34
35 ERROR: cannot-find-source definition ;
36
37 M: cannot-find-source error.
38     "Cannot find source for ``" write
39     definition>> pprint-short
40     "''" print ;
41
42 GENERIC: edit ( object -- )
43
44 M: object edit
45     dup where [ first2 edit-location ] [ cannot-find-source ] ?if ;
46
47 M: link edit name>> edit ;
48
49 M: string edit
50     dup lookup-vocab [ edit ] [ cannot-find-source ] ?if ;
51
52 : edit-error ( error -- )
53     [ error-file ] [ error-line ] bi
54     over [ 1 or edit-location ] [ 2drop ] if ;
55
56 : :edit ( -- )
57     error get edit-error ;
58
59 : edit-each ( seq -- )
60     [
61         [ "Editing " write . ]
62         [
63             "RETURN moves on to the next usage, C+d stops." print
64             flush
65             edit
66             readln
67         ] bi
68     ] all? drop ;
69
70 : fix ( word -- )
71     [ "Fixing " write pprint " and all usages..." print nl ]
72     [ [ smart-usage ] keep prefix ] bi
73     edit-each ;
74
75 : edit-docs ( vocab -- )
76     vocab-docs-path 1 edit-location ;
77
78 : edit-tests ( vocab -- )
79     vocab-tests-file 1 edit-location ;
80
81 : edit-platforms ( vocab -- )
82     dup vocab-platforms-path vocab-append-path 1 edit-location ;
83
84 : edit-authors ( vocab -- )
85     dup vocab-authors-path vocab-append-path 1 edit-location ;
86
87 : edit-tags ( vocab -- )
88     dup vocab-tags-path vocab-append-path 1 edit-location ;
89
90 : edit-summary ( vocab -- )
91     dup vocab-summary-path vocab-append-path 1 edit-location ;
92