Skip to content

Commit

Permalink
Remove Yi.Core.msgEditor, because we already have Yi.Editor.printMsg.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethercrow committed Oct 11, 2014
1 parent b334798 commit 0fc9bc6
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 50 deletions.
6 changes: 3 additions & 3 deletions yi/src/library/Yi/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import qualified Data.Text as T
import Data.Typeable
import System.Exit (ExitCode(..))
import Yi.Buffer
import Yi.Core (msgEditor, startSubprocess)
import Yi.Core (startSubprocess)
import Yi.Dynamic
import Yi.Editor
import Yi.Keymap
Expand Down Expand Up @@ -64,13 +64,13 @@ shellCommandV cmd = do
then withEditor . void $ -- see GitHub issue #477
newBufferE (MemBuffer "Shell Command Output")
(R.fromString cmdOut)
else msgEditor $ case T.pack cmdOut of
else (withEditor . printMsg) $ case T.pack cmdOut of
"" -> "(Shell command with no output)"
-- Drop trailing newline from output
xs -> if T.last xs == '\n' then T.init xs else xs
-- FIXME: here we get a string and convert it back to utf8;
-- this indicates a possible bug.
ExitFailure _ -> msgEditor $ T.pack cmdErr
ExitFailure _ -> (withEditor . printMsg) $ T.pack cmdErr

----------------------------
-- Cabal-related commands
Expand Down
20 changes: 8 additions & 12 deletions yi/src/library/Yi/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Yi.Core
, userForceRefresh

-- * Global editor actions
, msgEditor -- :: String -> YiM ()
, errorEditor -- :: String -> YiM ()
, closeWindow -- :: YiM ()

Expand Down Expand Up @@ -336,18 +335,15 @@ runProcessWithInput cmd inp = do

------------------------------------------------------------------------

-- | Same as 'msgEditor', but do nothing instead of printing @()@
msgEditor' :: T.Text -> YiM ()
msgEditor' "()" = return ()
msgEditor' s = msgEditor s
-- | Same as 'Yi.Editor.printMsg', but do nothing instead of printing @()@
msgEditor :: T.Text -> YiM ()
msgEditor "()" = return ()
msgEditor s = withEditor (printMsg s)

runAction :: Action -> YiM ()
runAction (YiA act) = act >>= msgEditor' . showT
runAction (EditorA act) = withEditor act >>= msgEditor' . showT
runAction (BufferA act) = withBuffer act >>= msgEditor' . showT

msgEditor :: T.Text -> YiM ()
msgEditor = withEditor . printMsg
runAction (YiA act) = act >>= msgEditor . showT
runAction (EditorA act) = withEditor act >>= msgEditor . showT
runAction (BufferA act) = withBuffer act >>= msgEditor . showT

-- | Show an error on the status line and log it.
errorEditor :: T.Text -> YiM ()
Expand Down Expand Up @@ -459,7 +455,7 @@ sendToProcess bufref s = do
yi <- ask
find ((== bufref) . bufRef) . yiSubprocesses <$> liftBase (readMVar (yiVar yi)) >>= \case
Just subProcessInfo -> io $ hPutStr (hIn subProcessInfo) s
Nothing -> msgEditor "Could not get subProcessInfo in sendToProcess"
Nothing -> withEditor (printMsg "Could not get subProcessInfo in sendToProcess")

pipeToBuffer :: Handle -> (String -> IO ()) -> IO ()
pipeToBuffer h append = void . ignoringException . forever $ do
Expand Down
40 changes: 20 additions & 20 deletions yi/src/library/Yi/Dired.hs
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ procDiredOp counting r@(DOChoice prompt op:ops) = do
allAction = do cleanUp
modDiredOpState (\st -> st{diredOpForAll=True})
proceedYes
quit = cleanUp >> msgEditor "Quit"
quit = cleanUp >> (withEditor . printMsg) "Quit"
help = do
msgEditor $ "y: yes, n: no, " <> "!: yes on all remaining items, "
(withEditor . printMsg) $ "y: yes, n: no, " <> "!: yes on all remaining items, "
<> "q: quit, h: help"
cleanUp
procDiredOp counting r -- repeat
Expand Down Expand Up @@ -382,9 +382,9 @@ askDelFiles dir fs =
ops = map opGenerator fs
showResult st = do
diredRefresh
msgEditor $ showT (diredOpSucCnt st) <> " of "
(withEditor . printMsg) $ showT (diredOpSucCnt st) <> " of "
<> showT total <> " deletions done"
showNothing _ = msgEditor "(No deletions requested)"
showNothing _ = (withEditor . printMsg) "(No deletions requested)"
total = length fs
opGenerator :: (FilePath, DiredEntry) -> IO DiredOp
opGenerator (fn, de) = do
Expand Down Expand Up @@ -438,7 +438,7 @@ diredKeymap =

dired :: YiM ()
dired = do
msgEditor "Dired..."
(withEditor . printMsg) "Dired..."
maybepath <- withBuffer $ gets file
dir <- io $ getFolder maybepath
void $ editFile dir
Expand Down Expand Up @@ -744,9 +744,9 @@ askRenameFiles dir fs =
ckParentDir = doesDirectoryExist $ takeDirectory (dropTrailingPathSeparator t)
showResult st = do
diredRefresh
msgEditor $ showT (diredOpSucCnt st) <> " of "
(withEditor . printMsg) $ showT (diredOpSucCnt st) <> " of "
<> showT total <> " item(s) moved."
showNothing _ = msgEditor "Quit"
showNothing _ = (withEditor . printMsg) "Quit"
total = length fs

-- | copy selected files in a given directory to the target location given
Expand Down Expand Up @@ -790,9 +790,9 @@ askCopyFiles dir fs =
takeDirectory (dropTrailingPathSeparator t)
showResult st = do
diredRefresh
msgEditor $ showT (diredOpSucCnt st) <> " of "
(withEditor . printMsg) $ showT (diredOpSucCnt st) <> " of "
<> showT total <> " item(s) copied."
showNothing _ = msgEditor "Quit"
showNothing _ = (withEditor . printMsg) "Quit"
total = length fs
op4Type :: DiredEntry -> FilePath -> FilePath -> DiredOp
op4Type (DiredDir _) = DOCopyDir
Expand Down Expand Up @@ -831,46 +831,46 @@ diredLoad = do
exists <- io $ doesFileExist sel
if exists
then void $ editFile sel
else msgEditor $ sel' <> " no longer exists"
else (withEditor . printMsg) $ sel' <> " no longer exists"
(DiredDir _dfi) -> do
exists <- io $ doesDirectoryExist sel
if exists
then diredDir sel
else msgEditor $ sel' <> " no longer exists"
else (withEditor . printMsg) $ sel' <> " no longer exists"
(DiredSymLink _dfi dest) -> do
let target = if isAbsolute dest then dest else dir </> dest
existsFile <- io $ doesFileExist target
existsDir <- io $ doesDirectoryExist target
msgEditor $ "Following link:" <> T.pack target
(withEditor . printMsg) $ "Following link:" <> T.pack target
if existsFile then void $ editFile target else
if existsDir then diredDir target else
msgEditor $ T.pack target <> " does not exist"
(withEditor . printMsg) $ T.pack target <> " does not exist"
(DiredSocket _dfi) -> do
exists <- io $ doesFileExist sel
msgEditor (if exists
(withEditor . printMsg) (if exists
then "Can't open Socket " <> sel'
else sel' <> " no longer exists")
(DiredBlockDevice _dfi) -> do
exists <- io $ doesFileExist sel
msgEditor (if exists
(withEditor . printMsg) (if exists
then "Can't open Block Device " <> sel'
else sel' <> " no longer exists")
(DiredCharacterDevice _dfi) -> do
exists <- io $ doesFileExist sel
msgEditor (if exists
(withEditor . printMsg) (if exists
then "Can't open Character Device " <> sel'
else sel' <> " no longer exists")
(DiredNamedPipe _dfi) -> do
exists <- io $ doesFileExist sel
msgEditor (if exists
(withEditor . printMsg) (if exists
then "Can't open Pipe " <> sel'
else sel' <> " no longer exists")
DiredNoInfo -> msgEditor $ "No File Info for:" <> sel'
DiredNoInfo -> (withEditor . printMsg) $ "No File Info for:" <> sel'
Nothing -> noFileAtThisLine


noFileAtThisLine :: YiM ()
noFileAtThisLine = msgEditor "(No file at this line)"
noFileAtThisLine = (withEditor . printMsg) "(No file at this line)"

-- | Extract the filename at point. NB this may fail if the buffer has been edited. Maybe use Markers instead.
fileFromPoint :: BufferM (Maybe (FilePath, DiredEntry))
Expand Down Expand Up @@ -898,7 +898,7 @@ diredCreateDir =
withMinibufferFree "Create Dir:" $ \nm -> do
dir <- currentDir
let newdir = dir </> T.unpack nm
msgEditor $ "Creating " <> T.pack newdir <> "..."
(withEditor . printMsg) $ "Creating " <> T.pack newdir <> "..."
io $ createDirectoryIfMissing True newdir
diredRefresh

Expand Down
4 changes: 2 additions & 2 deletions yi/src/library/Yi/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Text.Read (readMaybe)
import Yi.Boot.Internal (reload)
import Yi.Buffer
import Yi.Config.Simple.Types
import Yi.Core (errorEditor, msgEditor, runAction)
import Yi.Core (errorEditor, runAction)
import Yi.Debug
import Yi.Dynamic
import Yi.Editor
Expand Down Expand Up @@ -244,7 +244,7 @@ parseErrorMessageB = parseErrorMessage <$> readLnB
-- 'parseErrorMessageB'.
jumpToErrorE :: YiM ()
jumpToErrorE = withBuffer parseErrorMessageB >>= \case
Nothing -> msgEditor "Couldn't parse out an error message."
Nothing -> (withEditor . printMsg) "Couldn't parse out an error message."
Just (f, l, c) -> jumpToE f l c

prompt :: R.YiString
Expand Down
12 changes: 6 additions & 6 deletions yi/src/library/Yi/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ revertE = do
now <- io getCurrentTime
s <- liftBase $ R.readFile fp
withBuffer $ revertB s now
msgEditor ("Reverted from " <> showT fp)
Nothing -> msgEditor "Can't revert, no file associated with buffer."
(withEditor . printMsg) ("Reverted from " <> showT fp)
Nothing -> (withEditor . printMsg) "Can't revert, no file associated with buffer."


-- | Try to write a file in the manner of vi\/vim
Expand All @@ -68,7 +68,7 @@ viWrite = do
let message = (showT f <>) (if f == s
then " written"
else " " <> showT s <> " written")
msgEditor message
(withEditor . printMsg) message

-- | Try to write to a named file in the manner of vi/vim
viWriteTo :: T.Text -> YiM ()
Expand All @@ -79,7 +79,7 @@ viWriteTo f = do
let message = f `T.append` if f == s
then " written"
else ' ' `T.cons` s `T.append` " written"
msgEditor message
(withEditor . printMsg) message

-- | Try to write to a named file if it doesn't exist. Error out if it does.
viSafeWriteTo :: T.Text -> YiM ()
Expand All @@ -100,11 +100,11 @@ fwriteBufferE bufferKey = do
<*> streamB Forward 0)
case nameContents of
(Just f, contents) -> io (doesDirectoryExist f) >>= \case
True -> msgEditor "Can't save over a directory, doing nothing."
True -> (withEditor . printMsg) "Can't save over a directory, doing nothing."
False -> do
liftBase $ R.writeFile f contents
io getCurrentTime >>= withGivenBuffer bufferKey . markSavedB
(Nothing, _c) -> msgEditor "Buffer not associated with a file"
(Nothing, _c) -> (withEditor . printMsg) "Buffer not associated with a file"

-- | Write current buffer to disk as @f@. The file is also set to @f@.
fwriteToE :: T.Text -> YiM ()
Expand Down
8 changes: 4 additions & 4 deletions yi/src/library/Yi/Keymap/Emacs/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import System.FilePath (takeDirectory, takeFileName, (</>))
import System.FriendlyPath ()
import Yi.Buffer
import Yi.Command (cabalConfigureE, cabalBuildE, reloadProjectE)
import Yi.Core (msgEditor, quitEditor)
import Yi.Core (quitEditor)
import Yi.Editor
import Yi.Eval
import Yi.File
Expand Down Expand Up @@ -272,7 +272,7 @@ 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
(withEditor . printMsg) $ "loading " <> filename
void $ editFile (T.unpack filename) >>= act

-- | Open a file using the minibuffer. We have to set up some stuff to
Expand All @@ -289,7 +289,7 @@ findFileReadOnly = findFileAndDo "find file (read only):" $ \b ->
findFileNewTab :: YiM ()
findFileNewTab = promptFile "find file (new tab): " $ \filename -> do
withEditor newTabE
msgEditor $ "loading " <> filename
(withEditor . printMsg) $ "loading " <> filename
void . editFile $ T.unpack filename


Expand Down Expand Up @@ -450,7 +450,7 @@ countWordsRegion = do
t <- withBuffer0 $ getRectangle >>= \(reg, _, _) -> readRegionB reg
let nls = R.countNewLines t
return (if nls == 0 then 1 else nls, length $ R.words t, R.length t)
msgEditor $ T.unwords [ "Region has", showT l, p l "line" <> ","
(withEditor . printMsg) $ T.unwords [ "Region has", showT l, p l "line" <> ","
, showT w, p w "word" <> ", and"
, showT c, p w "character" <> "."
]
Expand Down
4 changes: 2 additions & 2 deletions yi/src/library/Yi/Mode/Haskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Data.Typeable
import Prelude hiding (and,error,elem,notElem,all,concatMap,exp)
import Text.Read (readMaybe)
import Yi.Buffer
import Yi.Core (msgEditor, sendToProcess)
import Yi.Core (sendToProcess)
import Yi.Debug
import Yi.Dynamic
import Yi.Editor
Expand Down Expand Up @@ -469,5 +469,5 @@ ghciSetProcessArgs = do
]
withMinibufferFree prompt $ \arg ->
case readMaybe $ T.unpack arg of
Nothing -> msgEditor "Could not parse as [String], keep old args."
Nothing -> (withEditor . printMsg) "Could not parse as [String], keep old args."
Just arg' -> setDynamic $ g & GHCi.ghciProcessArgs .~ arg'
3 changes: 2 additions & 1 deletion yi/src/library/Yi/Mode/IReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Data.Text ()
import Control.Lens
import Data.Char (intToDigit)
import Yi.Buffer.Misc
import Yi.Editor
import Yi.IReader
import Yi.Keymap
import Yi.Keymap.Keys
Expand All @@ -41,4 +42,4 @@ ireadMode :: YiM ()
ireadMode = do
withBuffer $ setAnyMode $ AnyMode ireaderMode
nextArticle
msgEditor "M-` new; M-0 delete; M-[1-9]: save w/higher priority"
(withEditor . printMsg) "M-` new; M-0 delete; M-[1-9]: save w/higher priority"

0 comments on commit 0fc9bc6

Please sign in to comment.