Exclude some styles (namely, code blocks) from autocorrect

Discuss the word processor
Post Reply
john1320
Posts: 70
Joined: Mon Jun 12, 2017 8:22 pm

Exclude some styles (namely, code blocks) from autocorrect

Post by john1320 »

Is there a way to exclude some styles from autocorrect?

Typical use case:

I use Writer for documents with code blocks. I like some autocorrect features, as "smart quotes", dashes instead of hyphens, and captial letters after dots. But, for obvious reasons, I want to avoid such replacements in code.

Thus, I use "Text Body" style for my main text and "Code Listings" style for my code blocks. And I want to achieve this desired result:
code.png
As you can see, replacements were applied for "Text Body" style, whereas "Code Listing" style preserved exactly as I typed, without any autocorrect changes.

Is there any way to achieve this?

Thanks, John.

Update

Well, it seems, there is no option for it.

https://bugs.documentfoundation.org/sho ... i?id=77568

Anyway, any ideas are welcome.
LibreOffice 5.2.7 on Windows 7
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Exclude some styles (namely, code blocks) from autocorre

Post by Hagar Delest »

Have you set the language to [None] in the font tab of the paragraph style "Code Listing"?
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
john1320
Posts: 70
Joined: Mon Jun 12, 2017 8:22 pm

Re: Exclude some styles (namely, code blocks) from autocorre

Post by john1320 »

Hagar Delest wrote:Have you set the language to [None] in the font tab of the paragraph style "Code Listing"?
Interesting. I changed language to [None], but it doesn't helped, because right after I typed something, the language was automatically detected as US English.

Then, I enabled "Ignore system input language" in Options. And now it's a bit fixed, but not completely. The quotes stay "dumb" (straight, not curly, good), but hyphens still changed to n-dashes, and first letter after the dot still changed to capital. So, at this moment of time, playing with languages fixed only the quotes.
LibreOffice 5.2.7 on Windows 7
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Exclude some styles (namely, code blocks) from autocorre

Post by acknak »

To my knowledge, there is no way for styles to interact with the autocorrect behavior.

Styles may disable spellcheck by setting the language to "none". This is often done for code styles, since there's no sense in checking the spelling there.

Quotes interact (indirectly) because the exact behavior of the quotes depends on the language being used; if the language is "none", it disables the automatic change from straight to curly quotes.
AOO4/LO5 • Linux • Fedora 23
john1320
Posts: 70
Joined: Mon Jun 12, 2017 8:22 pm

Re: Exclude some styles (namely, code blocks) from autocorre

Post by john1320 »

acknak wrote:Quotes interact (indirectly) because the exact behavior of the quotes depends on the language being used.
By the way, dashes also depends on languages. In some languages, it is common to use n-dashes, whereas in another languages the m-dashes are used. Writer, however, always inserts n-dashes if language is set-upped to [None]. So, Writer is a bit inconsistent between quotes and dashes. It should be more correct to use the same logic as for quotes - the hyphens should not be changed to anything.
LibreOffice 5.2.7 on Windows 7
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Exclude some styles (namely, code blocks) from autocorre

Post by Hagar Delest »

john1320 wrote:The quotes stay "dumb" (straight, not curly, good), but hyphens still changed to n-dashes, and first letter after the dot still changed to capital. So, at this moment of time, playing with languages fixed only the quotes.
I did some checks before posting and the dashes are not replaced if the language is set to [None].
john1320 wrote:Writer, however, always inserts n-dashes if language is set-upped to [None]. So, Writer is a bit inconsistent between quotes and dashes.
Agreed. Both should have the same behavior, I also discovered that with by investigating your problem. It is the same with the ordinal numbers (1st, ...), it changes it whatever the language.
But all that should be language sensitive IMHO (like the dashes).
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
john1320
Posts: 70
Joined: Mon Jun 12, 2017 8:22 pm

Re: Exclude some styles (namely, code blocks) from autocorre

Post by john1320 »

Hagar Delest wrote:I did some checks before posting and the dashes are not replaced if the language is set to [None].
Strange, doesn't work for me. Probably I should test more or maybe it is some difference between Open and Libre Office.
LibreOffice 5.2.7 on Windows 7
Post Reply