Gedit - An IDE for Go

658 views
Skip to first unread message

jgord

unread,
Dec 15, 2009, 5:29:54 AM12/15/09
to golang-nuts
For anybody that is interested, I have created a tutorial about things
you can do with Gedit under Linux Gnome to make it a basic IDE for
Go. www.gohelp.wordpress.com

Joan Miller

unread,
Dec 15, 2009, 6:33:15 AM12/15/09
to golang-nuts
Thank you very much. It's awesome!

befelemepeseveze

unread,
Dec 15, 2009, 7:19:01 AM12/15/09
to golang-nuts
I'm using a slightly different format tool for gedit, it handles the
situation when gofmt reject your code and returns nothing on stdout,
which one must then undo in gedit. The bellow version is for the
upcoming semicolon rules, so if you are not using them, set the
"oldprinter" and "oldparser" to true. Or just delete those options, as
that is the current default setting.

#!/bin/sh

tmp=`mktemp`
cat > $tmp
gofmt -oldprinter=false -oldparser=false -w $tmp 2>/dev/null
cat $tmp
rm -f $tmp

jgord

unread,
Dec 15, 2009, 8:58:10 PM12/15/09
to golang-nuts
Good catch. Thanks. I put a note on the site. While I try out
workarounds like you suggest, I suggested that the output from 'gofmt'
could be redirected to a new tab rather than the current one in Gedit.

From the Rob Pike video and the little bit in 'effective go', I
assumed that 'gofmt' was just a pretty pager and that if it saw
something it couldn't handle it would just skip it. I should know
better. After looking at some of these postings and the bug tracker,
it appears that they are using it for source file conversion as the
language quickly evolves. I will leave the discussion about what it
should change to others, but I would find it more useful if they
output the source file and, when it found something it didn't like
other than basic prettiness, show an in-line comment.


On Dec 15, 7:19 pm, befelemepeseveze <befelemepesev...@gmail.com>
wrote:

Steven Blenkinsop

unread,
Dec 16, 2009, 12:04:58 AM12/16/09
to golang-nuts
Its not too bad. I just hit the undo button when it goes screwy. But
yes, one mistake shouldn't make the output (next to) useless. I had a
'disaster' with a missing ',' at the end of a multi-line struct
literal (not having one with the new semicolon rules makes the parser
put a semicolon at the end of the list, breaking the code). The error
in this case is quite useless, since it then refers to the non-
existent semicolon, and one doesn't expect to have to put a ',' at the
end of a list.

jgord

unread,
Dec 16, 2009, 6:36:31 AM12/16/09
to golang-nuts
Too easy! Thanks for the tip. I'll add it to 'Gedit - An IDE for
Go'.

befelemepeseveze

unread,
Dec 16, 2009, 8:50:44 AM12/16/09
to golang-nuts
On 15 pro, 11:29, jgord <jgord1...@gmail.com> wrote:
More bits of possible interest. Paste to terminal only. If pasting to
an editor instead, you have to unescape the backticks.

cat > ~/.gnome2/gedit/tools/go-godoc-current-word <<EOF
#!/bin/sh
# [Gedit Tool]
# Name=godoc for package name under cursor
# Shortcut=F1
# Languages=go
# Applicability=all
# Output=output-panel
# Input=word
# Save-files=nothing


godoc \`cat\`
EOF

cat > ~/.gnome2/gedit/tools/go-godoc-selected-qualident <<EOF
#!/bin/sh
# [Gedit Tool]
# Name=godoc for selected qualified identifier
# Shortcut=<Shift>F1
# Languages=go
# Applicability=all
# Output=output-panel
# Input=selection-document
# Save-files=nothing


godoc \`sed 's/\./ /'\`
EOF

Qtvali

unread,
Dec 16, 2009, 9:08:22 AM12/16/09
to golang-nuts
Couldn't write a script, which catches stderr and writes input to
stdout if this is the case?

For example:
* Direct output from gofmt to one file
* Direct stdout to another file
* If this other file is empty, direct first file to real stdout,
otherwise direct original input to real stdout

This could handle the case?

Joan Miller

unread,
Dec 16, 2009, 2:22:23 PM12/16/09
to golang-nuts
I just find a little feature.

Tools>Manage External Tools

In 'Tools' window, click over a function for Go, and on the right you
have to click just above the Close button --which has marked all
languages-- and then you set Go. :)

On 15 dic, 10:29, jgord <jgord1...@gmail.com> wrote:

delfick

unread,
Dec 16, 2009, 7:49:01 PM12/16/09
to golang-nuts

On Dec 16, 9:58 am, jgord <jgord1...@gmail.com> wrote:
> Good catch.  Thanks.  I put a note on the site.  While I try out
> workarounds like you suggest, I suggested that the output from 'gofmt'
> could be redirected to a new tab rather than the current one in Gedit.

you do realise that gofmt has an option to replace the files it
formats right ?

so you don't have to manually replace the file with the ouput of
gofmt.......

jgord

unread,
Dec 17, 2009, 12:58:24 AM12/17/09
to golang-nuts
I followed up on your tip from above and wrote a more complete Go
Format script. It does the following:

1. If the reformat is successful, with no errors, it outputs the
reformatted file with a commented datetime stamp at the bottom.
2. If the reformat produces errors, it outputs a commented error
list at the top of the original source file.
3. Any other condition, it outputs the original source file.

It is posted at www.gohelp.wordpress.com under Go Format V2.


On Dec 16, 8:50 pm, befelemepeseveze <befelemepesev...@gmail.com>
wrote:

jgord

unread,
Dec 17, 2009, 1:00:25 AM12/17/09
to golang-nuts
Yes, but I wanted the safety of easy recovery in Gedit, so didn't want
to overwrite the original file.

jgord

unread,
Dec 17, 2009, 1:02:56 AM12/17/09
to golang-nuts
You might want to look at my new post above and look at new script at
www.gohelp.wordpress.com Go Format V2. Hope this helps.

Steven Blenkinsop

unread,
Dec 17, 2009, 1:45:49 AM12/17/09
to golang-nuts
Thats a bit better. If only there were some way to pipe selectively,
but it doesn't seem that there is.

jgord

unread,
Dec 17, 2009, 3:35:43 AM12/17/09
to golang-nuts
It would be nice if External Tools had one more output selection, so
you could specify one for stdout and another for stderr. For example,
stderr going to the bottom pane. I dug around quite a bit and don't
see a way to switch panes on the fly. One could send stderr to a pop-
up terminal.

Joan Miller

unread,
Dec 17, 2009, 3:47:29 AM12/17/09
to golang-nuts
These functions only works when the line is selected:

* Comment (<Control>3)
-----------
#!/bin/bash

char='//'
sed "s|^|$char|"
-----------
Input: current line
Output: Replace current selection
Applicability: All documents

* Comment out (<Control>2)
-----------
#!/bin/bash

char='//'
sed "s|^$char||"
-----------
Input: current line
Output: Replace current selection
Applicability: All documents

* --------------------- *
It should there be an option in the Output to choose 'Replace current
line'.

jgord

unread,
Dec 17, 2009, 3:48:43 AM12/17/09
to golang-nuts
Nice! Before it recognized when a Go document was open, I assume it
used the program suffix '.go'. But with this we can move other Tools
we don't need out of the way on the Tools>External Tools dropdown
menu. For example, I changed the built in 'Build' Tool and the 'Remove
trailing spaces' Tool to C. Now I don't see them with Go.

Thanks, I will add this to the Howto.

befelemepeseveze

unread,
Dec 17, 2009, 4:27:32 AM12/17/09
to golang-nuts
On 17 pro, 07:00, jgord <jgord1...@gmail.com> wrote:
> Yes, but I wanted the safety of easy recovery in Gedit, so didn't want
> to overwrite the original file.

AFAIK gofmt -w <file(s)> does overwrite the original <file(s)> IFF
there are no errors during the formating/converting/rewriting.
Otherwise it keeps the original untouched and only produces a error
list on stderr.

delfick

unread,
Dec 17, 2009, 4:29:06 AM12/17/09
to golang-nuts

On Dec 17, 2:00 pm, jgord <jgord1...@gmail.com> wrote:
> Yes, but I wanted the safety of easy recovery in Gedit, so didn't want
> to overwrite the original file.

You still have that safety.

It'll just say the file has been modified from elsewhere and ask if
you want to refresh it....

Also, you should be relying on external version control for recovery
anyways.....

befelemepeseveze

unread,
Dec 17, 2009, 4:43:23 AM12/17/09
to golang-nuts
On 17 pro, 09:47, Joan Miller <pelok...@gmail.com> wrote:
> * Comment (<Control>3)
> -----------
> * Comment out (<Control>2)
> -----------

Also you can get the "gedit-plugins" package using our distro's pkg
manager (sudo apt-get gedit-plugins on Ubuntu for example) and enable
the commenting plugin in gedit.

Joan Miller

unread,
Dec 17, 2009, 6:41:03 AM12/17/09
to golang-nuts
Thanks! It has the plugins that I wanted, I'll can now to substitute
my komodo edit which I use for python.

jgord

unread,
Dec 17, 2009, 7:21:51 AM12/17/09
to golang-nuts
your right, I start messing with version control in the next chapter.

jgord

unread,
Dec 17, 2009, 7:39:26 AM12/17/09
to golang-nuts
thanks, commenting is very handy. I had found the 3rd party plugins
page, but did not realize that the best had been packaged. I'll add
them to the Howto.

On Dec 17, 4:43 pm, befelemepeseveze <befelemepesev...@gmail.com>
wrote:

jgord

unread,
Jan 4, 2010, 9:30:32 AM1/4/10
to golang-nuts
Gedit - An IDE for Go has been completely revised and expanded using
the input that I have received.

Go Format, Go Build, Go Run and Go Doc all now have real scripts
behind them in Version 2. They can display to a Pop up Window, a Pop
up Terminal or in Gedit depending upon your needs. Go Format
especially now behaves much better, with the new format in the
original edit tab, if it succeeds, or the original file restored, if
it does not, with multiple options for the error display.

I hope my small contribution to the Go project is useful.

BTW, has anybody used tortoisehg on Linux? I am starting on version
control.

John


On Dec 15 2009, 5:29 pm, jgord <jgord1...@gmail.com> wrote:
> For anybody that is interested, I have created a tutorial about things

> you can do withGeditunder Linux Gnome to make it a basic IDE for
> Go.  www.gohelp.wordpress.com

Reply all
Reply to author
Forward
0 new messages