Skip to content

Commit

Permalink
Implement C-x C-r (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuuzetsu committed Oct 5, 2014
1 parent 5d9ab45 commit 4c1079d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion yi/src/library/Yi/Keymap/Emacs.hs
Expand Up @@ -42,7 +42,8 @@ import Yi.Keymap.Emacs.Utils
(askQuitEditor, evalRegionE, executeExtendedCommandE, findFile,
findFileNewTab, promptFile, insertNextC, isearchKeymap, killBufferE,
queryReplaceE, readUniversalArg, scrollDownE, scrollUpE, switchBufferE,
askSaveEditor, argToInt, promptTag, justOneSep, joinLinesE, countWordsRegion)
askSaveEditor, argToInt, promptTag, justOneSep, joinLinesE, countWordsRegion,
findFileReadOnly)
import Yi.MiniBuffer
import Yi.Misc (adjBlock, adjIndent)
import Yi.Mode.Buffers ( listBuffers )
Expand Down Expand Up @@ -264,6 +265,7 @@ emacsKeys univArg =
, ctrlCh 'b' ?>>! listBuffers
, ctrlCh 'c' ?>>! askQuitEditor
, ctrlCh 'f' ?>>! findFile
, ctrlCh 'r' ?>>! findFileReadOnly
, ctrlCh 'q' ?>>! withBuffer0 (readOnlyA %= not)
, ctrlCh 's' ?>>! fwriteE
, ctrlCh 'w' ?>>! promptFile "Write file:" fwriteToE
Expand Down
18 changes: 15 additions & 3 deletions yi/src/library/Yi/Keymap/Emacs/Utils.hs
Expand Up @@ -41,6 +41,7 @@ module Yi.Keymap.Emacs.Utils
, killBufferE
, insertNextC
, findFile
, findFileReadOnly
, findFileNewTab
, promptFile
, promptTag
Expand Down Expand Up @@ -262,12 +263,23 @@ readUniversalArg :: KeymapM (Maybe Int)
readUniversalArg = optional ((ctrlCh 'u' ?>> (read <$> some (digit id) <|> pure 4)) <|> (read <$> some tt))


-- | Finds file and runs specified action on the resulting buffer
findFileAndDo :: T.Text -- ^ Prompt
-> (BufferRef -> YiM a) -- ^ Action to run on the resulting buffer
-> YiM ()
findFileAndDo prompt act = promptFile prompt $ \filename -> do
msgEditor $ "loading " <> filename
void $ editFile (T.unpack filename) >>= act

-- | Open a file using the minibuffer. We have to set up some stuff to
-- allow hints and auto-completion.
findFile :: YiM ()
findFile = promptFile "find file:" $ \filename -> do
msgEditor $ "loading " <> filename
void $ editFile (T.unpack filename)
findFile = findFileAndDo "find file:" return

-- | Like 'findFile' but sets the resulting buffer to read-only.
findFileReadOnly :: YiM ()
findFileReadOnly = findFileAndDo "find file (read only):" $ \b ->
withGivenBuffer b (readOnlyA .= True)

-- | Open a file in a new tab using the minibuffer.
findFileNewTab :: YiM ()
Expand Down

0 comments on commit 4c1079d

Please sign in to comment.