Skip to content

Commit

Permalink
Merge pull request #1 from Russtopia/rlm-hkgo-enh
Browse files Browse the repository at this point in the history
Enhanced Go hooks to add: goimports (esc-alt-i), gofmt (esc-alt-f),
  • Loading branch information
jcowgar committed Apr 5, 2016
2 parents 230fbfb + a0ef222 commit 9136014
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 30 deletions.
28 changes: 7 additions & 21 deletions go.etf
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
/* -*- Go -*- ***************************************************************
*
* System :
* Module :
* Object Name : $RCSfile$
* Revision : $Revision$
* Date : $Date$
* Author : $Author$
* Created By : $USER_NAME$
* Created : $ASCII_TIME$
* Last Modified : <110506.0027>
/* -*- go -*-
* $RCSfile$ $Revision$ : $Date$ : $Author$
*
* Description
*
* Notes
*
* History
*
****************************************************************************
**************
*
* Copyright (c) $YEAR$ $COMPANY_NAME$.
*
* All Rights Reserved.
* Copyright (c) $YEAR$ $COMPANY_NAME$. All Rights Reserved.
*
* This document may not, in whole or in part, be copied, photocopied,
* reproduced, translated, or reduced to any electronic medium or machine
* This document may not, in whole or in part, be copied, photocopied,
* reproduced, translated, or reduced to any electronic medium or machine
* readable form without prior written consent from $COMPANY_NAME$.
*
****************************************************************************/
*/
58 changes: 49 additions & 9 deletions hkgo.emf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set-variable .fhook-go.setup &reg "/history/fhook/go" "bdfghnopxlqv"
set-variable .fhook-go.setup-mask "abdefghikmnoptuxclqrvy"
set-variable .fhook-go.comment "|/*| */|*| * | * |f|"
set-variable .fhook-go.comment-1 "|//||//|// | //|r|"
set-variable .fhook-go.indent-width 4
set-variable .fhook-go.indent-width 8

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

; Setup Commands
set-variable .fhook-go.command-flag "|t|th|th|"
set-variable .fhook-go.command-name "||gofmt|gomake|"
set-variable .fhook-go.command-nbind "||||"
set-variable .fhook-go.command-kbind "||||"
set-variable .fhook-go.command-desc "||Go \HFormat|Go \HMake|"
set-variable .fhook-go.command-flag "|t|th|th|th|th|"
set-variable .fhook-go.command-name "||gofmt|goimports|gobuild|gorun|"
set-variable .fhook-go.command-nbind "||||||"
set-variable .fhook-go.command-kbind "||||||"
set-variable .fhook-go.command-desc "||Go \HFormat|Go \HImports|Go \HBuild|Go \HRun|"

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

;define-macro gofmt
; filter-buffer "gofmt -w"
; ; DANGER would like to save-buffer auto here, but if gofmt hits an error
; ; the output of filter-buffer is empty, nuking your file! Need some logic
; ; here to detect empty filter-buffer?
; ;save-buffer
;!emacro

define-macro gofmt
filter-buffer "gofmt"
set-variable .file $buffer-bname
;filter-buffer "gofmt"
5 shell-command &cat "gofmt -w " .file

!if &equ $result 0
0 reread-file
;save-buffer
!endif
!emacro

define-macro goimports
set-variable .file $buffer-bname
;filter-buffer "goimports"
5 shell-command &cat "goimports -w " .file

!if &equ $result 0
0 reread-file
;save-buffer
!endif
!emacro

define-macro gomake
compile "gomake"
define-macro gobuild
set-variable .file $buffer-bname
compile &cat "go build " .file
; delete-other-windows
!emacro

define-macro gorun
set-variable .file $buffer-bname
compile &cat "go run " .file
!emacro

buffer-init-fhook "go"

; Useful shortcuts
global-bind-key "gofmt" "esc A-f"
global-bind-key "goimports" "esc A-i"
global-bind-key "gobuild" "esc A-b"
global-bind-key "gorun" "esc A-r"
global-bind-key "delete-other-windows" "esc f1"

5 comments on commit 9136014

@Russtopia
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I wonder if some of the new macros should do a save-buffer prior to running (eg., gofmt: esc-alt-f, and goimports: est-alt-i).

I hadn't loaded up a session in awhile, and forgot that one must explicitly hit ctrl-x-s to save a buffer prior to doing eithe rof the above, otherwise changes are lost!

Current macros look like this:

define-macro gofmt
set-variable .file $buffer-bname
;filter-buffer "gofmt"
5 shell-command &cat "gofmt -w " .file

!if &equ $result 0
    0 reread-file
    ;save-buffer
!endif

!emacro

I'll see if I can make a version that sensibly calls save-buffer prior to the shell-command. If a better workflow occurs to you suggestions are welcome as to how best to improve these.

@jcowgar
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Russtopia, I no longer use MicroEmacs, if you would like to take this project over, I'd be happy with that!

@Russtopia
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh :)
Well I still have a soft spot for it even though I admit I've fallen down the Eclipse rathole over the last few years. Sure. Is there a formal handoff procedure or shall I just start updating my own tree directly and leave it at that? I'm a bit of a github n00b.

@jcowgar
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can transfer it to you. I tried, but it said dotmicroemacs already exists for you. Maybe you have to remove your copy first? Did you add anything to it that is not in mine?

@Russtopia
Copy link
Contributor

@Russtopia Russtopia commented on 9136014 Apr 14, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.