All Projects → brantou → emacs-go-tag

brantou / emacs-go-tag

Licence: GPL-3.0 license
Edit field tags for golang struct fields

Programming Languages

emacs lisp
2029 projects

Projects that are alternatives of or similar to emacs-go-tag

grammarly
Grammarly API interface
Stars: ✭ 87 (+77.55%)
Mutual labels:  emacs-plugin
Gops
A tool to list and diagnose Go processes currently running on your system
Stars: ✭ 5,404 (+10928.57%)
Mutual labels:  go-tools
Realize
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.
Stars: ✭ 4,162 (+8393.88%)
Mutual labels:  go-tools
unew
A tool for append URLs, skipping duplicates/paths & combine parameters.
Stars: ✭ 103 (+110.2%)
Mutual labels:  go-tools

emacs-go-tag

https://img.shields.io/badge/license-GPL_v3-green.svg https://melpa.org/packages/go-tag-badge.svg https://stable.melpa.org/packages/go-tag-badge.svg

Introduction

Edit field tags for golang struct fields, based on gomodifytags. This package is inspired by GoAddTags of vim-go and go-add-tags.

gomodifytags

Go tool to modify/update field tags in structs. gomodifytags makes it easy to update, add or delete the tags in a struct field. It can be installed with
go get github.com/fatih/gomodifytags

Installation

Available on all major package.el community maintained repos - MELPA Stable and MELPA repos.

MELPA Stable is recommended as it has the latest stable version. MELPA has a development snapshot for users who don’t mind breakage but don’t want to run from a git checkout.

You can install go-tag using the following command:

M-x package-install [RET] go-tag [RET]

or if you’d rather keep it in your dotfiles:

(unless (package-installed-p 'go-tag)
  (package-refresh-contents)
  (package-install 'go-tag))

If the installation doesn’t work try refreshing the package list:

M-x package-refresh-contents

Commands

If you are familiar with GoAddTags AND GoRemoveTags of vim-go , go-tag you will get started quickly.
  • go-tag-add

    :[range]go-tag-add [key],[option] [key1],[option] …

    Adds field tags for the fields of a struct. If called inside a struct it automatically add field tags with the json key and the value automatically generated based on the field name. An error message is given if it’s called outside a struct definition or if the file is not correctly formatted.

    If [range] is given, only the selected fields will be changed.

    The default json can be changed by providing one or more [key] arguments. An example of adding xml and db would be:

    :go-tag-add xml db

    If [option] is passed it’ll either add a new tag with an option or will modify existing tags. An example of adding omitempty to all json fields would be:

    :go-tag-add json,omitempty

    You can define a constant value instead of the default field based value. For example the following command will add `valid:"1"` to all fields.

    :go-tag-add valid=1

    https://github.com/brantou/emacs-go-tag/blob/master/img/go-tag-add.gif

  • go-tag-remove

    :[range]go-tag-remove [key],[option] [key1],[option1] …

    Rmove field tags for the fields of a struct. If called inside a struct it automatically remove all field tags. An error message is given if it’s called outside a struct definition or if the file is not correctly formatted

    If [range] is given, only the selected fields will be changed.

    If [key] is given, it will only remove those keys. Example:

    :go-tag-remove json

    If [option] is passed with a [key], it will only remove the options. Example, this will only remove omitempty options from fields containing json:

    :go-tag-remove json,omitempty

    https://github.com/brantou/emacs-go-tag/blob/master/img/go-tag-remove.gif

  • go-tag-refresh (Useful when designing structures)

    :[range]go-tag-refresh [key],[option] [key1],[option] …

    Equal to:

    :[range]go-tag-remove [key] [key1] …

    :[range]go-tag-add [key],[option] [key1],[option] …

Configuration

support the following transformations:

  • snakecase: BaseDomain -> base_domain
  • camelcase: BaseDomain -> baseDomain
  • lispcase: BaseDomain -> base-domain
(setq go-tag-args (list "-transform" "camelcase"))
(with-eval-after-load 'go-mode
  (define-key go-mode-map (kbd "C-c t") #'go-tag-add)
  (define-key go-mode-map (kbd "C-c T") #'go-tag-remove))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].