New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework #984 #985

Merged
merged 4 commits into from Jan 26, 2018

Conversation

Projects
None yet
3 participants
@justbur
Collaborator

justbur commented Nov 28, 2017

@wasamasa Here's a different version of #984. Changes are

  1. I removed the customization variable. I think this is sufficiently correct functionality to make it the default even if it does modify someone's config slightly.

  2. I now teach evil-initial-state to look at aliases for modes. This makes a little more sense to me and simplifies the code.

  3. I detect the circular references and print a message as requested.
    Teach evil-initial-state to look at aliases for a mode when they exist and to
    handle nil for modes

Note that I still need to add tests for this.

Show outdated Hide outdated evil-core.el
@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Nov 28, 2017

Member

Interestingly enough, this doesn't appear to handle circular references. Here's some sample code:

(define-derived-mode foo-mode prog-mode "Foo")
(define-derived-mode bar-mode foo-mode "Bar")
(put 'foo-mode 'derived-mode-parent 'bar-mode)
(foo-mode)

If I evaluate this in an Emacs using this branch's code, it displays the message and hangs. Make sure to run it in a separate instance.

Member

wasamasa commented Nov 28, 2017

Interestingly enough, this doesn't appear to handle circular references. Here's some sample code:

(define-derived-mode foo-mode prog-mode "Foo")
(define-derived-mode bar-mode foo-mode "Bar")
(put 'foo-mode 'derived-mode-parent 'bar-mode)
(foo-mode)

If I evaluate this in an Emacs using this branch's code, it displays the message and hangs. Make sure to run it in a separate instance.

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Nov 29, 2017

Collaborator

Circular references cause bigger problems in Emacs it turns out. derived-mode-p easily gets caught in an infinite loop for example.

Collaborator

justbur commented Nov 29, 2017

Circular references cause bigger problems in Emacs it turns out. derived-mode-p easily gets caught in an infinite loop for example.

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Nov 29, 2017

Member

You see, this is why I originally suggested to throw an error to abort execution completely.

Member

wasamasa commented Nov 29, 2017

You see, this is why I originally suggested to throw an error to abort execution completely.

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Nov 29, 2017

Collaborator

I still don't like throwing an error. Take your example and enable global-paren-face-mode. If evil throws an error in the middle of initialization it leaves evil in a weird state (not fully initialized). Emacs still hangs due to a line like this in paren-face.

So the result is evil is not initialized (when it could be) and Emacs hangs anyway. If you have debug-on-error set then you might get a better indication of what's going on I guess.

Collaborator

justbur commented Nov 29, 2017

I still don't like throwing an error. Take your example and enable global-paren-face-mode. If evil throws an error in the middle of initialization it leaves evil in a weird state (not fully initialized). Emacs still hangs due to a line like this in paren-face.

So the result is evil is not initialized (when it could be) and Emacs hangs anyway. If you have debug-on-error set then you might get a better indication of what's going on I guess.

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Nov 29, 2017

Member

I'm sorry, but I don't quite understand how this example supports your argument. The shown code calls derived-mode-p which will hang if there's a cyclical reference anywhere. How is this related to Evil? More importantly, how is a setting that affects the initial state of buffers relevant to load-up which only touches elisp files? It's not like your standard elisp file does nothing else than triggering as many different major modes as possible until it hits one triggering that corner case. I expect the error to happen as you're editing, open a file with a less well written major mode and run into it. Erroring out there makes more sense to me than making Emacs unusable.

Member

wasamasa commented Nov 29, 2017

I'm sorry, but I don't quite understand how this example supports your argument. The shown code calls derived-mode-p which will hang if there's a cyclical reference anywhere. How is this related to Evil? More importantly, how is a setting that affects the initial state of buffers relevant to load-up which only touches elisp files? It's not like your standard elisp file does nothing else than triggering as many different major modes as possible until it hits one triggering that corner case. I expect the error to happen as you're editing, open a file with a less well written major mode and run into it. Erroring out there makes more sense to me than making Emacs unusable.

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Nov 30, 2017

Collaborator

@wasamasa I'll defer to you, but let me explain my reasoning. I have at least two minor modes (not including evil) which hang with circular references, so here is my experience

If we throw an error here:

  1. Evil's initialization errors out.
  2. Emacs hangs initializing another minor mode
  3. If I quit I'm left with a buffer in which evil is uninitialized or maybe partially initialized, but doesn't work.

If we issue a message here:

  1. Evil's initialization goes through fine with the default state being chosen for the buffer.
  2. Emacs hangs initializing another minor mode
  3. If I quit I'm left with a buffer in which evil is in a good state.

In either case, the message about the circular reference is there, but in the latter case I have a more functional editor (at least from the experience of an evil user).

Collaborator

justbur commented Nov 30, 2017

@wasamasa I'll defer to you, but let me explain my reasoning. I have at least two minor modes (not including evil) which hang with circular references, so here is my experience

If we throw an error here:

  1. Evil's initialization errors out.
  2. Emacs hangs initializing another minor mode
  3. If I quit I'm left with a buffer in which evil is uninitialized or maybe partially initialized, but doesn't work.

If we issue a message here:

  1. Evil's initialization goes through fine with the default state being chosen for the buffer.
  2. Emacs hangs initializing another minor mode
  3. If I quit I'm left with a buffer in which evil is in a good state.

In either case, the message about the circular reference is there, but in the latter case I have a more functional editor (at least from the experience of an evil user).

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 4, 2018

Collaborator

@wasamasa I updated this to throw an error for the circular reference thing.

Collaborator

justbur commented Jan 4, 2018

@wasamasa I updated this to throw an error for the circular reference thing.

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Jan 4, 2018

Member

Thanks, this leaves some tests which can be probably adapted from #904.

Member

wasamasa commented Jan 4, 2018

Thanks, this leaves some tests which can be probably adapted from #904.

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 4, 2018

Collaborator

@wasamasa added some tests

Collaborator

justbur commented Jan 4, 2018

@wasamasa added some tests

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Jan 6, 2018

Member

I've found a case that doesn't work correctly, if I've configured Evil to only use prog-mode and text-mode for normal state and make Emacs state the default, this doesn't give me normal state when opening a json-mode buffer. It seems as if the alias detection doesn't work correctly yet. json-mode derives from javascript-mode which is an alias for js-mode, so I'd expect this PR's code to detect that and check js-mode and its parents until encountering prog-mode to reach normal state.

Here's my config:

(setq evil-default-state 'emacs
      evil-emacs-state-modes nil
      evil-insert-state-modes nil
      evil-motion-state-modes nil
      evil-normal-state-modes '(text-mode prog-mode fundamental-mode
                                          css-mode conf-mode
                                          TeX-mode LaTeX-mode
                                          diff-mode))
Member

wasamasa commented Jan 6, 2018

I've found a case that doesn't work correctly, if I've configured Evil to only use prog-mode and text-mode for normal state and make Emacs state the default, this doesn't give me normal state when opening a json-mode buffer. It seems as if the alias detection doesn't work correctly yet. json-mode derives from javascript-mode which is an alias for js-mode, so I'd expect this PR's code to detect that and check js-mode and its parents until encountering prog-mode to reach normal state.

Here's my config:

(setq evil-default-state 'emacs
      evil-emacs-state-modes nil
      evil-insert-state-modes nil
      evil-motion-state-modes nil
      evil-normal-state-modes '(text-mode prog-mode fundamental-mode
                                          css-mode conf-mode
                                          TeX-mode LaTeX-mode
                                          diff-mode))
@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 7, 2018

Collaborator

Yep, I wasn't checking parents of the aliases, which is what your example shows. I changed the logic to do this now.

Collaborator

justbur commented Jan 7, 2018

Yep, I wasn't checking parents of the aliases, which is what your example shows. I changed the logic to do this now.

Show outdated Hide outdated evil-core.el
@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 8, 2018

Collaborator

@wasamasa seems like the travis segfaults are back.

Collaborator

justbur commented Jan 8, 2018

@wasamasa seems like the travis segfaults are back.

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Jan 9, 2018

Member

Damnit. Code looks fine now, but I'll have to do some more testing before this is good to go.

Member

wasamasa commented Jan 9, 2018

Damnit. Code looks fine now, but I'll have to do some more testing before this is good to go.

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 9, 2018

Collaborator

I just rebased and the seg fault went away, so a good sign at least...

Collaborator

justbur commented Jan 9, 2018

I just rebased and the seg fault went away, so a good sign at least...

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Jan 9, 2018

Member

That's no proof considering it went undetected for like dozens of test runs.

Member

wasamasa commented Jan 9, 2018

That's no proof considering it went undetected for like dozens of test runs.

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Jan 24, 2018

Member

Alright, I think this can be merged, that is, once you've fixed this (hopefully trivial) merge conflict. I'd fix it myself if this were a branch on here...

edit: https://travis-ci.org/emacs-evil/evil/builds/333000270

Member

wasamasa commented Jan 24, 2018

Alright, I think this can be merged, that is, once you've fixed this (hopefully trivial) merge conflict. I'd fix it myself if this were a branch on here...

edit: https://travis-ci.org/emacs-evil/evil/builds/333000270

justbur added some commits Nov 27, 2017

Use initial states of parent major modes
Teach evil-initial-state to look at aliases for a mode when they exist and to
handle nil for modes

Search parent modes (and their aliases) for defined initial states in
evil-initial-state-for-buffer.

One effect is that

(evil-set-initial-state 'special-mode 'motion)

now makes motion state the default for all major modes that derive from special
mode and don't have defaults set for them.
Teach evil-initial-state about parent modes
Previously this was done in evil-initial-state-for-buffer, but it's easier to
recursively follow all parent branches (including those from aliases) within
evil-initial-state.
@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 25, 2018

Collaborator

@wasamasa done. I squashed two of the commits, too.

Collaborator

justbur commented Jan 25, 2018

@wasamasa done. I squashed two of the commits, too.

@wasamasa wasamasa merged commit 2992858 into emacs-evil:master Jan 26, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Jan 26, 2018

Member

Thanks!

Member

wasamasa commented Jan 26, 2018

Thanks!

@marktran

This comment has been minimized.

Show comment
Hide comment
@marktran

marktran Jan 28, 2018

This PR disables evil in org-mode for me. How do get it working with org-mode again?

cc @justbur @wasamasa

marktran commented Jan 28, 2018

This PR disables evil in org-mode for me. How do get it working with org-mode again?

cc @justbur @wasamasa

@wasamasa

This comment has been minimized.

Show comment
Hide comment
@wasamasa

wasamasa Jan 28, 2018

Member

@marktran First of all, the worst it could do is enabling Emacs state (as denoted by <E> in the mode line) which is not the same as disabling Evil. Second, I cannot reproduce that withing a make emacs session. It's therefore most probably something in your init file. Please open a more specific bug report once you have a minimal repro.

Member

wasamasa commented Jan 28, 2018

@marktran First of all, the worst it could do is enabling Emacs state (as denoted by <E> in the mode line) which is not the same as disabling Evil. Second, I cannot reproduce that withing a make emacs session. It's therefore most probably something in your init file. Please open a more specific bug report once you have a minimal repro.

@marktran

This comment has been minimized.

Show comment
Hide comment
@marktran

marktran Jan 28, 2018

Yes, please excuse my terminology.

I see that this PR makes org-mode derive its initial state from text-mode and my config had the following:

(loop for (mode . state) in '((inferior-emacs-lisp-mode . emacs)
                              (comint-mode              . emacs)
                              (eshell-mode              . emacs)
                              (occur-mode               . emacs)
                              (paradox-menu-mode        . emacs)
                              (special-mode             . emacs)
                              (sql-interactive-mode     . emacs)
                              (text-mode                . emacs))
      do (evil-set-initial-state mode state))

All fixed now. Thanks.

marktran commented Jan 28, 2018

Yes, please excuse my terminology.

I see that this PR makes org-mode derive its initial state from text-mode and my config had the following:

(loop for (mode . state) in '((inferior-emacs-lisp-mode . emacs)
                              (comint-mode              . emacs)
                              (eshell-mode              . emacs)
                              (occur-mode               . emacs)
                              (paradox-menu-mode        . emacs)
                              (special-mode             . emacs)
                              (sql-interactive-mode     . emacs)
                              (text-mode                . emacs))
      do (evil-set-initial-state mode state))

All fixed now. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment