Permalink
Browse files

Fixed tabs with < and > commands

  • Loading branch information...
1 parent 1a7749d commit 9c4805cf4c85e4c2f5aca799459963125218eac5 @jaredpar committed Jan 23, 2011
Showing with 12,394 additions and 288 deletions.
  1. +2 −0 CodingGuidelines.txt
  2. +18 −6 VimCore/CoreInterfaces.fs
  3. +6 −0 VimCore/EditorUtil.fs
  4. +67 −11 VimCore/Modes_CommonOperations.fs
  5. +32 −20 VimCore/VimSettings.fs
  6. +203 −78 VimCoreTest/CommonOperationsTest.cs
  7. +1 −1 VimCoreTest/IntegrationTests.cs
  8. +12 −4 VimCoreTest/VimCoreTest.csproj
  9. +4 −0 VimCoreTest/packages.config
  10. +0 −84 VimUnitTestUtils/Mock/MockVimGlobalSettings.cs
  11. +0 −61 VimUnitTestUtils/Mock/MockVimLocalSettings.cs
  12. +8 −4 VimUnitTestUtils/VimUnitTestUtils.csproj
  13. +4 −0 VimUnitTestUtils/packages.config
  14. +15 −13 VimWpfTest/BlockCaretControllerTest.cs
  15. +11 −2 VimWpfTest/VimWpfTest.csproj
  16. +4 −0 VimWpfTest/packages.config
  17. +10 −4 VsVimTest/VsVimTest.csproj
  18. +4 −0 VsVimTest/packages.config
  19. BIN packages/NUnit.2.5.7.10213/Logo.ico
  20. BIN packages/NUnit.2.5.7.10213/NUnit.2.5.7.10213.nupkg
  21. +277 −0 packages/NUnit.2.5.7.10213/NUnitFitTests.html
  22. +277 −0 packages/NUnit.2.5.7.10213/Tools/NUnitFitTests.html
  23. +84 −0 packages/NUnit.2.5.7.10213/Tools/NUnitTests.config
  24. +14 −0 packages/NUnit.2.5.7.10213/Tools/NUnitTests.nunit
  25. +4 −0 packages/NUnit.2.5.7.10213/Tools/agent.conf
  26. +18 −0 packages/NUnit.2.5.7.10213/Tools/agent.log.conf
  27. +18 −0 packages/NUnit.2.5.7.10213/Tools/launcher.log.conf
  28. BIN packages/NUnit.2.5.7.10213/Tools/lib/Failure.png
  29. BIN packages/NUnit.2.5.7.10213/Tools/lib/Ignored.png
  30. BIN packages/NUnit.2.5.7.10213/Tools/lib/Inconclusive.png
  31. BIN packages/NUnit.2.5.7.10213/Tools/lib/Skipped.png
  32. BIN packages/NUnit.2.5.7.10213/Tools/lib/Success.png
  33. BIN packages/NUnit.2.5.7.10213/Tools/lib/fit.dll
  34. BIN packages/NUnit.2.5.7.10213/Tools/lib/log4net.dll
  35. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit-console-runner.dll
  36. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit-gui-runner.dll
  37. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit.core.dll
  38. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit.core.interfaces.dll
  39. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit.fixtures.dll
  40. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit.uiexception.dll
  41. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit.uikit.dll
  42. BIN packages/NUnit.2.5.7.10213/Tools/lib/nunit.util.dll
  43. BIN packages/NUnit.2.5.7.10213/Tools/nunit-agent-x86.exe
  44. +76 −0 packages/NUnit.2.5.7.10213/Tools/nunit-agent-x86.exe.config
  45. BIN packages/NUnit.2.5.7.10213/Tools/nunit-agent.exe
  46. +76 −0 packages/NUnit.2.5.7.10213/Tools/nunit-agent.exe.config
  47. BIN packages/NUnit.2.5.7.10213/Tools/nunit-console-x86.exe
  48. +76 −0 packages/NUnit.2.5.7.10213/Tools/nunit-console-x86.exe.config
  49. BIN packages/NUnit.2.5.7.10213/Tools/nunit-console.exe
  50. +76 −0 packages/NUnit.2.5.7.10213/Tools/nunit-console.exe.config
  51. BIN packages/NUnit.2.5.7.10213/Tools/nunit-x86.exe
  52. +91 −0 packages/NUnit.2.5.7.10213/Tools/nunit-x86.exe.config
  53. BIN packages/NUnit.2.5.7.10213/Tools/nunit.exe
  54. +91 −0 packages/NUnit.2.5.7.10213/Tools/nunit.exe.config
  55. BIN packages/NUnit.2.5.7.10213/Tools/nunit.framework.dll
  56. BIN packages/NUnit.2.5.7.10213/Tools/pnunit-agent.exe
  57. +77 −0 packages/NUnit.2.5.7.10213/Tools/pnunit-agent.exe.config
  58. BIN packages/NUnit.2.5.7.10213/Tools/pnunit-launcher.exe
  59. +77 −0 packages/NUnit.2.5.7.10213/Tools/pnunit-launcher.exe.config
  60. BIN packages/NUnit.2.5.7.10213/Tools/pnunit.framework.dll
  61. BIN packages/NUnit.2.5.7.10213/Tools/pnunit.tests.dll
  62. BIN packages/NUnit.2.5.7.10213/Tools/runFile.exe
  63. +43 −0 packages/NUnit.2.5.7.10213/Tools/runFile.exe.config
  64. +2 −0 packages/NUnit.2.5.7.10213/Tools/runpnunit.bat
  65. +24 −0 packages/NUnit.2.5.7.10213/Tools/test.conf
  66. +342 −0 packages/NUnit.2.5.7.10213/fit-license.txt
  67. BIN packages/NUnit.2.5.7.10213/lib/nunit.framework.dll
  68. +10,228 −0 packages/NUnit.2.5.7.10213/lib/nunit.framework.xml
  69. BIN packages/NUnit.2.5.7.10213/lib/nunit.mocks.dll
  70. BIN packages/NUnit.2.5.7.10213/lib/pnunit.framework.dll
  71. +15 −0 packages/NUnit.2.5.7.10213/license.txt
  72. +7 −0 packages/repositories.config
View
@@ -20,6 +20,8 @@ F#
- Don't add a space between
- Parens in everything but after keywords and discriminated union values
x.Foo()
+ - After the get in a mutable property defenition
+ with get() =
- To Deteremine:
- Should functions returning an option be prefixed with Try? Example KeyNotationUtil
View
@@ -1040,6 +1040,8 @@ module GlobalSettingNames =
let StartOfLineName = "startofline"
let TabStopName = "tabstop"
let TildeOpName = "tildeop"
+ let UseEditorIndentName = "vsvim_useeditorindent"
+ let UseEditorTabSettingsName = "vsvim_useeditortabsettings"
let VisualBellName = "visualbell"
let VirtualEditName = "virtualedit"
let VimRcName = "vimrc"
@@ -1050,10 +1052,11 @@ module LocalSettingNames =
let AutoIndentName = "autoindent"
let CursorLineName = "cursorline"
+ let ExpandTabName = "expandtab"
let NumberName = "number"
let ScrollName = "scroll"
+ let TabStopName = "tabstop"
let QuoteEscapeName = "quoteescape"
- let UseEditorIndentName = "vsvim_useeditorindent"
/// Holds mutable data available to all buffers
type IVimData =
@@ -1117,7 +1120,7 @@ and IVimGlobalSettings =
/// Is the onemore option inside of VirtualEdit set
abstract IsVirtualEditOneMore : bool with get
- /// Controls how many spaces a tab counts for.
+ /// Controls how many spaces a tab counts for.
abstract TabStop : int with get,set
/// Controls the behavior of ~ in normal mode
@@ -1134,6 +1137,13 @@ and IVimGlobalSettings =
/// any upper case letters
abstract SmartCase : bool with get,set
+ /// Let the editor control indentation of lines instead. Overrides the AutoIndent
+ /// setting
+ abstract UseEditorIndent : bool with get, set
+
+ /// Use the editor tab setting over the ExpandTab one
+ abstract UseEditorTabSettings : bool with get, set
+
/// Retrieves the location of the loaded VimRC file. Will be the empty string if the load
/// did not succeed or has not been tried
abstract VimRc : string with get, set
@@ -1164,18 +1174,20 @@ and IVimLocalSettings =
/// Whether or not to highlight the line the cursor is on
abstract CursorLine : bool with get, set
+ /// Whether or not to expand tabs into spaces
+ abstract ExpandTab : bool with get, set
+
/// Return the handle to the global IVimSettings instance
abstract GlobalSettings : IVimGlobalSettings
+ /// How many spaces a tab counts for
+ abstract TabStop : int with get, set
+
abstract Scroll : int with get, set
/// Which characters escape quotes for certain motion types
abstract QuoteEscape : string with get, set
- /// Let the editor control indentation of lines instead. Overrides the AutoIndent
- /// setting
- abstract UseEditorIndent : bool with get, set
-
inherit IVimSettings
/// Vim instance. Global for a group of buffers
View
@@ -462,6 +462,12 @@ module SnapshotLineUtil =
|> SeqUtil.tryHeadOnly
|> OptionUtil.getOrDefault (GetEnd line)
+ /// Get the text of the ITextSnapshotLine
+ let GetText (line : ITextSnapshotLine) = line.GetText()
+
+ /// Get the text of the ITextSnapshotLine including the line break
+ let GetTextIncludingLineBreak (line : ITextSnapshotLine) = line.GetTextIncludingLineBreak()
+
[<RequireQualifiedAccess>]
type PointKind =
/// Normal valid point within the ITextSnapshot. Point in question is the argument
@@ -4,6 +4,7 @@ namespace Vim.Modes
open Vim
open Microsoft.VisualStudio.Text
open Microsoft.VisualStudio.Text.Editor
+open Microsoft.VisualStudio.Text.Editor.OptionsExtensionMethods
open Microsoft.VisualStudio.Text.Operations
open Microsoft.VisualStudio.Text.Outlining
open System.Text.RegularExpressions
@@ -26,6 +27,20 @@ type internal CommonOperations ( _data : OperationsData ) =
let _smartIndentationServtice = _data.SmartIndentationService
let _regexFactory = VimRegexFactory(_data.LocalSettings.GlobalSettings)
+ /// Whether or not to use spaces over tabs where applicable
+ member x.UseSpaces =
+ if _settings.GlobalSettings.UseEditorTabSettings then
+ DefaultOptionExtensions.IsConvertTabsToSpacesEnabled(_options)
+ else
+ _settings.ExpandTab
+
+ /// How many spaces does a tab count for
+ member x.TabSize =
+ if _settings.GlobalSettings.UseEditorTabSettings then
+ DefaultOptionExtensions.GetTabSize(_options)
+ else
+ _settings.TabStop
+
/// The caret sometimes needs to be adjusted after an Up or Down movement. Caret position
/// and virtual space is actually quite a predicamite for VsVim because of how Vim standard
/// works. Vim has no concept of Virtual Space and is designed to work in a fixed width
@@ -66,25 +81,66 @@ type internal CommonOperations ( _data : OperationsData ) =
let buffer = span.Snapshot.TextBuffer
buffer.Delete(span.Span) |> ignore
+ /// Convert the provided whitespace into spaces. The conversion of
+ /// tabs into spaces will be done based on the TabSize setting
+ member x.GetAndNormalizeLeadingWhitespaceToSpaces line =
+ let text =
+ line
+ |> SnapshotLineUtil.GetText
+ |> Seq.takeWhile CharUtil.IsWhiteSpace
+ |> List.ofSeq
+ let builder = System.Text.StringBuilder()
+ let tabSize = x.TabSize
+ for c in text do
+ match c with
+ | ' ' ->
+ builder.Append(' ') |> ignore
+ | '\t' ->
+ // Insert spaces up to the next tab size modulus.
+ let count =
+ let remainder = builder.Length % tabSize
+ if remainder = 0 then tabSize else remainder
+ for i = 1 to count do
+ builder.Append(' ') |> ignore
+ | _ ->
+ builder.Append(' ') |> ignore
+ builder.ToString(), text.Length
+
+ /// Normalize the whitespace into tabs / spaces based on the ExpandTab,
+ /// TabSize settings
+ member x.NormalizeSpaces (text : string) =
+ if x.UseSpaces then
+ text
+ else
+ let tabSize = x.TabSize
+ let spacesCount = text.Length % tabSize
+ let tabCount = (text.Length - spacesCount) / tabSize
+ let prefix = StringUtil.repeatChar tabCount '\t'
+ let suffix = StringUtil.repeatChar spacesCount ' '
+ prefix + suffix
+
member x.ShiftLineRangeRight multiplier (lineSpan:SnapshotLineRange) =
- let text = new System.String(' ', _settings.GlobalSettings.ShiftWidth * multiplier)
+ let shiftText =
+ let count = _settings.GlobalSettings.ShiftWidth * multiplier
+ StringUtil.repeatChar count ' '
use edit = _data.TextView.TextBuffer.CreateEdit()
lineSpan.Lines
- |> Seq.map (fun line -> line.Extent)
- |> Seq.iter (fun span -> edit.Replace(span.Start.Position, 0, text) |> ignore)
+ |> Seq.iter (fun line ->
+ let ws, originalLength = x.GetAndNormalizeLeadingWhitespaceToSpaces line
+ let ws = x.NormalizeSpaces (ws + shiftText)
+ edit.Replace(line.Start.Position, originalLength, ws) |> ignore)
edit.Apply() |> ignore
member x.ShiftLineRangeLeft multiplier (lineSpan:SnapshotLineRange) =
let count = _settings.GlobalSettings.ShiftWidth * multiplier
use edit = _data.TextView.TextBuffer.CreateEdit()
lineSpan.Lines
- |> Seq.map (fun line -> line.Extent)
- |> Seq.iter (fun span ->
- let text = SnapshotSpanUtil.GetText span
- let toReplace =
- let whiteSpaceLen = text |> Seq.takeWhile CharUtil.IsWhiteSpace |> Seq.length
- min whiteSpaceLen count
- edit.Replace(span.Start.Position, toReplace, StringUtil.empty) |> ignore )
+ |> Seq.iter (fun line ->
+ let ws, originalLength = x.GetAndNormalizeLeadingWhitespaceToSpaces line
+ let ws =
+ let length = max (ws.Length - count) 0
+ StringUtil.repeatChar length ' ' |> x.NormalizeSpaces
+ edit.Replace(line.Start.Position, originalLength, ws) |> ignore)
edit.Apply() |> ignore
/// Change the letters on the given span by applying the specified function
@@ -423,7 +479,7 @@ type internal CommonOperations ( _data : OperationsData ) =
else
TextViewUtil.MoveCaretToPoint _textView newLine.Start |> ignore
- if _settings.UseEditorIndent then
+ if _settings.GlobalSettings.UseEditorIndent then
let indent = _smartIndentationServtice.GetDesiredIndentation(_textView, newLine)
if indent.HasValue then
let point = new VirtualSnapshotPoint(newLine, indent.Value)
View
@@ -113,22 +113,24 @@ type internal GlobalSettings() =
static let GlobalSettings =
[|
- (CaretOpacityName, CaretOpacityName, NumberKind, NumberValue(65));
- (HighlightSearchName, "hls", ToggleKind, ToggleValue(false));
- (IgnoreCaseName,"ic", ToggleKind, ToggleValue(false));
- (MagicName, MagicName, ToggleKind, ToggleValue(true));
- (ShiftWidthName, "sw", NumberKind, NumberValue(4));
- (SelectionName, "sel", StringKind, StringValue("inclusive"));
- (ScrollOffsetName, "so", NumberKind, NumberValue(0));
- (SmartCaseName, "scs", ToggleKind, ToggleValue(false));
- (StartOfLineName, "sol", ToggleKind, ToggleValue(true));
- (TabStopName, "ts", NumberKind, NumberValue(8));
- (TildeOpName, "top", ToggleKind, ToggleValue(false));
- (VimRcName, VimRcName, StringKind, StringValue(System.String.Empty));
- (VimRcPathsName, VimRcPathsName, StringKind, StringValue(System.String.Empty));
- (VirtualEditName, "ve", StringKind, StringValue(StringUtil.empty));
- (VisualBellName, "vb", ToggleKind, ToggleValue(false));
- (WrapScanName, "ws", ToggleKind, ToggleValue(true));
+ (CaretOpacityName, CaretOpacityName, NumberKind, NumberValue(65))
+ (HighlightSearchName, "hls", ToggleKind, ToggleValue(false))
+ (IgnoreCaseName,"ic", ToggleKind, ToggleValue(false))
+ (MagicName, MagicName, ToggleKind, ToggleValue(true))
+ (ShiftWidthName, "sw", NumberKind, NumberValue(4))
+ (SelectionName, "sel", StringKind, StringValue("inclusive"))
+ (ScrollOffsetName, "so", NumberKind, NumberValue(0))
+ (SmartCaseName, "scs", ToggleKind, ToggleValue(false))
+ (StartOfLineName, "sol", ToggleKind, ToggleValue(true))
+ (TabStopName, "ts", NumberKind, NumberValue(8))
+ (TildeOpName, "top", ToggleKind, ToggleValue(false))
+ (UseEditorIndentName, UseEditorIndentName, ToggleKind, ToggleValue(true))
+ (UseEditorTabSettingsName, UseEditorTabSettingsName, ToggleKind, ToggleValue(true))
+ (VimRcName, VimRcName, StringKind, StringValue(System.String.Empty))
+ (VimRcPathsName, VimRcPathsName, StringKind, StringValue(System.String.Empty))
+ (VirtualEditName, "ve", StringKind, StringValue(StringUtil.empty))
+ (VisualBellName, "vb", ToggleKind, ToggleValue(false))
+ (WrapScanName, "ws", ToggleKind, ToggleValue(true))
|]
let _map = SettingsMap(GlobalSettings, true)
@@ -177,6 +179,12 @@ type internal GlobalSettings() =
member x.TildeOp
with get() = _map.GetBoolValue TildeOpName
and set value = _map.TrySetValue TildeOpName (ToggleValue(value)) |> ignore
+ member x.UseEditorIndent
+ with get() = _map.GetBoolValue UseEditorIndentName
+ and set value = _map.TrySetValue UseEditorIndentName (ToggleValue(value)) |> ignore
+ member x.UseEditorTabSettings
+ with get() = _map.GetBoolValue UseEditorTabSettingsName
+ and set value = _map.TrySetValue UseEditorTabSettingsName (ToggleValue(value)) |> ignore
member x.VimRc
with get() = _map.GetStringValue VimRcName
and set value = _map.TrySetValue VimRcName (StringValue(value)) |> ignore
@@ -209,10 +217,11 @@ type internal LocalSettings
[|
(AutoIndentName, "ai", ToggleKind, ToggleValue(false))
(CursorLineName, "cul", ToggleKind, ToggleValue(false))
+ (ExpandTabName, "et", ToggleKind, ToggleValue(false))
(NumberName, "nu", ToggleKind, ToggleValue(false))
(ScrollName, "scr", NumberKind, NumberValue(25))
+ (TabStopName, "ts", NumberKind, NumberValue(8))
(QuoteEscapeName, "qe", StringKind, StringValue(@"\"))
- (UseEditorIndentName, UseEditorIndentName, ToggleKind, ToggleValue(true))
|]
let _map = SettingsMap(LocalSettingInfo, false)
@@ -280,15 +289,18 @@ type internal LocalSettings
member x.CursorLine
with get() = _map.GetBoolValue CursorLineName
and set value = _map.TrySetValue CursorLineName (ToggleValue(value)) |> ignore
+ member x.ExpandTab
+ with get() = _map.GetBoolValue ExpandTabName
+ and set value = _map.TrySetValue ExpandTabName (ToggleValue(value)) |> ignore
member x.Scroll
with get() = _map.GetNumberValue ScrollName
and set value = _map.TrySetValue ScrollName (NumberValue(value)) |> ignore
+ member x.TabStop
+ with get() = _map.GetNumberValue TabStopName
+ and set value = _map.TrySetValue TabStopName (NumberValue(value)) |> ignore
member x.QuoteEscape
with get() = _map.GetStringValue QuoteEscapeName
and set value = _map.TrySetValue QuoteEscapeName (StringValue(value)) |> ignore
- member x.UseEditorIndent
- with get() = _map.GetBoolValue UseEditorIndentName
- and set value = _map.TrySetValue UseEditorIndentName (ToggleValue(value)) |> ignore
[<CLIEvent>]
member x.SettingChanged = _map.SettingChanged
Oops, something went wrong.

0 comments on commit 9c4805c

Please sign in to comment.