help-nano
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it possible to run formatter before saving?


From: Benno Schulenberg
Subject: Re: Is it possible to run formatter before saving?
Date: Fri, 30 Apr 2021 16:47:37 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

Op 30-04-2021 om 00:00 schreef Stepan Bujnak:
> I'm writing a lot of Go code. When editing a Go file in nano, I would like to 
> run
> `goimports -w` which automatically formats the code right before saving. I 
> can do
> that by binding it to a key combination, but I'm interested whether it would 
> be
> possible to run the formatter automatically after pressing ^S or ^X and before
> saving the file.

Your question is a bit confusing: ^S saves the file, but you want to run
the formatter /after/ that but before saving the file???

Anyway, how about creating a little script that first runs /bin/nano on
all arguments, and then checks each argument in turn and runs whatever
on it when it is a Go file?  Then alias nano to this script and presto.

If instead you want ^S to format the buffer before saving it to disk,
then you need to rebind things.  Say 'bind M-5 savefile main',  and
'bind ^S "^[f^[5" main' (where ^[ is a literal escape), which causes
^S to act as if you pressed M-f followed by M-5.

Benno

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]