{"action":"created","issue":{"url":"https://api.github.com/repos/bengardner/uncrustify/issues/132","labels_url":"https://api.github.com/repos/bengardner/uncrustify/issues/132/labels{/name}","comments_url":"https://api.github.com/repos/bengardner/uncrustify/issues/132/comments","events_url":"https://api.github.com/repos/bengardner/uncrustify/issues/132/events","html_url":"https://github.com/bengardner/uncrustify/issues/132","id":9914659,"number":132,"title":"Options to control whitespace stripping","user":{"login":"ryanmaxwell","id":718440,"avatar_url":"https://avatars.githubusercontent.com/u/718440?v=3","gravatar_id":"","url":"https://api.github.com/users/ryanmaxwell","html_url":"https://github.com/ryanmaxwell","followers_url":"https://api.github.com/users/ryanmaxwell/followers","following_url":"https://api.github.com/users/ryanmaxwell/following{/other_user}","gists_url":"https://api.github.com/users/ryanmaxwell/gists{/gist_id}","starred_url":"https://api.github.com/users/ryanmaxwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryanmaxwell/subscriptions","organizations_url":"https://api.github.com/users/ryanmaxwell/orgs","repos_url":"https://api.github.com/users/ryanmaxwell/repos","events_url":"https://api.github.com/users/ryanmaxwell/events{/privacy}","received_events_url":"https://api.github.com/users/ryanmaxwell/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2013-01-12T20:35:50Z","updated_at":"2015-06-05T22:11:40Z","closed_at":"2013-01-15T10:46:38Z","body":"Hi Ben, i'm trying to configure the whitespace stripping settings. Uncrustify has default behaviour to strip trailing whitespace on any line, with no option as far as I can tell to disable this. \r\n\r\nWhat I was looking for was something akin to the current settings in Xcode - control over trimming trailing whitespace on a line, as well as whether to apply this to blank lines.\r\n\r\nGenerally the blank lines have whitespace to indent to the code-level. An option to set this would be appreciated too (unless there already is one!). Thanks."},"comment":{"url":"https://api.github.com/repos/bengardner/uncrustify/issues/comments/109456690","html_url":"https://github.com/bengardner/uncrustify/issues/132#issuecomment-109456690","issue_url":"https://api.github.com/repos/bengardner/uncrustify/issues/132","id":109456690,"user":{"login":"kankaristo","id":3522333,"avatar_url":"https://avatars.githubusercontent.com/u/3522333?v=3","gravatar_id":"","url":"https://api.github.com/users/kankaristo","html_url":"https://github.com/kankaristo","followers_url":"https://api.github.com/users/kankaristo/followers","following_url":"https://api.github.com/users/kankaristo/following{/other_user}","gists_url":"https://api.github.com/users/kankaristo/gists{/gist_id}","starred_url":"https://api.github.com/users/kankaristo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kankaristo/subscriptions","organizations_url":"https://api.github.com/users/kankaristo/orgs","repos_url":"https://api.github.com/users/kankaristo/repos","events_url":"https://api.github.com/users/kankaristo/events{/privacy}","received_events_url":"https://api.github.com/users/kankaristo/received_events","type":"User","site_admin":false},"created_at":"2015-06-05T22:11:40Z","updated_at":"2015-06-05T22:11:40Z","body":"This is quite simple to do actually. For all empty lines, take the indentation of the next line (iterate over lines backwards).\r\n\r\nI wrote a small script, which pretends to be Uncrustify (`uncrustify.sh`):\r\n```bash\r\n#!/bin/bash\r\n\r\n# Directory containing this script\r\nDIR=$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\r\n\r\n# Run Uncrustify\r\nuncrustify \"$@\" > /tmp/uncrustify_output\r\n\r\n# Re-indent empty lines\r\nlua $DIR/reindent_file.lua /tmp/uncrustify_output\r\n```\r\n\r\nAnd a Lua script, which \"re-indents\" the file (`reindent_file.lua`):\r\n```lua\r\n--\r\n-- Indent empty lines in a file.\r\n--\r\n\r\n-- File name\r\nlocal fileName = arg[1] or error(\"No file name given.\", 2)\r\n\r\n-- Open the file\r\nlocal file = assert(io.open(fileName, \"r\"))\r\n\r\n-- Read the file into a table\r\nlocal lines = {}\r\nfor line in file:lines() do\r\n    lines[#lines + 1] = line\r\nend\r\n\r\n-- Close the file\r\nfile:close()\r\n\r\n-- Loop over the lines from end to beginning\r\nfor i = #lines - 1, 1, -1 do\r\n    -- Check that the current line is empty\r\n    if lines[i]:find(\"^%s*$\") then\r\n        -- Write the indent on the next line to the current line\r\n        lines[i] = lines[i + 1]:match(\"^(%s*)\")\r\n    end\r\nend\r\n\r\n-- Output the result\r\nio.write(table.concat(lines, \"\\n\"))\r\nio.flush()\r\n```\r\n\r\nI wrote this in Lua, but the basic idea is really simple and could easily be done in any language.\r\n\r\nUncrustify could do this after all other formatting, if an option is specified.\r\n\r\n@bengardner, could something like this be added to Uncrustify? It's obviously a sought after feature."}}