alphapapa / outshine

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

Compatibility issue with python-mode #42

Open yuhan0 opened 5 years ago

yuhan0 commented 5 years ago

python-mode sets the variable outline-heading-end-regexp to be ":[^\n]*\n", affecting the behavior of (outline-end-of-heading) and making visibility cycling break in unexpected ways.

Possible solution: override outline-heading-end-regexp to default value of "\n" during minor mode activation, along with the other protected variables. Are there any scenarios now where the end of a headline is not at the EOL of same line?

thblt commented 5 years ago

Possible solution: override outline-heading-end-regexp to default value of "\n" during minor mode activation, along with the other protected variables.

sounds good.

Are there any scenarios now where the end of a headline is not at the EOL of same line?

I don't think so. I just discovered most programming major modes configure Outline to reflect the code blocks structure (defuns, etc). IIUC, Python-mode also wants to remove comments from the heading, for some reason. (Also the regexp is broken, because it assumes : can only appear as the very last token of a block start, but it's also the string slicing operator: for x in a[2..3]:)


Yet there's a more general issue I didn't know about: we're using Outline in unexpected ways on programming modes. This may be worth investigating.

alphapapa commented 5 years ago

I'm not sure, but I wonder if changing this would affect tools like imenu. We should be very careful here, I think. :)

thblt commented 5 years ago

Also godot-gdscript-mode, #60

prosoitos commented 5 years ago

I was about to open an issue, but maybe it is relevant with this:

I am unable to get outshine to behave normally in python-mode. imenu doesn't work and neither does the visibility cycling. The only thing that works for me in python-mode is the header highlighting. Outshine behaves normally in all other modes in which I use it (many modes).

Kodiologist commented 2 years ago

Outshine mode has been acting funny with Python mode for me since a recent upgrade, although I'm not sure which specific piece of software being upgraded made the difference. (I'm now running Emacs 27.1 and Outshine 20191112.1414.) The issue is that cycling an Outshine buffer treats not only starred comment lines as headlines, but also, apparently, some kinds of code. It sounds similar to the problem described in this issue, but things used to work for me, and I'm seeing the default outline-regexp as "# [*]\\{1,8\\} " and outline-heading-end-regexp as "\n".

Consider the following buffer in Python mode:

# * headline 1

x = 5
if 1:
    print('hello')

# * headline 2

y = 9
def p():
    return 3

When I run outshine-cycle-buffer, I get

# * headline 1

x = 5
if 1:...
# * headline 2

y = 9
def p():...

rather than the desired

# * headline 1...
# * headline 2...

I don't see this problem in the major modes of other programming languages.

DiogoFerrari commented 2 years ago

Any development on this?

DiogoFerrari commented 2 years ago

My temporary solution, based on @yuhan0 comment:

(add-hook 'python-mode-hook 'outshine-mode)
(add-hook 'python-mode-hook (lambda ()(setq outline-heading-end-regexp "\n")))