13

I work on some projects with indentation styles that I find really irritating. I'd like to view the code with a certain indentation style, but always save to disk with the prescribed indentation style.

Specifically, I like emacs default style of indentation on multi-line function arguments...

void foo(int a, int b,
         string c)

But the project is tab-only, single indent on everything...

void foo(int a, int b,
    string c)

Can I see the first case, but share the second?

  • What about: disable auto-revert mode, then run a command (e.g., astyle) which formats the file to your team's style in your after-save-hook – nanny Sep 17 '15 at 20:37
  • have you considered a version-control level formatting hook, e.g. git pre-commit hook? – erjoalgo Sep 13 '18 at 18:47
1

An obvious approach to this would be to

  • indent a copy of the buffer using c-mode; and then
  • put the copy's indent as display properties on the indentation space in the original buffer.

Note 1: Implementing this while keeping the ability to edit the buffer could be a nightmare, so I'd make the buffer read-only.
Note 2: Text properties are much faster than overlays, so I'd use them. Unless in the odd case where the original buffer's indent is 0 and c-mode's is not.

  • This can be done with text properties by adding extra font-locking keywords. I'm more concerned about figuring out how the indent should be displayed instead. – wasamasa Jun 19 '15 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.