Skip to content

Commit

Permalink
Support temporary options
Browse files Browse the repository at this point in the history
  • Loading branch information
lippfi committed Nov 10, 2023
1 parent 93c83f7 commit ddfe8cf
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 58 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/maddyhome/idea/vim/group/IjOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public object IjOptions {
"lookupkeys",
"<Tab>,<Down>,<Up>,<Enter>,<Left>,<Right>,<C-Down>,<C-Up>,<PageUp>,<PageDown>,<C-J>,<C-Q>")
)
public val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true))
public val trackactionids: ToggleOption = addOption(ToggleOption("trackactionids", GLOBAL, "tai", false))
public val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true))
public val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true))
public val commandOrMotionAnnotation: ToggleOption = addOption(ToggleOption("commandormotionannotation", GLOBAL, "commandormotionannotation", true))
public val visualdelay: UnsignedNumberOption = addOption(UnsignedNumberOption("visualdelay", GLOBAL, "visualdelay", 100))
public val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true, isTemporary = true))
public val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true, isTemporary = true))
public val commandOrMotionAnnotation: ToggleOption = addOption(ToggleOption("commandormotionannotation", GLOBAL, "commandormotionannotation", true, isTemporary = true))

// This needs to be Option<out VimDataType> so that it can work with derived option types, such as NumberOption, which
// derives from Option<VimInt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ class SetCommandTest : VimTestCase() {
assertCommandOutput("set all",
"""
|--- Options ---
|noargtextobj noideatracetime scroll=0 nosurround
| closenotebooks ideawrite=all scrolljump=1 notextobj-entire
|nocommentary noignorecase scrolloff=0 notextobj-indent
|nodigraph noincsearch selectmode= timeout
|noexchange nomatchit shellcmdflag=-x timeoutlen=1000
|nogdefault maxmapdepth=20 shellxescape=@ notrackactionids
|nohighlightedyank more shellxquote={ undolevels=1000
| history=50 nomultiple-cursors showcmd unifyjumps
|nohlsearch noNERDTree showmode virtualedit=
|noideaglobalmode nrformats=hex sidescroll=0 novisualbell
|noideajoin nonumber sidescrolloff=0 visualdelay=100
| ideamarks oldundo nosmartcase whichwrap=b,s
| ideastrictmode norelativenumber startofline wrapscan
|noargtextobj noideatracetime scrolljump=1 notextobj-entire
| closenotebooks ideawrite=all scrolloff=0 notextobj-indent
|nocommentary noignorecase selectmode= timeout
|nodigraph noincsearch shellcmdflag=-x timeoutlen=1000
|noexchange nomatchit shellxescape=@ notrackactionids
|nogdefault maxmapdepth=20 shellxquote={ undolevels=1000
|nohighlightedyank more showcmd unifyjumps
| history=50 nomultiple-cursors showmode virtualedit=
|nohlsearch noNERDTree sidescroll=0 novisualbell
|noideaglobalmode nrformats=hex sidescrolloff=0 visualdelay=100
|noideajoin nonumber nosmartcase whichwrap=b,s
| ideamarks norelativenumber startofline wrapscan
| ideastrictmode scroll=0 nosurround
| clipboard=ideaput,autoselect,exclude:cons\|linux
| excommandannotation
| guicursor=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
Expand All @@ -194,7 +194,6 @@ class SetCommandTest : VimTestCase() {
| shell=/dummy/path/to/bash
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
|
""".trimMargin())
}
Expand Down Expand Up @@ -261,7 +260,6 @@ class SetCommandTest : VimTestCase() {
|noNERDTree
| nrformats=hex
|nonumber
| oldundo
|norelativenumber
|noReplaceWithRegister
| scroll=0
Expand Down Expand Up @@ -289,7 +287,6 @@ class SetCommandTest : VimTestCase() {
| unifyjumps
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
| virtualedit=
|novisualbell
| visualdelay=100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,19 @@ class SetglobalCommandTest : VimTestCase() {
setOsSpecificOptionsToSafeValues()
assertCommandOutput("setglobal all", """
|--- Global option values ---
|noargtextobj noideatracetime scroll=0 nosurround
| closenotebooks ideawrite=all scrolljump=1 notextobj-entire
|nocommentary noignorecase scrolloff=0 notextobj-indent
|nodigraph noincsearch selectmode= timeout
|noexchange nomatchit shellcmdflag=-x timeoutlen=1000
|nogdefault maxmapdepth=20 shellxescape=@ notrackactionids
|nohighlightedyank more shellxquote={ undolevels=1000
| history=50 nomultiple-cursors showcmd unifyjumps
|nohlsearch noNERDTree showmode virtualedit=
|noideaglobalmode nrformats=hex sidescroll=0 novisualbell
|noideajoin nonumber sidescrolloff=0 visualdelay=100
| ideamarks oldundo nosmartcase whichwrap=b,s
| ideastrictmode norelativenumber startofline wrapscan
|noargtextobj noideatracetime scrolljump=1 notextobj-entire
| closenotebooks ideawrite=all scrolloff=0 notextobj-indent
|nocommentary noignorecase selectmode= timeout
|nodigraph noincsearch shellcmdflag=-x timeoutlen=1000
|noexchange nomatchit shellxescape=@ notrackactionids
|nogdefault maxmapdepth=20 shellxquote={ undolevels=1000
|nohighlightedyank more showcmd unifyjumps
| history=50 nomultiple-cursors showmode virtualedit=
|nohlsearch noNERDTree sidescroll=0 novisualbell
|noideaglobalmode nrformats=hex sidescrolloff=0 visualdelay=100
|noideajoin nonumber nosmartcase whichwrap=b,s
| ideamarks norelativenumber startofline wrapscan
| ideastrictmode scroll=0 nosurround
| clipboard=ideaput,autoselect,exclude:cons\|linux
| excommandannotation
| guicursor=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
Expand All @@ -380,7 +380,6 @@ class SetglobalCommandTest : VimTestCase() {
| shell=/dummy/path/to/bash
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
|""".trimMargin()
)
}
Expand Down Expand Up @@ -443,7 +442,6 @@ class SetglobalCommandTest : VimTestCase() {
|noNERDTree
| nrformats=hex
|nonumber
| oldundo
|norelativenumber
|noReplaceWithRegister
| scroll=0
Expand Down Expand Up @@ -471,7 +469,6 @@ class SetglobalCommandTest : VimTestCase() {
| unifyjumps
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
| virtualedit=
|novisualbell
| visualdelay=100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,19 @@ class SetlocalCommandTest : VimTestCase() {
setOsSpecificOptionsToSafeValues()
assertCommandOutput("setlocal all", """
|--- Local option values ---
|noargtextobj ideastrictmode norelativenumber startofline
| closenotebooks noideatracetime scroll=0 nosurround
|nocommentary ideawrite=all scrolljump=1 notextobj-entire
|nodigraph noignorecase scrolloff=-1 notextobj-indent
|noexchange noincsearch selectmode= timeout
|nogdefault nomatchit shellcmdflag=-x timeoutlen=1000
|nohighlightedyank maxmapdepth=20 shellxescape=@ notrackactionids
| history=50 more shellxquote={ unifyjumps
|nohlsearch nomultiple-cursors showcmd virtualedit=
|noideaglobalmode noNERDTree showmode novisualbell
|--ideajoin nrformats=hex sidescroll=0 visualdelay=100
| ideamarks nonumber sidescrolloff=-1 whichwrap=b,s
| idearefactormode= oldundo nosmartcase wrapscan
|noargtextobj ideastrictmode scroll=0 nosurround
| closenotebooks noideatracetime scrolljump=1 notextobj-entire
|nocommentary ideawrite=all scrolloff=-1 notextobj-indent
|nodigraph noignorecase selectmode= timeout
|noexchange noincsearch shellcmdflag=-x timeoutlen=1000
|nogdefault nomatchit shellxescape=@ notrackactionids
|nohighlightedyank maxmapdepth=20 shellxquote={ unifyjumps
| history=50 more showcmd virtualedit=
|nohlsearch nomultiple-cursors showmode novisualbell
|noideaglobalmode noNERDTree sidescroll=0 visualdelay=100
|--ideajoin nrformats=hex sidescrolloff=-1 whichwrap=b,s
| ideamarks nonumber nosmartcase wrapscan
| idearefactormode= norelativenumber startofline
| clipboard=ideaput,autoselect,exclude:cons\|linux
| excommandannotation
| guicursor=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
Expand All @@ -412,7 +412,6 @@ class SetlocalCommandTest : VimTestCase() {
| undolevels=-123456
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
|""".trimMargin()
)
}
Expand Down Expand Up @@ -481,7 +480,6 @@ class SetlocalCommandTest : VimTestCase() {
|noNERDTree
| nrformats=hex
|nonumber
| oldundo
|norelativenumber
|noReplaceWithRegister
| scroll=0
Expand Down Expand Up @@ -509,7 +507,6 @@ class SetlocalCommandTest : VimTestCase() {
| unifyjumps
|novim-paragraph-motion
| viminfo='100,<50,s10,h
| vimscriptfunctionannotation
| virtualedit=
|novisualbell
| visualdelay=100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ import java.util.*
* @param abbrev An abbreviated name for the option, recognised by `:set`
* @param defaultValue The default value of the option, if not set by the user
* @param unsetValue The value of the local part of a global-local option, if the local part has not been set
* @param isTemporary True for feature-toggle options that will be reviewed in future releases.
* Such options won't be printed in option list.
*/
public abstract class Option<T : VimDataType>(public val name: String,
public val declaredScope: OptionDeclaredScope,
public val abbrev: String,
defaultValue: T,
public val unsetValue: T) {
public val unsetValue: T,
public val isTemporary: Boolean = false) {
private var defaultValueField = defaultValue

public open val defaultValue: T
Expand Down Expand Up @@ -292,13 +295,14 @@ public open class UnsignedNumberOption(
* @param abbrev An abbreviated name for the option, recognised by `:set`
* @param defaultValue The option's default value of the option
*/
public class ToggleOption(name: String, declaredScope: OptionDeclaredScope, abbrev: String, defaultValue: VimInt) :
Option<VimInt>(name, declaredScope, abbrev, defaultValue, VimInt.MINUS_ONE) {
public constructor(name: String, declaredScope: OptionDeclaredScope, abbrev: String, defaultValue: Boolean) : this(
public class ToggleOption(name: String, declaredScope: OptionDeclaredScope, abbrev: String, defaultValue: VimInt, isTemporary: Boolean = false) :
Option<VimInt>(name, declaredScope, abbrev, defaultValue, VimInt.MINUS_ONE, isTemporary) {
public constructor(name: String, declaredScope: OptionDeclaredScope, abbrev: String, defaultValue: Boolean, isTemporary: Boolean = false) : this(
name,
declaredScope,
abbrev,
if (defaultValue) VimInt.ONE else VimInt.ZERO
if (defaultValue) VimInt.ONE else VimInt.ZERO,
isTemporary
)

override fun checkIfValueValid(value: VimDataType, token: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public fun parseOptionLine(editor: VimEditor, args: String, scope: OptionAccessS
when {
argument.isEmpty() -> {
// No arguments mean we show only changed values
val changedOptions = optionGroup.getAllOptions().filter { !optionGroup.isDefaultValue(it, scope) }
val changedOptions = optionGroup.getAllOptions().filter { !optionGroup.isDefaultValue(it, scope) && !it.isTemporary }
showOptions(editor, changedOptions.map { Pair(it.name, it.name) }, scope, true, columnFormat)
return
}
argument == "all" -> {
showOptions(editor, optionGroup.getAllOptions().map { Pair(it.name, it.name) }, scope, true, columnFormat)
showOptions(editor, optionGroup.getAllOptions().filter { !it.isTemporary }.map { Pair(it.name, it.name) }, scope, true, columnFormat)
return
}
argument == "all&" -> {
Expand Down

0 comments on commit ddfe8cf

Please sign in to comment.