ethan-wspace icon indicating copy to clipboard operation
ethan-wspace copied to clipboard

ethan-wspace detetes trailing minuses (dashes) in auctex math formulas

Open sewkokot opened this issue 4 years ago • 2 comments

I have ethan-wspace installed for more than a year with the following configuration: (use-package ethan-wspace :diminish :config (setq mode-require-final-newline nil) (setq ethan-wspace-face-customized nil) (global-ethan-wspace-mode 1)) I'm using current emacs from git (compiled and built every two days or so)

For a week or two I have found that the function ethan-wspace-clean-before-save-hook in before-save-hook deletes trailing dashes (minuses) in math formulas of auctex mode. I have also noticed that strings of trailing dashes in comments of other modes are also removed. How this happens and how to prevent it (delete only trailing spaces not dashes)?

Thank you in advance!

sewkokot avatar Apr 12 '20 05:04 sewkokot

This is a really nasty bug - many equations in auctex mode and comments composed of trailing dashes/hyphens in other files were deleted. Fortunately I could identify and revert these changes under git version control.

I suspect that this is related to https://gitlab.com/ideasman42/emacs-spell-fu/-/blob/master/spell-fu.el which has this line: (modify-syntax-entry ?- "-" table) and in fact dashes in the affected files had the syntax of whitespace and not symbol.

In fact I played with spell-fu these days so it can the the reason. Anyway, I removed loading spell-fu and now the dashes are not removed anymore and the syntax of '---' is symbol.

Can you confirm that this could be the reason that the syntax table is related to this trailing dash removal?

sewkokot avatar Apr 16 '20 06:04 sewkokot

Sorry for the delayed reply!

This sounds like it's related to the eol cleanup code. However, this code doesn't itself do any of the deleting -- it just calls to the builtin emacs function delete-trailing-whitespace (shown here). You could see if the problem is there by just calling delete-trailing-whitespace explicitly instead of saving the file. I suspect that it will still delete your hyphen characters because of the code here -- it's going backwards until it finds a character that isn't of the syntax -, and then deleting it.

It seems that the syntax - is the syntax category of "whitespace". I see that spell-fu describes this as trying to make the hyphen character a "word boundary". Maybe setting it to syntax class _, meaning "symbol constitutent", would work instead, or ., for "punctuation character? However, I think the code in spell-fu is not trying to use this modified syntax table globally, but just in a few functions. Maybe the bug is that the syntax table is getting used too broadly somehow?

I do think that this interaction is the cause of the bug. I'm not 100% sure what to do about it. Maybe you could open a bug on the spell-fu repository. I'm happy to help more if I can!

glasserc avatar Apr 20 '20 01:04 glasserc