xmonad / xmonad-contrib

Contributed modules for xmonad
https://xmonad.org
BSD 3-Clause "New" or "Revised" License
579 stars 271 forks source link

DocumentedKeys #867

Closed janesser closed 5 months ago

janesser commented 5 months ago

hello,

the idea is to have a quick and searchable overview of all keybindings. rather novice in haskell, open to comments.

cheers, Jan

Description

Include a description for your changes, including the motivation behind them.

Checklist

janesser commented 5 months ago

@slotThe totally missed, thanks for the pointer. looking deeper into it.

portnov commented 5 months ago

I had an idea to extend X.A.NamedActions to support more structured headers and prefixes... like,

data Actions =
    Actions String (Maybe String) [Actions]
  | Action String String (X ())

actions = Actions "All keybindings" Nothing [
  , Actions "Window manipulations" (Just "M-w ") [
      Action "l" "Switch to window to the right" $ windowGo R False
    , Action "k" "Switch to window to the top" $ windowGo U False
    , ...
  , Actions "Subheader" (Just "key prefix") [ sub actions ]
]

addKeysFromActions :: Actions -> [(String, X ())]

actionsToMarkdown :: Actions -> String

actionsToHtml :: Actions -> String
...

or I suspect we can invent even more pretty EDSL, like

actions = header "All keybindings" [
    header "Window manipulations" [
      header "Switch to another window" `withPrefix` "M-w " [
        key "l" "Switch to window to the right" $ windowGo R False
      , key "k" "Switch to window to the top" $ windowGo U False
      , ...
      ]
      , header "Move windows around" `withPrefix` "M-w S-" [
          key "l" "Move window to the right" $ windowSwap R False
        , ...
      ]
    ]
]

(sorry for messed up indents, I hope you understood what I meant :))

janesser commented 5 months ago

@portnov the idea of sectionizing the keybindings is great. i stumbled over some "submap" in NamedActions thing that could come in handy. ill include that in my thinking.

janesser commented 5 months ago

i substituted most of my config using X.U.NamedActions, see here: https://github.com/janesser/xmonad.hs/commit/3ddf243d550665c099aee876e6d869a47e5a5643

next TODOs

portnov commented 5 months ago

For me personally, the interest is mostly theoretical, as I seem to be able to memorize shortcuts that I invented :) However, one could think of structure like

janesser commented 5 months ago

CLOSING UP

original PR motivation is covered by XMonad.Util.NamedAction

Original auther already shared this thoughts on browsing NamedActions here: https://github.com/xmonad/xmonad-contrib/blob/f3ee6289ece46a55a362ff4b4f3107f8d3ecb35c/XMonad/Util/NamedActions.hs#L96

Quickwin:

myKeysConfig :: XConfig l -> XConfig l
myKeysConfig =
  addDescrKeys
    ((mod4Mask .|. shiftMask, xK_h), noName . myKeysPrompt def )
    (myBasicKeys <+> myWindowKeys <+> myJournalKeys)

...

xKeysPrompt :: XPConfig -> [((KeyMask, KeySym), NamedAction)] -> X ()
xKeysPrompt c keylist = do
  mkXPrompt Bindings c (mkComplFunFromList' c $ showKmSimple keylist) doIt
 where
  doIt k = spawn $ "xdotool key " ++ doToolKey k
  doToolKey = intercalate "+" . map doControlKey . splitOn "-"
  doControlKey "C" = "Control_L"
  doControlKey "S" = "Shift_L"
  doControlKey "M4" = "Super_L"
  doControlKey k = filter (/= '>') $ filter (/= '<') k

data Bindings = Bindings
instance XPrompt Bindings where
  showXPrompt Bindings = "Bindings: "

-- Searching by names would be something, whilst `mkComplFunFromList'` is prefix-search.