alphapapa / outshine

Org-mode for non-Org buffers
GNU General Public License v2.0
211 stars 23 forks source link

allow preceding whitespace #14

Open JohnLunzer opened 6 years ago

JohnLunzer commented 6 years ago

Is there any way to allow preceding whitespace before headlines?

I'm having some issues getting my outlines working properly in Python because in Python there is a lot of indentation.

Any advice?

alphapapa commented 6 years ago

IIRC this is a matter of outline-minor-mode and the associated regexp-containing variables that match commented outline headings. You can experiment with them in your config, try adding optional whitespace matchers, etc. Of course, you'll have to avoid matching newlines. ISTR that it gets pretty messy. Anyway, AFAIK it's not related to Outshine itself.

kepi commented 5 years ago

I tried to play around it for some time but without any success. I'm not sure if I want same thing as @JohnLunzer but I think so :)

If you see screenshot bellow, what I want is TAB do outline-cycle on both headings, Layers and Enter layers bellow one. It is working as supposed on Layers as it is starting at the beginning of line, but only runs indent-relative when not.

outshine_heading_space

I belive that this behaviour is intentional as documented in outline-cycle. But it would be great if it would work when I have cursor placed after comments or maybe just cycle outline after indent-relative is called (would be probably best).

You can see in screenshot, that faces are working and it is displayed as it should, but cycle is not working.

If this is related to regexp, can you help me with pointing out which one? I was trying to play with outline-regexp but its buffer local variable and different for every mode.

alphapapa commented 5 years ago

If this is related to regexp, can you help me with pointing out which one? I was trying to play with outline-regexp but its buffer local variable and different for every mode.

It's complicated. IIRC there are two regexps, one for matching outline headings and one for determining heading levels. You'll have to dig into the outline-mode code. Anyway, AFAIK it's not related to Outshine.

It might be better to look into alternative outline packages, like Origami.

johnbcoughlin commented 5 years ago

Based on my reading of the code, it seems that outshine is building the outline-regexp and outline-level string and function for each major mode:

;;;;; Calculate outline-regexp and outline-level

It then chomps off the leading whitespace from the computed regexp:

(defun outshine-normalize-regexps ()
  "Chomp leading and trailing whitespace from outline regexps."
  (and comment-start
       (setq outshine-normalized-comment-start
             (if outshine-preserve-delimiter-whitespace
                 comment-start
               (outshine-chomp comment-start))))
  (and comment-end
       (setq outshine-normalized-comment-end
             (outshine-chomp comment-end)))
  (and outshine-regexp-base
       (setq outshine-normalized-outline-regexp-base
             (outshine-chomp outshine-regexp-base))))

So it seems like this is within outshine. It would be great if it were possible to use preceding whitespace, because in a language like Rust, the rustfmt utility will indent comments to the current indentation level, which makes them invalid as outline headings.

henrymazza commented 4 years ago

Looks like a outline-mode problem. Outshine recognizes indented headings, it even highlights it. But outline-hide-subtree that don't behaves well.

I tried to change outline-regexp but not luck at all. But i'm no expert...

alphapapa commented 4 years ago

Based on my reading of the code, it seems that outshine is building the outline-regexp and outline-level string and function for each major mode:

It then chomps off the leading whitespace from the computed regexp:

So it seems like this is within outshine. It would be great if it were possible to use preceding whitespace, because in a language like Rust, the rustfmt utility will indent comments to the current indentation level, which makes them invalid as outline headings.

[...one year later...]

Thanks. The interaction and overlap between outshine-mode and outline-minor-mode is a source of confusion. Ideally Outshine should reuse as much functionality that's built-in to Emacs as possible.

For that reason, I'd still recommend trying to fix this in outline-minor-mode. If it's not possible to use regexps with leading whitespace with outline-minor-mode, I'd suggest raising that on the emacs-devel mailing list, or just filing an Emacs bug report.

Then we should try to make Outshine reuse that functionality rather than redefining its own regexps.