Partial implementation of pruning empty paths
authorGreg Hurrell <greg@hurrell.net>
Sat, 11 Jun 2016 06:03:56 +0000 (23:03 -0700)
committerGreg Hurrell <greg@hurrell.net>
Sat, 11 Jun 2016 06:03:56 +0000 (23:03 -0700)
Partly addresses: https://github.com/wincent/docvim/issues/9

15 files changed:
docvim.cabal
lib/Text/Docvim/Compile.hs
lib/Text/Docvim/Printer/Vim.hs
tests/fixtures/parser/command.golden
tests/fixtures/parser/comments.golden
tests/fixtures/parser/empty.golden
tests/fixtures/parser/integration-docvim.golden
tests/fixtures/parser/integration-ferret-ftplugin-qf.golden
tests/fixtures/parser/integration-ferret-plugin.golden
tests/fixtures/parser/integration-ferret-private.golden
tests/fixtures/parser/integration-pinnacle.golden
tests/fixtures/parser/just-whitespace.golden
tests/fixtures/parser/minimal-annotation.golden
tests/fixtures/parser/plugin-annotation.golden
tests/fixtures/parser/simple-annotations.golden

index 59f45934b144de593af65a874b546cf7ff55e0e6..5c46133990d03538b95ba2ea15f69fc20fd568a3 100644 (file)
@@ -97,6 +97,7 @@ library
   exposed-modules:  Text.Docvim.AST
                  ,  Text.Docvim.CLI
                  ,  Text.Docvim.Compile
+                 ,  Text.Docvim.Optimize
                  ,  Text.Docvim.Options
                  ,  Text.Docvim.Parse
                  ,  Text.Docvim.Printer.Markdown
@@ -151,6 +152,7 @@ test-suite tasty
                ,    temporary
   other-modules:     Text.Docvim.AST
                ,     Text.Docvim.Compile
+               ,     Text.Docvim.Optimize
                ,     Text.Docvim.Parse
                ,     Text.Docvim.Printer.Markdown
                ,     Text.Docvim.Printer.Vim
index efed5848831db9971cd76109a5a421a31a772b10..afb09bc14daf704ae65b3480afc08037f4810c0b 100644 (file)
@@ -1,6 +1,7 @@
 module Text.Docvim.Compile (compile) where
 
 import Text.Docvim.AST
+import Text.Docvim.Optimize
 import Text.Docvim.Visitor
 import Text.Docvim.Visitor.Command
 import Text.Docvim.Visitor.Commands
@@ -33,7 +34,7 @@ compile ns = do
   let (ast9, options) = extract extractOptions ast8
   let (ast10, option) = extract extractOption ast9
   let (ast11, footer) = extract extractFooter ast10
-  injectTOC $ Project $ concat [ plugin
+  optimize $ injectTOC $ Project $ concat [ plugin
                                , [ast11]
                                , commands
                                , command
index 5c4f4b8e7572545bb16db2f96537cb3b69f41d07..908448b88943e42fcf6bed19d5e20f7a8720ee18 100644 (file)
@@ -148,7 +148,7 @@ node n = case n of
 
 plugin :: String -> String -> Env
 plugin name desc = appendNoWrap $
-   (center filename desc (target normalized) " " " ") ++ "\n\n"
+   center filename desc (target normalized) " " " " ++ "\n\n"
   where
     filename = "*" ++ normalized ++ ".txt*"
     normalized = map toLower name
index f8458bd2db73a3bd7e0cf275f6abc1c3b25acc51..1cbe19519bc66cc8e44c76212e6ace749ac1dee4 100644 (file)
@@ -1,5 +1,5 @@
 Project
-  [ Project [ Unit [ DocBlock [] ] , DocBlock [] ]
+  [ Empty
   , CommandsAnnotation
   , CommandAnnotation "Ack" (Just "{pattern} {options}")
   , Paragraph [ Plaintext "Info." ]
index 940306e712f3dfc141a0db0034cf9101d733a6d2..53a90bffae3d87177f8eeb064b8fc81d1f9a3781 100644 (file)
@@ -1 +1 @@
-Project [ Project [ Unit [] ] ]
+Empty
index 940306e712f3dfc141a0db0034cf9101d733a6d2..53a90bffae3d87177f8eeb064b8fc81d1f9a3781 100644 (file)
@@ -1 +1 @@
-Project [ Project [ Unit [] ] ]
+Empty
index 94832768c274c21c2cf17a2b957f8800a57ff58e..5a68d50b3251e242a5e277550303c6cb03d93bba 100644 (file)
@@ -935,5 +935,5 @@ Project
       [ ListItem
           [ Plaintext "Initial" , Whitespace , Plaintext "release." ]
       ]
-  , Project [ Unit [ DocBlock [] ] ]
+  , Empty
   ]
index ace589f7fb0b582bb8af11a301915ab4d2360bb3..8c6174e3d238506421a3df9da1f4f1c745eb7a68 100644 (file)
@@ -1,7 +1,7 @@
 Project
   [ Project
       [ Unit
-          [ DocBlock []
+          [ Empty
           , LetStatement
               { letLexpr = "s:options"
               , letValue = "get(g:, 'FerretQFOptions', 1)"
@@ -26,7 +26,7 @@ Project
           , GenericStatement "augroup END"
           , GenericStatement "endif"
           , GenericStatement "endif"
-          , DocBlock []
+          , Empty
           , LetStatement
               { letLexpr = "s:map" , letValue = "get(g:, 'FerretQFMap', 1)" }
           , GenericStatement "if s:map"
@@ -38,7 +38,7 @@ Project
               "vnoremap <buffer> <silent> d :call ferret#private#qf_delete()<CR>"
           , GenericStatement "endif"
           ]
-      , DocBlock []
+      , Empty
       ]
   , OptionsAnnotation
   , OptionAnnotation "g:FerretQFOptions" "boolean" (Just "1")
index 9b0498264e51c0f5cb92be86e2d9b460788e149c..f68d84391fcbb2cb0d00936fb3a482288936285d 100644 (file)
@@ -829,8 +829,8 @@ Project
   , Fenced [ ":call pathogen#helptags()" ]
   , Project
       [ Unit
-          [ DocBlock []
-          , DocBlock []
+          [ Empty
+          , Empty
           , GenericStatement
               "if exists('g:FerretLoaded') || &compatible || v:version < 700"
           , GenericStatement "finish"
@@ -867,50 +867,50 @@ Project
           , GenericStatement "autocmd QuickFixCmdPost l* nested lwindow"
           , GenericStatement "augroup END"
           , GenericStatement "endif"
-          , DocBlock []
+          , Empty
           , GenericStatement
               "command! -nargs=+ -complete=file Ack call ferret#private#ack(<q-args>)"
-          , DocBlock []
+          , Empty
           , GenericStatement
               "command! -nargs=+ -complete=file Lack call ferret#private#lack(<q-args>)"
-          , DocBlock []
+          , Empty
           , GenericStatement
               "command! -nargs=1 Acks call ferret#private#acks(<q-args>)"
-          , DocBlock []
+          , Empty
           , LetStatement
               { letLexpr = "s:map" , letValue = "get(g:, 'FerretMap', 1)" }
           , GenericStatement "if s:map"
           , GenericStatement
               "if !hasmapto('<Plug>(FerretAck)') && maparg('<leader>a', 'n') ==# ''"
-          , DocBlock []
+          , Empty
           , GenericStatement "nmap <unique> <leader>a <Plug>(FerretAck)"
           , GenericStatement "endif"
           , GenericStatement "nnoremap <Plug>(FerretAck) :Ack<space>"
           , GenericStatement
               "if !hasmapto('<Plug>FerretLack') && maparg('<leader>l', 'n') ==# ''"
-          , DocBlock []
+          , Empty
           , GenericStatement "nmap <unique> <leader>l <Plug>(FerretLack)"
           , GenericStatement "endif"
           , GenericStatement "nnoremap <Plug>(FerretLack) :Lack<space>"
           , GenericStatement
               "if !hasmapto('<Plug>(FerretAckWord)') && maparg('<leader>s', 'n') ==# ''"
-          , DocBlock []
+          , Empty
           , GenericStatement "nmap <unique> <leader>s <Plug>(FerretAckWord)"
           , GenericStatement "endif"
           , GenericStatement
               "nnoremap <Plug>(FerretAckWord) :Ack <C-r><C-w><CR>"
           , GenericStatement
               "if !hasmapto('<Plug>(FerretAcks)') && maparg('<leader>r', 'n') ==# ''"
-          , DocBlock []
+          , Empty
           , GenericStatement "nmap <unique> <leader>r <Plug>(FerretAcks)"
           , GenericStatement "endif"
           , GenericStatement
               "nnoremap <Plug>(FerretAcks) :Acks <c-r>=(exists('g:ferret_lastsearch') ? '/' . g:ferret_lastsearch . '//' : ' ')<CR><Left>"
           , GenericStatement "endif"
-          , DocBlock []
+          , Empty
           , GenericStatement
               "command! -bar Qargs execute 'args' ferret#private#qargs()"
-          , DocBlock []
+          , Empty
           , LetStatement
               { letLexpr = "s:commands"
               , letValue = "get(g:, 'FerretQFCommands', 1)"
@@ -929,8 +929,8 @@ Project
               { letLexpr = "&cpoptions " , letValue = "s:cpoptions" }
           , UnletStatement { unletBang = False , unletBody = "s:cpoptions" }
           ]
-      , DocBlock []
-      , DocBlock []
+      , Empty
+      , Empty
       ]
   , CommandsAnnotation
   , CommandAnnotation "Ack" (Just "{pattern} {options}")
index 90cc3836d257ba317d29842ef03c4b0392390d3a..f01965a44412cd993a2376b007718cc7c0268490 100644 (file)
@@ -25,7 +25,7 @@ Project
               , functionArguments = ArgumentList []
               , functionAttributes = []
               , functionBody =
-                  [ DocBlock []
+                  [ Empty
                   , LetStatement
                       { letLexpr = "l:dispatch"
                       , letValue = "get(g:, 'FerretDispatch', 1)"
@@ -247,7 +247,7 @@ Project
               , functionAttributes = [ "abort" ]
               , functionBody =
                   [ GenericStatement "if has('extra_search')"
-                  , DocBlock []
+                  , Empty
                   , LetStatement
                       { letLexpr = "l:hlsearch"
                       , letValue = "get(g:, 'FerretHlsearch', &hlsearch)"
@@ -345,7 +345,7 @@ Project
                   ]
               }
           ]
-      , DocBlock []
+      , Empty
       ]
   , OptionsAnnotation
   , OptionAnnotation "g:FerretDispatch" "boolean" (Just "1")
index 4088fd691235e811d8cf3b15d40b9af3d098624f..a3e72572997bcb6ab71d6207157966f901ed5d47 100644 (file)
@@ -774,5 +774,5 @@ Project
       [ ListItem
           [ Plaintext "Initial" , Whitespace , Plaintext "release." ]
       ]
-  , Project [ Unit [ DocBlock [] ] ]
+  , Empty
   ]
index 940306e712f3dfc141a0db0034cf9101d733a6d2..53a90bffae3d87177f8eeb064b8fc81d1f9a3781 100644 (file)
@@ -1 +1 @@
-Project [ Project [ Unit [] ] ]
+Empty
index 899351d6ce8ee908ac81ab1465715405307460a1..f0d9c2723a61ad9d44346868f1cf9c7165a72ba5 100644 (file)
@@ -1,4 +1,2 @@
 Project
-  [ DocBlock [ PluginAnnotation "Foo" "Bar" , TOC [] ]
-  , Project [ Unit [ DocBlock [] ] ]
-  ]
+  [ DocBlock [ PluginAnnotation "Foo" "Bar" , TOC [] ] , Empty ]
index 085f0e0a81fd59ee5bde0b3c63a81a051f2caa47..7e2d34f8d6a3345f0b0555c5d76d98d48fb84b12 100644 (file)
@@ -3,5 +3,5 @@ Project
       [ PluginAnnotation "Foo" "Description with trailing whitespace"
       , TOC []
       ]
-  , Project [ Unit [ DocBlock [] ] ]
+  , Empty
   ]
index a002a58f3a8d087a1104e2ce3bc062447bb50303..c070693a7fb8f6228e8b02d69b7ba5b20b7b5205 100644 (file)
@@ -4,7 +4,7 @@ Project
   , Project
       [ Unit
           [ LetStatement { letLexpr = "g:x" , letValue = "1 \"Unset!" }
-          , DocBlock []
+          , Empty
           , LetStatement { letLexpr = "g:y" , letValue = "1" }
           ]
       ]