xmonad-contrib/XMonad/Util/SpawnOnce.hs
Adam Plaice ca866229f6 Fix most remaining broken inter-module docs links
The links were broken due to:

1. Incorrect quotes (' instead of " for module links and occasionally
vice-versa).

2. Changes in the name of the "target" module not reflected in the
"source" docs.

3. Typos to begin with.

4. Use of `<foo>` in the docs is rendered as just `foo` with a link to
`/foo`.

5. Similarly for `"Foo"` if it starts with a capital letter (and hence
could be a module).

6. Markup inside `@` code blocks still being applied.

e.g. `@M-<arrow-keys>@` is rendered as `M-arrow-keys` with a spurious
hyperlink from arrow-keys to `/arrow-keys`, which is confusing.

Three links from XMonad.Util.Run have been removed outright, since
they're no longer examples of the usage of 'runProcessWithInput'.
WmiiActions has been gone since 2008, while XMonad.Prompt.Directory
and XMonad.Layout.WorkspaceDir haven't been using
'runProcessWithInput' since 2020 and 2012, respectively.

In some cases the `<foo>` were surrounded with @, especially in the
case of key definitions, for consistency.  (This wasn't done
everywhere, because it looks ugly in the source.)

MoreManageHelpers has never been in xmonad-contrib.  ManageHelpers
seems to fill the expected role.

In the case of the module description for X.H.ManageDebug the quotes
were simply removed because none of the likely options to make the
link work were successful.
2022-11-01 19:35:55 +01:00

73 lines
2.5 KiB
Haskell

-----------------------------------------------------------------------------
-- |
-- Module : XMonad.Util.SpawnOnce
-- Description : A module for spawning a command once, and only once.
-- Copyright : (c) Spencer Janssen 2009
-- License : BSD3-style (see LICENSE)
--
-- Maintainer : spencerjanssen@gmail.com
-- Stability : unstable
-- Portability : not portable
--
-- A module for spawning a command once, and only once. Useful to start
-- status bars and make session settings inside startupHook. See also
-- "XMonad.Util.SessionStart" for a different and more flexible way to
-- run commands only on first startup.
--
-----------------------------------------------------------------------------
module XMonad.Util.SpawnOnce (spawnOnce,
-- * 'SpawnOn' helpers
-- $spawnon
manageSpawn,
spawnOnOnce,
spawnNOnOnce,
spawnAndDoOnce) where
import XMonad
import XMonad.Actions.SpawnOn
import Data.Set as Set
import qualified XMonad.Util.ExtensibleState as XS
import XMonad.Prelude
newtype SpawnOnce = SpawnOnce { unspawnOnce :: Set String }
deriving (Read, Show)
instance ExtensionClass SpawnOnce where
initialValue = SpawnOnce Set.empty
extensionType = PersistentExtension
doOnce :: (String -> X ()) -> String -> X ()
doOnce f s = do
b <- XS.gets (Set.member s . unspawnOnce)
unless b $ do
f s
XS.modify (SpawnOnce . Set.insert s . unspawnOnce)
-- | The first time 'spawnOnce' is executed on a particular command,
-- that command is executed. Subsequent invocations for a command do
-- nothing.
spawnOnce :: String -> X ()
spawnOnce = doOnce spawn
-- $spawnon
-- These functions combine 'spawnOnce' with their relatives in
-- "XMonad.Actions.SpawnOn". You must add 'manageSpawn' to your
-- @manageHook@ for them to work, as with @SpawnOn@.
-- | Like 'spawnOnce' but launches the application on the given workspace.
spawnOnOnce :: WorkspaceId -> String -> X ()
spawnOnOnce ws = doOnce (spawnOn ws)
-- | Lanch the given application n times on the specified
-- workspace. Subsequent attempts to spawn this application will be
-- ignored.
spawnNOnOnce :: Int -> WorkspaceId -> String -> X ()
spawnNOnOnce n ws = doOnce (replicateM_ n . spawnOn ws)
-- | Spawn the application once and apply the manage hook. Subsequent
-- attempts to spawn this application will be ignored.
spawnAndDoOnce :: ManageHook -> String -> X ()
spawnAndDoOnce mh = doOnce (spawnAndDo mh)