From: John Benediktsson Date: Fri, 5 Aug 2022 23:15:56 +0000 (-0700) Subject: editors: adding EDITOR: syntax and use classes instead of tuples X-Git-Tag: 0.99~1212 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=41f2f000e19f505803519f01678aff828ac4469e editors: adding EDITOR: syntax and use classes instead of tuples --- diff --git a/basis/editors/editors-docs.factor b/basis/editors/editors-docs.factor index a67d16b003..1570bd7958 100644 --- a/basis/editors/editors-docs.factor +++ b/basis/editors/editors-docs.factor @@ -9,7 +9,7 @@ ARTICLE: "editor" "Editor integration" { $code "USE: editors.emacs" } "If you intend to always use the same editor, it helps to have it load during stage 2 bootstrap. Place the code to load and possibly configure it in the " { $link ".factor-boot-rc" } "." $nl -"Editor integration vocabularies store a class or tuple in a global variable when loaded:" +"Editor integration vocabularies store an object in a global variable when loaded:" { $subsections editor-class } "If a syntax error was thrown while loading a source file, you can jump to the location of the error in your editor:" { $subsections :edit } ; diff --git a/basis/editors/editors.factor b/basis/editors/editors.factor index 48df40246b..36c59dc385 100644 --- a/basis/editors/editors.factor +++ b/basis/editors/editors.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs calendar continuations debugger -definitions io io.launcher io.pathnames kernel namespaces -prettyprint sequences source-files.errors splitting strings +definitions io io.launcher io.pathnames kernel lexer namespaces +prettyprint sequences sets source-files.errors splitting strings threads tools.crossref vocabs vocabs.files vocabs.hierarchy vocabs.loader vocabs.metadata words ; IN: editors @@ -10,12 +10,16 @@ IN: editors SYMBOL: editor-class : available-editors ( -- seq ) - "editors" disk-child-vocab-names ; + "editors" disk-child-vocab-names + { "editors.ui" "editors.private" } diff ; : editor-restarts ( -- alist ) available-editors [ [ "Load " prepend ] keep ] { } map>assoc ; +SYNTAX: EDITOR: + f editor-class set-global "editors." scan-token append reload ; + HOOK: editor-command editor-class ( file line -- command ) M: f editor-command diff --git a/basis/editors/gvim/gvim.factor b/basis/editors/gvim/gvim.factor index 756fdcc722..f230ada603 100644 --- a/basis/editors/gvim/gvim.factor +++ b/basis/editors/gvim/gvim.factor @@ -5,9 +5,12 @@ IN: editors.gvim ! This code builds on the code in editors.vim; see there for ! more information. -TUPLE: gvim < vim ; +SINGLETON: gvim -editor-class [ T{ gvim } ] initialize +INSTANCE: gvim vim-base + +editor-class get-global dup [ vim? not ] when +[ gvim editor-class set-global ] unless HOOK: find-gvim-path io-backend ( -- path ) diff --git a/basis/editors/macvim/macvim.factor b/basis/editors/macvim/macvim.factor index ef4427fb90..cc3267fdb6 100644 --- a/basis/editors/macvim/macvim.factor +++ b/basis/editors/macvim/macvim.factor @@ -2,9 +2,12 @@ USING: editors editors.vim io.pathnames io.standard-paths kernel namespaces ; IN: editors.macvim -TUPLE: macvim < vim ; +SINGLETON: macvim -editor-class [ T{ macvim } ] initialize +INSTANCE: macvim vim-base + +editor-class get-global dup [ vim? not ] when +[ macvim editor-class set-global ] unless : find-macvim-bundle-path ( -- path/f ) "org.vim.MacVim" find-native-bundle [ diff --git a/basis/editors/vim/vim.factor b/basis/editors/vim/vim.factor index 39d20c41d1..e44d80b709 100644 --- a/basis/editors/vim/vim.factor +++ b/basis/editors/vim/vim.factor @@ -2,9 +2,13 @@ USING: editors io.standard-paths kernel make math.parser namespaces sequences strings ; IN: editors.vim -TUPLE: vim ; +SINGLETON: vim -editor-class [ T{ vim } ] initialize +MIXIN: vim-base + +INSTANCE: vim vim-base + +editor-class [ vim ] initialize SYMBOL: vim-path @@ -14,14 +18,14 @@ HOOK: vim-ui? editor-class ( -- ? ) SYMBOL: vim-tabs? -M: vim vim-ui? f ; +M: vim-base vim-ui? f ; -M: vim find-vim-path "vim" ?find-in-path ; +M: vim-base find-vim-path "vim" ?find-in-path ; : actual-vim-path ( -- path ) \ vim-path get [ find-vim-path ] unless* ; -M: vim editor-command +M: vim-base editor-command [ actual-vim-path dup string? [ , ] [ % ] if vim-ui? [ "-g" , ] when @@ -30,4 +34,4 @@ M: vim editor-command , ] { } make ; -M: vim editor-detached? f ; +M: vim-base editor-detached? f ; diff --git a/basis/editors/visual-studio-code-exploration/visual-studio-code-exploration.factor b/basis/editors/visual-studio-code-exploration/visual-studio-code-exploration.factor index 0d507f9aa9..2f848afb0e 100644 --- a/basis/editors/visual-studio-code-exploration/visual-studio-code-exploration.factor +++ b/basis/editors/visual-studio-code-exploration/visual-studio-code-exploration.factor @@ -5,9 +5,12 @@ io.pathnames io.standard-paths kernel namespaces system tools.which ; IN: editors.visual-studio-code-exploration -TUPLE: visual-studio-code-exploration < visual-studio-code ; +SINGLETON: visual-studio-code-exploration -editor-class [ T{ visual-studio-code-exploration } ] initialize +INSTANCE: visual-studio-code-exploration visual-studio-code-base + +editor-class get-global dup [ visual-studio-code? not ] when +[ visual-studio-code-exploration editor-class set-global ] unless M: visual-studio-code-exploration find-visual-studio-code-path os { diff --git a/basis/editors/visual-studio-code-insiders/visual-studio-code-insiders.factor b/basis/editors/visual-studio-code-insiders/visual-studio-code-insiders.factor index 48678de096..24328975c2 100644 --- a/basis/editors/visual-studio-code-insiders/visual-studio-code-insiders.factor +++ b/basis/editors/visual-studio-code-insiders/visual-studio-code-insiders.factor @@ -5,9 +5,12 @@ io.pathnames io.standard-paths kernel namespaces system tools.which ; IN: editors.visual-studio-code-insiders -TUPLE: visual-studio-code-insiders < visual-studio-code ; +SINGLETON: visual-studio-code-insiders -editor-class [ T{ visual-studio-code-insiders } ] initialize +INSTANCE: visual-studio-code-insiders visual-studio-code-base + +editor-class get-global dup [ visual-studio-code? not ] when +[ visual-studio-code-insiders editor-class set-global ] unless M: visual-studio-code-insiders find-visual-studio-code-path os { diff --git a/basis/editors/visual-studio-code/visual-studio-code.factor b/basis/editors/visual-studio-code/visual-studio-code.factor index 70880e99e9..289ffca8d9 100644 --- a/basis/editors/visual-studio-code/visual-studio-code.factor +++ b/basis/editors/visual-studio-code/visual-studio-code.factor @@ -8,13 +8,15 @@ IN: editors.visual-studio-code ! Command line arguments ! https://code.visualstudio.com/docs/editor/command-line -TUPLE: visual-studio-code ; +SINGLETON: visual-studio-code -editor-class [ T{ visual-studio-code } ] initialize +MIXIN: visual-studio-code-base + +editor-class [ visual-studio-code ] initialize HOOK: find-visual-studio-code-path editor-class ( -- path ) -M: visual-studio-code find-visual-studio-code-path +M: visual-studio-code-base find-visual-studio-code-path os { { linux [ { @@ -46,5 +48,5 @@ ERROR: can't-find-visual-studio-code ; number>string ":" glue , ] { } make ; -M: visual-studio-code editor-command +M: visual-studio-code-base editor-command visual-studio-code-editor-command ; diff --git a/basis/editors/visual-studio-codium/visual-studio-codium.factor b/basis/editors/visual-studio-codium/visual-studio-codium.factor index 923001c375..32207ed8ec 100644 --- a/basis/editors/visual-studio-codium/visual-studio-codium.factor +++ b/basis/editors/visual-studio-codium/visual-studio-codium.factor @@ -5,9 +5,12 @@ io.pathnames io.standard-paths kernel namespaces system tools.which ; IN: editors.visual-studio-codium -TUPLE: visual-studio-codium < visual-studio-code ; +SINGLETON: visual-studio-codium -editor-class [ T{ visual-studio-codium } ] initialize +INSTANCE: visual-studio-codium visual-studio-code-base + +editor-class get-global dup [ visual-studio-code? not ] when +[ visual-studio-codium editor-class set-global ] unless M: visual-studio-codium find-visual-studio-code-path os {