joinLinesB :: Region -> BufferM ()
joinLinesB = savingPointB . modifyRegionB g'
  where
    g' = overInit $ mconcat . pad . R.lines

    pad :: [R.YiString] -> [R.YiString]
    pad [] = []
    pad (x:xs) = x : fmap (skip (R.cons ' ' . R.dropWhile isSpace)) xs

    skip g x = if R.null x then x else g x

-- | Concatenates lines in the region preserving the trailing newline
-- if any.
joinLinesB :: Region -> BufferM ()
joinLinesB = savingPointB . modifyRegionB g'
  where
    g' = overInit $ mconcat . pad . R.lines

    pad :: [R.YiString] -> [R.YiString]
    pad [] = []
    pad (x:xs) = x : fmap (skip (R.cons ' ' . R.dropWhile isSpace)) xs

    skip g x = if R.null x then x else g x

-- | Concatenates lines in the region preserving the trailing newline
-- if any.
joinLinesB = savingPointB . modifyRegionB g'
  where
    g' = overInit $ mconcat . pad . R.lines

    pad :: [R.YiString] -> [R.YiString]
    pad [] = []
    pad (x:xs) = x : fmap (skip (R.cons ' ' . R.dropWhile isSpace)) xs

    skip g x = if R.null x then x else g x

-- | Concatenates lines in the region preserving the trailing newline
-- if any.