10000 Use Emacs as DefaultEditMode on Linux / OS X by andyleejordan · Pull Request #1388 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Use Emacs as DefaultEditMode on Linux / OS X #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

10000 Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ public class PSConsoleReadlineOptions
public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan;
public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red;

public const EditMode DefaultEditMode = EditMode.Windows;
public const EditMode DefaultEditMode =
#if LINUX
EditMode.Emacs;
#else
EditMode.Windows;
#endif

public const string DefaultContinuationPrompt = ">> ";

Expand Down
19 changes: 19 additions & 0 deletions src/Microsoft.PowerShell.PSReadLine/KeyBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ static KeyHandler MakeKeyHandler(Action<ConsoleKeyInfo?, object> action, string
private Dictionary<ConsoleKeyInfo, KeyHandler> _dispatchTable;
private Dictionary<ConsoleKeyInfo, Dictionary<ConsoleKeyInfo, KeyHandler>> _chordDispatchTable;

/// <summary>
/// Helper to set bindings based on EditMode
/// </summary>
void SetDefaultBindings(EditMode editMode)
{
switch (editMode)
{
case EditMode.Emacs:
SetDefaultEmacsBindings();
break;
case EditMode.Vi:
SetDefaultViBindings();
break;
case EditMode.Windows:
SetDefaultWindowsBindings();
break;
}
}

void SetDefaultWindowsBindings()
{
_dispatchTable = new Dictionary<ConsoleKeyInfo, KeyHandler>(new ConsoleKeyInfoComparer())
Expand Down
13 changes: 1 addition & 12 deletions src/Microsoft.PowerShell.PSReadLine/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,7 @@ private void SetOptionsInternal(SetPSReadlineOption options)
// Switching/resetting modes - clear out chord dispatch table
_chordDispatchTable.Clear();

switch (options._editMode)
{
case EditMode.Emacs:
SetDefaultEmacsBindings();
break;
case EditMode.Vi:
SetDefaultViBindings();
break;
case EditMode.Windows:
SetDefaultWindowsBindings();
break;
}
SetDefaultBindings(Options.EditMode);
}
if (options._showToolTips.HasValue)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.PowerShell.PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,6 @@ private PSConsoleReadLine()
_console = new ConhostConsole();
#endif

SetDefaultWindowsBindings();

_buffer = new StringBuilder(8 * 1024);
_statusBuffer = new StringBuilder(256);
_savedCurrentLine = new HistoryItem();
Expand Down Expand Up @@ -516,6 +514,7 @@ private PSConsoleReadLine()
hostName = "PSReadline";
}
_options = new PSConsoleReadlineOptions(hostName);
SetDefaultBindings(_options.EditMode);
}

private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
Expand Down
10 changes: 10 additions & 0 deletions test/powershell/Modules/PSReadLine/PSReadLine.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ Describe "PSReadLine" {
$module.Version | Should Be "1.2"
}

It "Should use Emacs Bindings on Linux and OS X" -skip:$IsWindows {
(Get-PSReadLineOption).EditMode | Should Be Emacs
(Get-PSReadlineKeyHandler | where { $_.Key -eq "Ctrl+A" }).Function | Should Be BeginningOfLine
}

It "Should use Windows Bindings on Windows" -skip:(-not $IsWindows) {
(Get-PSReadLineOption).EditMode | Should Be Windows
(Get-PSReadlineKeyHandler | where { $_.Key -eq "Ctrl+A" }).Function | Should Be SelectAll
}

It "Should set the edit mode" {
Set-PSReadlineOption -EditMode Windows
(Get-PSReadlineKeyHandler | where { $_.Key -eq "Ctrl+A" }).Function | Should Be SelectAll
Expand Down
0