3

I've been trying to use GNU indent to indent some very simple C files, and I wish to use the K&R indentation style but without any use of spaces, purely tabs.

I've tried indent -kr --use-tabs, and just indent -kr but they both just use the default K&R with spaces or mix indentation with spaces and tabs.

Is there a way to use K&R with GNU indent while strictly using tabs only? If not, is there a better utility for indentation in this style?

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • 1
    You don't have to use a text editor for long to realise that tabs make it difficult to manoeuvre the caret around the text. It jumps unexpectedly. Ditto with deleting text, always having to recover when you deleted too much. Simple answer: don't use tabs. – Weather Vane Jun 11 '16 at 22:16
  • 3
    Are you kidding me? Your comment was simply to bring up an age old argument? If you don't have an answer, then don't bother. – breakonthrough Jun 11 '16 at 22:19
  • 1
    @Clifford Exactly, I set my editor to interpret tab width as 4, and if I released something to the public, I would like if they could interpret it the way they wish as well. But unless you're planning to launch a holy crusade to eliminate one of either tabs or spaces once and for all, this is pointless to argue. – breakonthrough Jun 11 '16 at 22:43
  • @breakonthrough it was just a comment with neither DV nor request to close. I thought it a question which goes into arguably unwise territory, which you now say you are aware of. – Weather Vane Jun 11 '16 at 22:54
  • 1
    @breakonthrough : I was suggesting choose one or the other for your own house-style, not *globally*! The point was that GNU indent managed to mix them in a single file which is a disaster when rendered by a tool with a different hard-tab width - lines with spaces+tabs will indent differently than those without. The same can happen in development teams with different editor settings. – Clifford Jun 12 '16 at 06:35

1 Answers1

7

The default assumed width of a tab in GNU indent is 8 (because historically that is what line-printers, teletypes and dumb terminals use). If your indent width is not then a multiple of 8, the tool will mix tabs and spaces to meet your indent width specification.

You need to set the tab width to match your indent with the --tab-size / -ts option, as described in the documentation.

Clifford
  • 88,407
  • 13
  • 85
  • 165