]> gitweb.factorcode.org Git - factor.git/blob - extra/editors/editors.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / extra / editors / editors.factor
1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: parser kernel namespaces sequences definitions io.files
4 inspector continuations tools.crossref tools.vocabs 
5 io prettyprint source-files assocs vocabs vocabs.loader
6 io.backend splitting accessors ;
7 IN: editors
8
9 TUPLE: no-edit-hook ;
10
11 M: no-edit-hook summary
12     drop "You must load one of the below vocabularies before using editor integration:" ;
13
14 SYMBOL: edit-hook
15
16 : available-editors ( -- seq )
17     "editors" all-child-vocabs-seq [ vocab-name ] map ;
18
19 : editor-restarts ( -- alist )
20     available-editors
21     [ [ "Load " prepend ] keep ] { } map>assoc ;
22
23 : no-edit-hook ( -- )
24     \ no-edit-hook new
25     editor-restarts throw-restarts
26     require ;
27
28 : edit-location ( file line -- )
29     >r (normalize-path) r>
30     edit-hook get [ call ] [ no-edit-hook edit-location ] if* ;
31
32 : edit ( defspec -- )
33     where [ first2 edit-location ] when* ;
34
35 : edit-vocab ( name -- )
36     vocab-source-path 1 edit-location ;
37
38 GENERIC: find-parse-error ( error -- error' )
39
40 M: parse-error find-parse-error
41     dup error>> find-parse-error [ ] [ ] ?if ;
42
43 M: condition find-parse-error
44     error>> find-parse-error ;
45
46 M: object find-parse-error
47     drop f ;
48
49 : :edit ( -- )
50     error get find-parse-error [
51         [ file>> path>> ] [ line>> ] bi edit-location
52     ] when* ;
53
54 : fix ( word -- )
55     [ "Fixing " write pprint " and all usages..." print nl ]
56     [ [ smart-usage ] keep prefix ] bi
57     [
58         [ "Editing " write . ]
59         [
60             "RETURN moves on to the next usage, C+d stops." print
61             flush
62             edit
63             readln
64         ] bi
65     ] all? drop ;