Skip to content

Commit a0ef222

Browse files
committed
Enhanced Go hooks to add: goimports (esc-alt-i), gofmt (esc-alt-f),
gobuild (esc-alt-b), go run (esc-alt-r)
1 parent 230fbfb commit a0ef222

File tree

2 files changed

+56
-30
lines changed

2 files changed

+56
-30
lines changed

go.etf

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
/* -*- Go -*- ***************************************************************
2-
*
3-
* System :
4-
* Module :
5-
* Object Name : $RCSfile$
6-
* Revision : $Revision$
7-
* Date : $Date$
8-
* Author : $Author$
9-
* Created By : $USER_NAME$
10-
* Created : $ASCII_TIME$
11-
* Last Modified : <110506.0027>
1+
/* -*- go -*-
2+
* $RCSfile$ $Revision$ : $Date$ : $Author$
123
*
134
* Description
145
*
156
* Notes
167
*
17-
* History
18-
*
19-
****************************************************************************
8+
**************
209
*
21-
* Copyright (c) $YEAR$ $COMPANY_NAME$.
22-
*
23-
* All Rights Reserved.
10+
* Copyright (c) $YEAR$ $COMPANY_NAME$. All Rights Reserved.
2411
*
25-
* This document may not, in whole or in part, be copied, photocopied,
26-
* reproduced, translated, or reduced to any electronic medium or machine
12+
* This document may not, in whole or in part, be copied, photocopied,
13+
* reproduced, translated, or reduced to any electronic medium or machine
2714
* readable form without prior written consent from $COMPANY_NAME$.
28-
*
29-
****************************************************************************/
15+
*/

hkgo.emf

+49-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ set-variable .fhook-go.setup &reg "/history/fhook/go" "bdfghnopxlqv"
2424
set-variable .fhook-go.setup-mask "abdefghikmnoptuxclqrvy"
2525
set-variable .fhook-go.comment "|/*| */|*| * | * |f|"
2626
set-variable .fhook-go.comment-1 "|//||//|// | //|r|"
27-
set-variable .fhook-go.indent-width 4
27+
set-variable .fhook-go.indent-width 8
2828

2929
; Setup collapse
3030
set-variable .fhook-go.collapse-open "^\\(func\\|type\\)"
@@ -35,11 +35,11 @@ set-variable .fhook-go.item-list-s1 "^\\s*\\(func\\|type\\)\\s+\\(.+\\)\\s+{"
3535
set-variable .fhook-go.item-list-r1 "\\1 \ecB\\2\ecA"
3636

3737
; Setup Commands
38-
set-variable .fhook-go.command-flag "|t|th|th|"
39-
set-variable .fhook-go.command-name "||gofmt|gomake|"
40-
set-variable .fhook-go.command-nbind "||||"
41-
set-variable .fhook-go.command-kbind "||||"
42-
set-variable .fhook-go.command-desc "||Go \HFormat|Go \HMake|"
38+
set-variable .fhook-go.command-flag "|t|th|th|th|th|"
39+
set-variable .fhook-go.command-name "||gofmt|goimports|gobuild|gorun|"
40+
set-variable .fhook-go.command-nbind "||||||"
41+
set-variable .fhook-go.command-kbind "||||||"
42+
set-variable .fhook-go.command-desc "||Go \HFormat|Go \HImports|Go \HBuild|Go \HRun|"
4343

4444
!if &not &exist .hilight.go
4545
set-variable .hilight.go &pinc .hilight.next 1
@@ -156,12 +156,52 @@ set-variable .fhook-go.command-desc "||Go \HFormat|Go \HMake|"
156156
indent .hilight.go c "/$" t
157157
!endif
158158

159+
;define-macro gofmt
160+
; filter-buffer "gofmt -w"
161+
; ; DANGER would like to save-buffer auto here, but if gofmt hits an error
162+
; ; the output of filter-buffer is empty, nuking your file! Need some logic
163+
; ; here to detect empty filter-buffer?
164+
; ;save-buffer
165+
;!emacro
166+
159167
define-macro gofmt
160-
filter-buffer "gofmt"
168+
set-variable .file $buffer-bname
169+
;filter-buffer "gofmt"
170+
5 shell-command &cat "gofmt -w " .file
171+
172+
!if &equ $result 0
173+
0 reread-file
174+
;save-buffer
175+
!endif
176+
!emacro
177+
178+
define-macro goimports
179+
set-variable .file $buffer-bname
180+
;filter-buffer "goimports"
181+
5 shell-command &cat "goimports -w " .file
182+
183+
!if &equ $result 0
184+
0 reread-file
185+
;save-buffer
186+
!endif
161187
!emacro
162188

163-
define-macro gomake
164-
compile "gomake"
189+
define-macro gobuild
190+
set-variable .file $buffer-bname
191+
compile &cat "go build " .file
192+
; delete-other-windows
193+
!emacro
194+
195+
define-macro gorun
196+
set-variable .file $buffer-bname
197+
compile &cat "go run " .file
165198
!emacro
166199

167200
buffer-init-fhook "go"
201+
202+
; Useful shortcuts
203+
global-bind-key "gofmt" "esc A-f"
204+
global-bind-key "goimports" "esc A-i"
205+
global-bind-key "gobuild" "esc A-b"
206+
global-bind-key "gorun" "esc A-r"
207+
global-bind-key "delete-other-windows" "esc f1"

0 commit comments

Comments
 (0)