greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, packages, and more.
https://www.racket-mode.com/
GNU General Public License v3.0
682 stars 93 forks source link

#| comments |# auto-fill failure on Emacs 24.4.1 #237

Closed mwand closed 7 years ago

mwand commented 7 years ago

In emacs 24.4.1, with auto-fill turned on, the #| string is repeated at every filled line. Example:

#|
here issfjljsld fsfa dfsd fs fas fa fa fa fasd fa df asf as fa dfa fa
#|f ads fa sdf  fa f f fa  fsd f f gjldjg;g dfjgflgdfjg;df lgdklgjl;
#|gdfklgj ;g;glg ggjsdgljggj; ffg d 
mwand commented 7 years ago

racket-mode version is 20161029.1105

greghendershott commented 7 years ago

Interesting. It hadn't occurred to me auto-fill-mode ought to work; I manually M-q a.k.a. M-x fill-paragraph.

I can reproduce.

I see that auto-fill-mode works fine with

greghendershott commented 7 years ago

Well, scheme-mode "works fine" in the sense that it doesn't start new lines with #|. But it prepends an extra newline, i.e. a blank line.

c-mode works the way I imagine you'd want racket-mode to work.

greghendershott commented 7 years ago

Also, for me on GNU Emacs 24.5.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21) of 2015-04-10 on builder10-9.porkrind.org:

racket-mode with M-x auto-fill-mode is generating something different from what you report:

#| afd asdf as fa sdf asdf a dsf adsf a df asdf adf af asdf a dfa dsf  |#
#| asd fa sdf asd f asd fa sdf asd fa sd fa dsf asd f asd fa sd fas  |#
#| dfas df as df asdf as df as dfa sdf a dsf asd fa sd fas df as df  |#
#| asd f a |#

This is at least valid -- there are no mismatched comment starts and ends, as in what you saw.

However stylistically it's not as nice -- IMHO, and maybe yours? -- as e.g. what c-mode and auto-fill-mode does:

/* adf afd asdf af asf adsf asdf adf a dfa asdf asdf a sdfas df asdf
   as dfa sdf asdf ads fa sdf asd fasdf asdf ad fasdf adf as dfa sdf
   a sf dsf adf */
greghendershott commented 7 years ago

I'm still researching this -- there's quite a tangle of fill and comment Elisp I'm trying to understand, and step through using edebug.

However as at least a temporary work-around, what if you set comment-multiline to t?

comment-multi-line is a variable defined in `newcomment.el'.
Its value is t
Original value was nil

Documentation:
Non-nil means `comment-indent-new-line' continues comments.
That is, it inserts no new terminator or starter.
This affects `auto-fill-mode', which is the main reason to
customize this variable.

It also affects C-M-j.  However, if you want this
behavior for explicit filling, you might as well use M-x newline-and-indent.

You can customize this variable.

That seems to cause the desired behavior, for me. But I'm not sure it's the correct answer, or if it might have unintended consequences.

mwand commented 7 years ago

Nope, doesn't work for me. Again, with emacs 24.5.1 , in racket-mode with auto-fill turned on. Look at the last example

comment-multi-line = nil

;; sd fsdf sfsdfasf asdf sfa sf adsads fsd fasdf asdf sdf sdf asdf sf ;; ads fasd fasf ads f

comment-multi-line = t

;; a sfs fsfads fadsfa dsfdsaf sfa fdsf dsf sdfa sfs fads fsfa dsfa ;; sdf asf asdf sfa s fa sf df

| a sfs fsf asdfasd fsdf asfaf adsf dsf asf as fasd fasdf as fas dfsd

| fs dfa df ds f s fs dfa f fsdf

;; as dfs fasf sfa sdf sdf asdfa sf asf asdf s fasf asd fsdf asd fasdf

| asd fs fa sd fdsf

--Mitch

On Mon, Oct 31, 2016 at 8:27 PM, Greg Hendershott notifications@github.com wrote:

I'm still researching this -- there's quite a tangle of fill and comment Elisp I'm trying to understand, and step through using edebug.

However as at least a temporary work-around, what if you set comment-multiline to t?

comment-multi-line is a variable defined in `newcomment.el'. Its value is t Original value was nil

Documentation: Non-nil means comment-indent-new-line' continues comments. That is, it inserts no new terminator or starter. This affectsauto-fill-mode', which is the main reason to customize this variable.

It also affects C-M-j. However, if you want this behavior for explicit filling, you might as well use M-x newline-and-indent.

You can customize this variable.

That seems to cause the desired behavior, for me. But I'm not sure it's the correct answer, or if it might have unintended consequences.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/greghendershott/racket-mode/issues/237#issuecomment-257460309, or mute the thread https://github.com/notifications/unsubscribe-auth/ACOxMIcBjiHavPpROPwHlwyPDs9bob1Fks5q5odwgaJpZM4KlZ2P .

greghendershott commented 7 years ago

Can you please try a quick experiment:

In a .rkt buffer, M-: (Alt+Shift+:) and at the Eval: prompt enter (setq-local comment-start-skip ";+ *").

Then do you still get the extra #|s?

mwand commented 7 years ago

I think this gives the right behavior for #| comments, but ;; comments get screwed up


#| jds;fljs sflksjf adslkfsj fasjfadsf adsjfadsjf;lsdjfa
dsjflsjf;lajdsf adsf;adsj;asjf ads;fjslfasjd;sjf;fjff;fldsjf
lasf;jfalf
sdffaf
|#

;; ajsdfjslkfjls fja;sdljf sdjflksjf akjsfa dsflkdsjf dsjfadsjf s jfa
;;sajf afa dskfsf akdsjfsldfj lasfdssfj

#|
aksjf;ads sd fds sf sd fas fs fsd fas fasf sd fsd fs dfs fsd fsd fa
fas f sff fa fds f f f ff
|#

Normal behavior would be to put a space after the ;; on succeeding lines of the comment, eg

;; ajsdfjslkfjls fja;sdljf sdjflksjf akjsfa dsflkdsjf dsjfadsjf s jfa
;; sajf afa dskfsf akdsjfsldfj lasfdssfj
greghendershott commented 7 years ago
;; ajsdfjslkfjls fja;sdljf sdjflksjf akjsfa dsflkdsjf dsjfadsjf s jfa
;;sajf afa dskfsf akdsjfsldfj lasfdssfj

I don't see that happen. I get the desired space.

Could you please M-x racket-bug-report and paste the contents here? That will a number of settings including active minor modes. Maybe one is responsible for this, and I can figure it out.

greghendershott commented 7 years ago

By the way, cc-mode seems to have ~1100 lines of code related to breaking and filling. Although I'm not sure how much of that racket-mode would need to borrow -- to be able to handle #| |# style comments as thoroughly as that mode handles /* */ style comments -- I think it's unlikely I'll take many steps down that road. :)

Although I admit it's "anecdata", I very rarely see #| |# style comments in Racket code.

Having said all that, f there are a few tactical fixes that make them work well-enough, I'll definitely try to improve it.

mwand commented 7 years ago

I don't see that happen. I get the desired space.

Works for me now, too. I may have omitted the space before the asterisk in (setq-local comment-start-skip ";+ *"). Sorry about that.

mwand commented 7 years ago

By the way, cc-mode seems to have ~1100 lines of code related to breaking and filling. Although I'm not sure how much of that racket-mode would need to borrow -- to be able to handle #| |# style comments as thoroughly as that mode handles /* */ style comments -- I think it's unlikely I'll take many steps down that road. :)

Although I admit it's "anecdata", I very rarely see #| |# style comments in Racket code.

I hear you. The simple workaround is to write the block-comment not as a comment, and then put the #| ... |# around it afterwards. That has the useful side-effect of allowing me to use the indenter while I'm writing my comment.

Thanks for the prompt responses.

I'm going to leave this open for now, but I won't be offended if you close it.

--Mitch

greghendershott commented 7 years ago

Well I should at least push a commit to make that be the default for comment-start-skip.

For me, with that it unfortunately still does the same weird thing as scheme-mode -- inserting extra blank lines when it wraps. To avoid that, I need to set comment-multi-line to t. However that var isn't not buffer-local, so I don't think racket-mode should do this automatically. (Also I discovered that only through reading, but not truly understanding, a lot of Emacs' fill and comment code.) So I might need to just document that as a tip -- then close this issue :smile: -- until/unless I learn more someday.

greghendershott commented 7 years ago

Actually I can set comment-multi-line to t locally for racket-mode buffers. About to push a commit.