emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Strangely recognized non-lists and non-headers.
@ 2020-02-02 10:11 D
  2020-02-02 11:59 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: D @ 2020-02-02 10:11 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

while debugging org-superstar-mode I noticed something very strange, and
I am not sure if it's a bug in org or a bug in my understanding of org.

First off, an MWE for Org mode version 9.1.9 (release_9.1.9-65-g5e4542):

#+BEGIN_SRC C
/*
* This is a header?
  + this
    + is
      * a list?
*/
#+END_SRC

This works. I can promote, demote, fold, etc.  org-superstar also has no
issue with accepting these.  I should add, this is the default config
(emacs -Q on Emacs 26.3).  So no spooky stuff I believe on that end.
So I began digging.

I use org-list-in-valid-context-p as a quick hack to check if what I am
looking at is actually a list.  Said predicate is a simple wrapper
around the function org-in-block-p being called with
org-list-forbidden-blocks.  It is the the list of environments where
lists are not allowed.

Value: ("example" "verse" "src" "export")

There is also a very similar variable: org-protecting-blocks.  This one
marks environments as quoted, disallowing org syntax.

Value: ("src" "example" "export")

Currently these two variables don't know of one another.  Maybe the
latter should be a strict subset of the former?

Anyway, from what I have found org-in-block-p seems to not recognize src
blocks reliably.  I wrote a small function to test this:

(defun nag ()
  (interactive)
  (when (org-list-in-valid-context-p)
    (warn "You can make a list here! :(")))

And it seems, yes, you can make a list in a src block.
That's all very peculiar, what do you guys think?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Strangely recognized non-lists and non-headers.
  2020-02-02 10:11 Strangely recognized non-lists and non-headers D
@ 2020-02-02 11:59 ` Nicolas Goaziou
  2020-02-02 13:33   ` D
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2020-02-02 11:59 UTC (permalink / raw)
  To: D; +Cc: emacs-orgmode

Hello,

D <d.williams@posteo.net> writes:

> I use org-list-in-valid-context-p as a quick hack to check if what I am
> looking at is actually a list.  

Long story short. Don't use this function, it is not correctly
implemented at the moment. The correct way to check if you're in a list
is something like:

  (org-element-lineage (org-element-at-point) '(plain-list) t)


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Strangely recognized non-lists and non-headers.
  2020-02-02 11:59 ` Nicolas Goaziou
@ 2020-02-02 13:33   ` D
  2020-02-02 14:13     ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: D @ 2020-02-02 13:33 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Hi,

On 02.02.20 12:59, Nicolas Goaziou wrote:
> Long story short. Don't use this function, it is not correctly
> implemented at the moment. The correct way to check if you're in a list
> is something like:
> 
>   (org-element-lineage (org-element-at-point) '(plain-list) t)

I tried that out, but it still seems to recognize source code as
headlines, replacing the predicate does not change the behavior.  It
seems to be something more deeply rooted than that, I mean, otherwise
org mode wouldn't try to collapse those fake-headlines when hitting TAB,
either.

Regards,

D.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Strangely recognized non-lists and non-headers.
  2020-02-02 13:33   ` D
@ 2020-02-02 14:13     ` Nicolas Goaziou
  2020-02-02 15:26       ` D
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2020-02-02 14:13 UTC (permalink / raw)
  To: D; +Cc: emacs-orgmode

D <d.williams@posteo.net> writes:

> On 02.02.20 12:59, Nicolas Goaziou wrote:
>> Long story short. Don't use this function, it is not correctly
>> implemented at the moment. The correct way to check if you're in a list
>> is something like:
>> 
>>   (org-element-lineage (org-element-at-point) '(plain-list) t)
>
> I tried that out, but it still seems to recognize source code as
> headlines, replacing the predicate does not change the behavior.

Of course. You cannot have headlines within a source block. You need to
escape them with commas. I'm just pointing out that the code above is
the right way to check if you're in a list.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Strangely recognized non-lists and non-headers.
  2020-02-02 14:13     ` Nicolas Goaziou
@ 2020-02-02 15:26       ` D
  0 siblings, 0 replies; 5+ messages in thread
From: D @ 2020-02-02 15:26 UTC (permalink / raw)
  To: Nicolas Goaziou, emacs-orgmode

> You need to escape them with commas.

Ah, I overlooked that because I did not check the manual whether leading
stars are escaped automatically and just assumed it, sorry.  Thanks a lot!

Though, there is one minor thing I noticed:

Leading stars are valid comment symbols in Fortran, as long as they are
the first character in the line.  They are recognized in SRC fortran
blocks when the star is unescaped, but not when the star is escaped, meaning
#+BEGIN_SRC fortran
,*******************************
,* a valid comment
,******************************
#+END_SRC
 is displayed with the org-block face instead of the usual
font-lock-comment-face.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-02 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-02 10:11 Strangely recognized non-lists and non-headers D
2020-02-02 11:59 ` Nicolas Goaziou
2020-02-02 13:33   ` D
2020-02-02 14:13     ` Nicolas Goaziou
2020-02-02 15:26       ` D

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).