DarthFennec / highlight-indent-guides

Emacs minor mode to highlight indentation
573 stars 27 forks source link

Enhancement request: Allow skipping preprocessor lines. #104

Open kbauer opened 3 years ago

kbauer commented 3 years ago

In some languages, preprocessor directives are used, most commonly C-style. These directives always start at the beginning of the line. This can lead to code like:

int doSomething() {
  if(1) {
    if(2) {
      if(3) {
        hello();
        world();
#ifdef DEBUG
        printInfo(1);
        printInfo(2);
#endif
        hello();
        world();
      }
    }
  }
}

Expectation

Consistent guides across the directives.

image (Mockup)

Result

The preprocessor lines confuse the guide creation, since they interrupt the indentation.

image

Possible solutions?

It likely is a problem without a good general solution; Interruptions of a strict "logical level = indent level" pattern may occur differently from code base to code base, even within the same language.

The best bet would likely be to allow configuring a regexp for lines to be ignored, which could then be customized per-mode, per-file or per-directory through mode-hooks, directory-local variables and file-local variables.

DarthFennec commented 3 years ago

I agree, there will need to be some kind of customizable regex or function for this. I'll look into it when I have time, thanks!