1 ;;; go-keyify.el --- keyify integration for Emacs
3 ;; Copyright 2016 Dominik Honnef. All rights reserved.
4 ;; Use of this source code is governed by a BSD-style
5 ;; license that can be found in the LICENSE file.
7 ;; Author: Dominik Honnef
9 ;; Keywords: languages go
10 ;; URL: https://github.com/dominikh/go-keyify
12 ;; This file is not part of GNU Emacs.
20 "Turn an unkeyed struct literal into a keyed one.
22 Call with point on or in a struct literal."
24 (let* ((name (buffer-file-name))
26 (bpoint (1- (position-bytes point)))
27 (out (get-buffer-create "*go-keyify-output")))
28 (with-current-buffer out
29 (setq buffer-read-only nil)
31 (with-current-buffer (get-buffer-create "*go-keyify-input*")
32 (setq buffer-read-only nil)
34 (go--insert-modified-files)
35 (call-process-region (point-min) (point-max) "keyify" t out nil
38 (format "%s:#%d" name bpoint)))
39 (let ((res (with-current-buffer out
40 (goto-char (point-min))
43 (1+ (cdr (assoc 'start res)))
44 (1+ (cdr (assoc 'end res))))
45 (insert (cdr (assoc 'replacement res)))
46 (indent-region (1+ (cdr (assoc 'start res))) (point))
51 ;;; go-keyify.el ends here