{"id":3355,"date":"2018-11-23T09:30:34","date_gmt":"2018-11-23T08:30:34","guid":{"rendered":"https:\/\/vizZzion.org\/blog\/?p=3355"},"modified":"2018-11-23T09:35:32","modified_gmt":"2018-11-23T08:35:32","slug":"different-indentation-styles-per-filetype","status":"publish","type":"post","link":"https:\/\/vizZzion.org\/blog\/2018\/11\/different-indentation-styles-per-filetype\/","title":{"rendered":"Different indentation styles per filetype"},"content":{"rendered":"<p>For my hacking, I love to use the <a href=\"https:\/\/www.kdevelop.org\/\">KDevelop<\/a> IDE. Once in a while, I find myself working on a project that has different indentation styles depending on the filetype &#8212; in this case, C++ files, Makefiles, etc. use tabs, JavaScript and HTML files use 2 spaces. I haven&#8217;t found this to be straight-forward from KDevelop&#8217;s configuration dialog (though I just learnt that it does seem to be possible). I did find myself having to fix indentation before committing (annoying!) and even having to fix up the indentation of code committed by myself (embarrassing!). As that&#8217;s both stupid and repetitive work, it&#8217;s something I wanted to avoid. Here&#8217;s how it&#8217;s done using <a href=\"https:\/\/editorconfig.org\/\">EditorConfig<\/a> files:<\/p>\n<ol>\n<li>put a file called <code>.editorconfig<\/code> in the project&#8217;s root directory<\/li>\n<li>specify a default style and then a specialization for certain filetypes<\/li>\n<li>restart KDevelop<\/li>\n<\/ol>\n<p>Here&#8217;s what my .editorconfig file looks like:<\/p>\n<pre><code>\r\n# EditorConfig is awesome: https:\/\/EditorConfig.org\r\n\r\n# for the top-most EditorConfig file, set...\r\n# root = true\r\n\r\n# In general, tabs shown 2 spaces wide\r\n[*]\r\nindent_style = tab\r\nindent_size = 2\r\n\r\n# Matches multiple files with brace expansion notation\r\n[*.{js,html}]\r\nindent_style = space\r\nindent_size = 2\r\n<\/code><\/pre>\n<p>This does the job nicely and has the following advantages:<\/p>\n<ul>\n<li>It doesn&#8217;t affect my other projects, so I don&#8217;t have to run around in the configuration to switch when task-switching. (Editorconfigs cascade, so will be looked up up in the filesystem tree for fallback styles.<\/li>\n<li>It works across different editors supporting the editorconfig standards, so not just KWrite, Kate, KDevelop, but also for <a href=\"https:\/\/editorconfig.org\/\">entirely different products<\/a>.<\/li>\n<li>It allows me to spend less time on formalities and more time on actual coding (or diving).<\/li>\n<\/ul>\n<p>(Thanks to <a href=\"https:\/\/www.reddit.com\/r\/kde\/comments\/9zjmh8\/kate_how_to_make_it_indent_py_with_spaces_and\/\" rel=\"noopener\" target=\"_blank\">Reddit<\/a>.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my hacking, I love to use the KDevelop IDE. Once in a while, I find myself working on a project that has different indentation styles depending on the filetype &#8212; in this case, C++ files, Makefiles, etc. use tabs, JavaScript and HTML files use 2 spaces. I haven&#8217;t found this to be straight-forward from&hellip; <a class=\"more-link\" href=\"https:\/\/vizZzion.org\/blog\/2018\/11\/different-indentation-styles-per-filetype\/\">Continue reading <span class=\"screen-reader-text\">Different indentation styles per filetype<\/span> <span class=\"meta-nav\" aria-hidden=\"true\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,29,25],"tags":[],"class_list":["post-3355","post","type-post","status-publish","format-standard","hentry","category-english","category-kde","category-linux"],"_links":{"self":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/3355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/comments?post=3355"}],"version-history":[{"count":9,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/3355\/revisions"}],"predecessor-version":[{"id":3364,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/3355\/revisions\/3364"}],"wp:attachment":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/media?parent=3355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/categories?post=3355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/tags?post=3355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}