Browse Source

added Clangd format_on_save (#621)

* clang autoformat do save lot of trouble

* clang autoformat do save lot of trouble

* clang indentation done, comments updated

* clang indentation done, comments updated

Co-authored-by: Mayank Sharma <info@Mayanks-MacBook-Air.local>
Mayank Dutta 4 years ago
parent
commit
7dc564c427
3 changed files with 18 additions and 1 deletions
  1. 10 0
      ftplugin/c.lua
  2. 2 1
      lua/default-config.lua
  3. 6 0
      utils/installer/lv-config.example.lua

+ 10 - 0
ftplugin/c.lua

@@ -19,3 +19,13 @@ require'lspconfig'.clangd.setup {
         })
     }
 }
+
+if O.lang.clang.autoformat then
+    require('lv-utils').define_augroups({
+      _clang_autoformat = {
+      {
+        'BufWritePre *.cpp lua vim.lsp.buf.formatting_sync(nil,1000)'
+
+      }
+    } })
+end

+ 2 - 1
lua/default-config.lua

@@ -150,7 +150,8 @@ O = {
                 underline = true,
             },
             cross_file_rename = true,
-            header_insertion = 'never'
+            header_insertion = 'never',
+            autoformat = false  -- update this to true for enabling autoformat
         },
         ruby = {
             diagnostics = {

+ 6 - 0
utils/installer/lv-config.example.lua

@@ -83,6 +83,12 @@ O.lang.go.autoformat = true
 
 -- rust
 O.lang.rust.autoformat = true
+
+-- clang
+O.lang.clang.autoformat = false -- Set to true to enable auto-format in C/C++ files.
+
+
+
 -- create custom autocommand field (This would be easy with lua)
 
 -- Turn off relative_numbers