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: Stepan Bujnak
Subject: Re: Is it possible to run formatter before saving?
Date: Mon, 3 May 2021 11:04:17 +0200

On Fri, Apr 30, 2021 at 4:47 PM Benno Schulenberg <bensberg@telfort.nl> wrote:

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.

Yes, this is exactly what I wanted and it works like a charm. Thank you.
 

Benno


reply via email to

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