From 85a6264358163b889e4b78435d1f866944ad984d Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Fri, 24 Oct 2014 18:34:17 +0100 Subject: [PATCH] More intuitive justOneSep What happened is that we got a bit more than we sanely hoped for: we were catching \n as a separator and correctly killing it and re-inserting. Because justOneSep moves forward a character in some cases, it looked like we were just going to the next line. Fixes #665 --- CHANGELOG | 1 + yi/src/library/Yi/Keymap/Emacs.hs | 2 +- yi/src/library/Yi/Keymap/Emacs/Utils.hs | 35 ++++++++++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ce14e4012..56398c47c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ * Try to guess and preserve the file encoding (#638) * Restore cursor position better after deleteTrailingSpacesB (#666) * Fix eolPoint' when on last, empty line (#667) + * More intuitive justOneSep (emacs M-SPC) (#665) 0.10.0 ------ diff --git a/yi/src/library/Yi/Keymap/Emacs.hs b/yi/src/library/Yi/Keymap/Emacs.hs index 1d1f6d279..5e782c830 100644 --- a/yi/src/library/Yi/Keymap/Emacs.hs +++ b/yi/src/library/Yi/Keymap/Emacs.hs @@ -183,7 +183,7 @@ emacsKeys univArg = , ctrlCh 'c' ?>> ctrlC -- All The key-bindings of the form M-c where 'c' is some character. - , metaCh ' ' ?>>! justOneSep + , metaCh ' ' ?>>! justOneSep univArg , metaCh 'v' ?>>! scrollUpE univArg , metaCh '!' ?>>! shellCommandE , metaCh '<' ?>>! repeatingArg topB diff --git a/yi/src/library/Yi/Keymap/Emacs/Utils.hs b/yi/src/library/Yi/Keymap/Emacs/Utils.hs index 851480312..eb91efff9 100644 --- a/yi/src/library/Yi/Keymap/Emacs/Utils.hs +++ b/yi/src/library/Yi/Keymap/Emacs/Utils.hs @@ -327,27 +327,38 @@ killBufferE = promptingForBuffer "kill buffer:" k (\o b -> o ++ (b \\ o)) -- | If on separators (space, tab, unicode seps), reduce multiple --- separators to just a single separator. If we aren't looking at a separator, --- insert a single space. This kind of behaves as emacs ‘just-one-space’ --- function with the argument of ‘1’ but it prefers to use the separator we're --- looking at instead of assuming a space. -justOneSep :: BufferM () -justOneSep = readB >>= \c -> +-- separators to just a single separator (or however many given +-- through 'UniversalArgument'). +-- +-- If we aren't looking at a separator, insert a single space. This is +-- like emacs ‘just-one-space’ but doesn't deal with negative argument +-- case but works with other separators than just space. What counts +-- as a separator is decided by 'isAnySep' modulo @\n@ character. +-- +-- Further, it will only reduce a single type of separator at once: if +-- we have hard tabs followed by spaces, we are able to reduce one and +-- not the other. +justOneSep :: UnivArgument -> BufferM () +justOneSep u = readB >>= \c -> pointB >>= \point -> case point of - Point 0 -> if isAnySep c then deleteSeparators else insertB ' ' + Point 0 -> if isSep c then deleteSeparators else insertMult c Point x -> - if isAnySep c + if isSep c then deleteSeparators else readAtB (Point $ x - 1) >>= \d -> -- We weren't looking at separator but there might be one behind us - if isAnySep d + if isSep d then moveB Character Backward >> deleteSeparators - else insertB ' ' -- no separators, insert a space just like emacs does + else insertMult ' ' -- no separators, insert a space just + -- like emacs does where + isSep c = c /= '\n' && isAnySep c + insertMult c = insertN $ R.replicateChar (maybe 1 (max 1) u) c + deleteSeparators = do genMaybeMoveB unitSepThisLine (Backward, InsideBound) Backward moveB Character Forward - doIfCharB isAnySep $ deleteB unitSepThisLine Forward + doIfCharB isSep $ deleteB unitSepThisLine Forward @@ -356,7 +367,7 @@ joinLinesE :: UnivArgument -> BufferM () joinLinesE Nothing = return () joinLinesE (Just _) = do moveB VLine Forward - moveToSol >> transformB (const " ") Character Backward >> justOneSep + moveToSol >> transformB (const " ") Character Backward >> justOneSep Nothing -- | Shortcut to use a default list when a blank list is given. -- Used for default values to emacs queries