]> git.wincent.com - docvim.git/commitdiff
Center plugin header
authorGreg Hurrell <greg@hurrell.net>
Sat, 11 Jun 2016 02:18:56 +0000 (19:18 -0700)
committerGreg Hurrell <greg@hurrell.net>
Sat, 11 Jun 2016 02:19:45 +0000 (19:19 -0700)
Or "justify", if you prefer.

lib/Text/Docvim/Printer/Vim.hs
tests/fixtures/integration/ferret/golden/plaintext.golden
tests/fixtures/integration/scalpel/golden/plaintext.golden
tests/fixtures/vim/headings.golden
tests/fixtures/vim/integration-ferret-plugin.golden
tests/fixtures/vim/integration-pinnacle.golden

index b410b6fe88b9ef092ff4b799e0a04c675a0e789a..f99154f2fc4384031ee51f087bf71cec1936c341 100644 (file)
@@ -1,3 +1,5 @@
+{-# LANGUAGE MultiWayIf #-}
+
 module Text.Docvim.Printer.Vim (vimHelp) where
 
 import Control.Arrow
@@ -146,10 +148,16 @@ node n = case n of
 
 -- TODO: add {name}.txt to the symbol table?
 plugin :: String -> String -> Env
-plugin name desc = append $
-  "*" ++ name ++ ".txt*" ++
-  "    " ++ desc ++ "      " ++
-  "*" ++ name ++ "*" ++ "\n\n"
+plugin name desc = appendNoWrap $
+   (center filename desc (target name) " " " ") ++ "\n\n"
+  where
+    filename = "*" ++ name ++ ".txt*"
+    center a b c s1 s2 =
+        if | renderedWidth str >= textwidth -> str
+           | odd $ renderedWidth str        -> center a b c (s1 ++ " ") s2
+           | otherwise                      -> center a b c s1 (s2 ++ " ")
+      where
+        str = a ++ s1 ++ b ++ s2 ++ c
 
 -- | Append a newline.
 nl :: [Operation] -> Env
@@ -193,9 +201,9 @@ command :: Node -> Env
 command (CommandAnnotation name params) = do
   lhs <- append $ concat [":", name, " ", fromMaybe "" params]
   ws <- append " "
-  target <- linkTargets [":" ++ name] False
+  target' <- linkTargets [":" ++ name] False
   trailing <- append "\n"
-  return $ concat [lhs, ws, target, trailing]
+  return $ concat [lhs, ws, target', trailing]
 -- TODO indent what follows until next annotation...
 -- will require us to hoist it up inside CommandAnnotation
 -- (and do similar for other sections)
@@ -252,9 +260,9 @@ heading :: String -> Env
 heading h = do
   metadata <- ask
   heading' <- appendNoWrap $ map toUpper h ++ " "
-  target <- maybe (append "\n") (\x -> linkTargets [target' x] False) (pluginName metadata)
+  targ <- maybe (append "\n") (\x -> linkTargets [target' x] False) (pluginName metadata)
   trailing <- append "\n"
-  return $ concat [heading', target, trailing]
+  return $ concat [heading', targ, trailing]
   where
     target' x = normalize $ x ++ "-" ++ h
 
@@ -267,6 +275,9 @@ sanitize x = if isSpace x then '-' else x
 link :: String -> String
 link l = "|" ++ l ++ "|"
 
+target :: String -> String
+target t = "*" ++ t ++ "*"
+
 -- TODO: be prepared to wrap these if there are a lot of them
 -- TODO: fix code smell of passing in `wrap` bool here
 linkTargets :: [String] -> Bool -> Env
index 42633e40d724399279f8a36e5629cd642f6fff4c..ce9c740a59d42aa31992f3e8abc6c3e334f387c1 100644 (file)
@@ -1,4 +1,4 @@
-*ferret.txt*    Ferret plug-in for Vim      *ferret*
+*ferret.txt*                    Ferret plug-in for Vim                    *ferret*
 
 CONTENTS                                                       *ferret-contents*
 
index 61b8e9d347b42248b50dda42e8c4ca6f7a7b15d9..febb27760a9635d6d4798d224818fb53704f576b 100644 (file)
@@ -1,4 +1,4 @@
-*scalpel.txt*    Scalpel plug-in for Vim      *scalpel*
+*scalpel.txt*                   Scalpel plug-in for Vim                  *scalpel*
 
 CONTENTS                                                      *scalpel-contents*
 
index f42eb11eb7da2e1c46c051c8c8441797ed16eb0b..9919829fce5aa179391d479d9d16a61de6f7f68f 100644 (file)
@@ -1,4 +1,4 @@
-*foo.txt*    We need this because otherwise we don't get link targets      *foo*
+*foo.txt*      We need this because otherwise we don't get link targets      *foo*
 
 CONTENTS                                                          *foo-contents*
 
index 31d8a136c32674f9db271fba3a8db2fc156e49f5..8f8410f8697e36ac223e869a8be4c66f41d88535 100644 (file)
@@ -1,4 +1,4 @@
-*ferret.txt*    Ferret plug-in for Vim      *ferret*
+*ferret.txt*                    Ferret plug-in for Vim                    *ferret*
 
 CONTENTS                                                       *ferret-contents*
 
index 33c32781377ab2595beb75891b8a65bc39f22b49..7f148a2f874a840155b714f2177f848c72a1f35c 100644 (file)
@@ -1,4 +1,4 @@
-*Pinnacle.txt*    Highlight group manipulation for Vim      *Pinnacle*
+*Pinnacle.txt*           Highlight group manipulation for Vim           *Pinnacle*
 
 CONTENTS                                                     *pinnacle-contents*