Re: getting nicely justified comments in an easy way

Benno Schulenberg <[email protected]> Fri, 29 Mar 2019 19:55:51 +0100
Newsgroups gmane.editors.nano.general
Message-ID <[email protected]>
Hello Seb,

Op 29-03-19 om 14:14 schreef Seb:
> First of all, thanks to the team for 'nano', which keeps getting better.

It's nice to hear that it is appreciated.  :)

> When I write some code, I comment a lot. What I do is disable the wrapping of
> long lines, write the long comment on one line, starting with '#', then apply ^J.
> Then the comment looks nice.
> 
> But this is not really convenient since I often need to re-read a part of the
> comment that is no longer on the screen. I then ^J and restart the process.
> 
> What I'd like is to enable the wrapping of long lines, start a comment with #,
> type away and see a '#' automagically appear at the beginning of a new line.

This automatic appearing of "#" (or whatever the comment starts with) is
not possible.  But you can use the new region-justifying feature to achieve
something close to it.

Start nano with --quotestr="^(# |// )".  When you want to write a comment,
you enable automatic hard-wrapping with M-L and start your comment with
either "# " or "// ", and then type away your text.  When you've finished,
you use <Shift+Up> to select the whole comment (but make sure the selection
does not begin before the first comment line), and then type ^J.  Et voilà:
the comment is justified and all lines start with the same character sequence
as the first.

You don't even have to select the whole first comment line, as long as
the cursor is on that line when you press ^J, nano will use the prefix
of that line for the rest of the lines too.

(David Ramsey made this new feature, available in nano-4.0.)

> Additionaly, I'd like to enable both '#' and '//' as comment strings within the
> same document, since I write HTML pages containing both Perl and JavaScript code.

The justify command will recognize any character (or character group)
that is in quotestr as a comment-introducer.  See man nanor(5).  You
can customize it if you want, like adding a mandatory trailing space,
as done above.

> Finally, a completely unrelated question: when a document contain long lines (>
> 80 chars), is there a keyboard switch what would allow me to see the far end of
> the line as wrapped, on the same screen, as Vim does?

Yes, you can toggle softwrap with: M-$.  On an American keyboard this
is somewhat awkward: Alt+Shift+$, but on a French keyboard it seems
the $ is on the first, unshifted plane, next to the Enter key?  So it
should be easy to type.  Or does the keystroke not work for you?

Benno

_______________________________________________
Help-nano mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-nano
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEv9AJBh5TUFKtDfIVDSjU0qCs6IQFAlyeajgACgkQDSjU0qCs
6ISdLg/+KZCf7dAkFArtp/LE/FxTBfTmzlOfo5UL/ZBTIwjWdw2I+Uqwgib4VkyZ
kNL3rAyy7lcRmIEZKlfWTX1bELAgQTlv8CiTH6g1I1PhLdmugy01bXlL+DLj1F5H
AC5u8aWwq3vjxfyeq5vbS4fK2abIwLYbcVW51xJXscVAlqqRGAkJnjkzbv2/w6F/
7CsJo9NZkwfyLKua57bKuTmM0O+NqhfWhsKMJg4UMPriG5YWj9NwAOc2qnu8ziHg
bHAxyZTIGagjdArMVnaNMvkgbJ/OrMFZLymRd/3EiChPOQd9tGA5E9C7KW1tobd/
nlGmlrkFsGG6wQJ2cCcYpX+TmxaOtC90uP146MTHS5xXR2gsirnJOWgfZuwUKujd
TlXBfKGYzHsgWdSC3x7TelX7FDu76qXklzWeMm/VBA7ptkHjX88H042uhP5Gyo1H
RFLj/+RtB0lC18QWZfRazh4A96UIHRMusu35a9ZFXKWGOJHfNamORun/6XyEjQC/
e1cjjh3liZoGUVhgpj/jkOF6cYSikD9A9VsCNJpzoxKkThKT9TgbnIOiEuJT5vM5
EvQkic9SkIE8BVGtYr+g9iLIWb4NcVm5SASUw43/2eHwT2m7w/Bp7xNOzwNZeeS8
iVjzuc0V/kskrrT4GmukDaP2iQB934RZlgrQU5BmqOGm74Ma/T0=
=m3/n
-----END PGP SIGNATURE-----