tmalsburg / guess-language.el

Emacs minor mode that detects the language you're typing in. Automatically switches spell checker. Supports multiple languages per document.
119 stars 14 forks source link

org-mode - "Wrong type argument: number-or-marker-p, nil" #20

Closed francesquini closed 5 years ago

francesquini commented 5 years ago

Hi there,

I've been experiencing some problems using guess-language and org-mode.

M-x guess-language in an org-file anywhere on the second line of the example below causes the error:

Wrong type argument: number-or-marker-p, nil.

  - First item. I'm just writing something longer so that the minimum
    number of characters is reached.

This problem also shows up (not always) when fly-spelling the whole buffer (M-x flyspell-buffer) stopping the verification before it reaches the end of the file.

My guess this error can be somewhat related to the (last part) of issue https://github.com/tmalsburg/guess-language.el/issues/17#issuecomment-294580409 and also commit 65dccb1 which deals with paragraph navigation in org-mode files.

Using: Emacs 26.1 Org mode 9.1.14 guess-language head from git repository.

Debugger output:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  org-list-struct()
  guess-language-forward-paragraph()
  guess-language()
  funcall-interactively(guess-language)
  call-interactively(guess-language record nil)
  command-execute(guess-language record)
  helm-M-x(nil "guess-language")
  funcall-interactively(helm-M-x nil "guess-language")
  call-interactively(helm-M-x nil nil)
  command-execute(helm-M-x)

Please let me know if you need further info to pinpoint the error.

tmalsburg commented 5 years ago

I can replicate this. The issue is that org-list-struct fails when invoked on the second line. This means that we're likely dealing with a bug in org-mode. The following numerical comparison fails in org-list-struct because itm-lst-s is nil:

          (when (<= ind (nth 1 (car itm-lst-2)))
        (push (cons ind (point)) end-lst-2))

Could you report this problem to the org-mode devs?

francesquini commented 5 years ago

Sure thing. Already done.

Not sure when org developers will take a look at it though.

Any suggestions on how to workaround this in the meanwhile? For the time being I've disabled guess-language on org buffers. Far from ideal, but better than nothing.

tmalsburg commented 5 years ago

In my setup, I only get an error when I call guess-language (or org-list-struct) explicitly. When I just write, and let guess-language do it's thing on the fly, I don't see any error messages. Is this different in your setup?

Thanks for reporting the org bug. I hope we get a constructive response.

francesquini commented 5 years ago

Hi Titus,

Thanks for the quick reply.

In my case the problem happens when I am using flyspell-mode (or M-x flyspell-buffer). Although not always (and I don't really know why). When fly-spelling the whole buffer the error ends up stopping the verification before it reaches the end of the file.

Is there any kind of test I could do to give you more info regarding this?

Thanks!

On Thu, Nov 15, 2018 at 7:04 AM Titus von der Malsburg < notifications@github.com> wrote:

In my setup, I only get an error when I call guess-language (or org-list-struct) explicitly. When I just write, and let guess-language do it's thing on the fly, I don't see any error messages. Is this different in your setup?

Thanks for reporting the org bug. I hope we get a constructive response.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tmalsburg/guess-language.el/issues/20#issuecomment-438967785, or mute the thread https://github.com/notifications/unsubscribe-auth/AAslLjQbo5pkZqYywyWwoVfZPX8nMZvsks5uvS4KgaJpZM4YXnbc .

tmalsburg commented 5 years ago

Sorry, I should have mentioned that I'm using flyspell-mode as well. A minimal reproducible example would be great as a starting point.

francesquini commented 5 years ago

Actually, the example I posted in the previous comment sometimes causes the error.

Apparently replicating the same snippet over and over again increases the probability of failure.

Nicolas Goaziou in response of the bug report I filed for org-mode said:

This is not a bug. The function org-list-struct has to be called on an item, not anywhere within an item. BTW, it is an internal function. You may want to use `org-element-at-point' instead.

Would that function work in this case?

tmalsburg commented 5 years ago

Thanks for contacting the org developers.

The function org-list-struct has to be called on an item, not anywhere within an item.

Do you know what this is supposed to mean? Isn't anywhere within an item also on the item? If not, what's the meaning of "on the item"?

Anyway, I tried org-element-at-point but discovered that org has (now?) functions for jumping to the beginning and end of a list (org-beginning-of-item-list and org-end-of-item-list) which make everything much easier. See commit bc6fe11d7ea36d5319ac05c00d52b50d42d64cea. Could you please check whether it works as expected? Thank you.

francesquini commented 5 years ago

Thanks for the fix!

That reported error seems to have been fixed. However, a new one (not limited to org-mode as it also manifests itself in fundamental-mode) seems to be happening. (Maybe I should open a new issue?)

Steps to reproduce:

The following lines must be in a language different from the language of the first line to cause the bug.
The number of lines below seems to be the minimum necessary to make the bug manifest itself in my system.

Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.
Uma linha longa o suficiente para que o problema se manifeste.

I get the following error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  flyspell-external-point-words()
  flyspell-large-region(1 1010)
  flyspell-region(1 1010)
  flyspell-buffer()
  funcall-interactively(flyspell-buffer)
  call-interactively(flyspell-buffer record nil)
  command-execute(flyspell-buffer record)
  helm-M-x(nil "flyspell-buffer")
  funcall-interactively(helm-M-x nil "flyspell-buffer")
  call-interactively(helm-M-x nil nil)
  command-execute(helm-M-x)

This does not happen with guess-language-mode disabled.

Any hints?

My guess-language configuration:

(require 'guess-language)
(setq guess-language-languages '(en fr pt))
(setq guess-language-min-paragraph-length 35)
(setq guess-language-langcodes
        '((en . ("en_US" "English"))
          (fr . ("fr_FR" "French"))
          (pt . ("pt_BR" "Portuguese"))
          ))
(add-hook 'flyspell-mode-hook (lambda () (guess-language-mode 1)))
francesquini commented 5 years ago

Do you know what this is supposed to mean? Isn't anywhere within an item also on the item? If not, what's the meaning of "on the item"?

As far as I understand, an item is limited to a single line. Anything below a heading (marked by - or *) is "inside" an item.

tmalsburg commented 5 years ago

I can't reproduce this problem. Could you please test with a minimal setup (emacs -q) and create a new issue? Thank you.

francesquini commented 5 years ago

Done! Opened issue #21

tmalsburg commented 5 years ago

Thank you! Will try to replicate tomorrow.