Skip to content

Commit

Permalink
More intuitive justOneSep
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Fuuzetsu committed Oct 24, 2014
1 parent 5037761 commit 85a6264
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -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
------
Expand Down
2 changes: 1 addition & 1 deletion yi/src/library/Yi/Keymap/Emacs.hs
Expand Up @@ -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
Expand Down
35 changes: 23 additions & 12 deletions yi/src/library/Yi/Keymap/Emacs/Utils.hs
Expand Up @@ -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



Expand All @@ -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
Expand Down

0 comments on commit 85a6264

Please sign in to comment.