vile
[Top][All Lists]
Advanced

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

[vile] help with macro


From: Matthew White
Subject: [vile] help with macro
Date: Fri, 15 Aug 2014 18:50:04 -0700

hello all

I have written a macro to call "gofmt" (a program which formats Go source code)

gofmt will either produce formatted code to stdout or print errors to stdout.

Right now, this is what I'm doing in my macro, it seems overly complicated having to call gofmt twice, so I'm wondering if there's a better way to do this:

store-procedure goformat
  ~local %tmp
  ~local %gocode
  setv %gocode=$cbufname
  setv %tmpbuf "[gofmt Errors]"

  ; this bit stolen from gnugpg.rc then slightly modified
  ~force buffer %tmpbuf
  ~if $status
    unmark-buffer
    buffer '[Trace]'
    kill-buffer %tmpbuf
    kill-buffer '[Trace]'
  ~endif

  ; this is the bit I'm wondering about.  can't I just stuff the output into a new buffer?
  buffer %gocode
  goto-beginning-of-file
  yank-lines-til end-of-file
  split-current-window
  next-window
  edit-buffer %tmpbuf
  put-before
  goto-beginning-of-file
  filter-til end-of-file "gofmt 1> /dev/null"

  ~if &equ $blines 0
    unmark-buffer %tmpbuf
    ~force delete-buffer %tmpbuf
    buffer %gocode
    goto-beginning-of-file
    filter-til end-of-file "gofmt"
  ~else
    unmark-buffer %tmpbuf
    edit-buffer %gocode
  ~endif
~endm



any help is appreciated!

-mtw

reply via email to

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