                         (kill-buffer errbuf)
                         (if newfile
                             ;; New file, replace it (diff-mode won't work)
-                            (gofmt-replace-buffer srcbuf patchbuf)
+                            (gofmt--replace-buffer srcbuf patchbuf)
                           ;; Existing file, patch it
-                          (gofmt-apply-patch filename srcbuf patchbuf))
+                          (gofmt--apply-patch filename srcbuf patchbuf))
                         (goto-char (min old-point (point-max)))
                         ;; Restore the mark and point
                         (if old-mark (push-mark (min old-mark (point-max)) t))
                         (set-window-configuration currconf))
 
                     ;; gofmt failed: display the errors
-                    (gofmt-process-errors filename errbuf))))))
+                    (gofmt--process-errors filename errbuf))))))
 
           ;; Collapse any window opened on outbuf if shell-command-on-region
           ;; displayed it.
           (delete-windows-on patchbuf)))
       (kill-buffer patchbuf))))
 
-(defun gofmt-replace-buffer (srcbuf patchbuf)
+(defun gofmt--replace-buffer (srcbuf patchbuf)
   (with-current-buffer srcbuf
     (erase-buffer)
     (insert-buffer-substring patchbuf)))
 
-(defun gofmt-apply-patch (filename srcbuf patchbuf)
+(defun gofmt--apply-patch (filename srcbuf patchbuf)
   (require 'diff-mode)
   ;; apply all the patch hunks
   (with-current-buffer patchbuf

            (let ((file (concat dir "/" file)))
              (when (file-directory-p file)
                (setq dirs (append (cons file
                                         (go-directory-dirs file))
                                   dirs))))))
        dirs)
    '()))

(defun go-flatten (lst)
  (if (atom lst)
      (list lst)
    (let ((item (car lst))
          (rest (cdr lst)))
      (if (not (atom item))
          (if rest
              (append (go-flatten item) (go-flatten rest))
            (let ((item-rest (cdr item)))
              (if item-rest
                  (append (go-flatten (car item))(go-flatten item-rest))
                (go-flatten (car item)))))
        (if rest
            (if item
                (append (list item) (go-flatten rest))
              (go-flatten rest))
          (if item
              (list item)
            nil))))))

    (when buffer (kill-buffer buffer))
    (get-buffer-create buffer-name)))

(defun godoc--buffer-sentinel (proc event)
  "Sentinel function run when godoc command completes."
  (with-current-buffer (process-buffer proc)
    (cond ((string= event "finished\n")  ;; Successful exit.
