Emacs supports Gomodifytags

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Inspired by the Go Ultimate guide: Writing a go tool, the idea of encapsulating the gomodifytags into a emacs-plugin, and then a two-week effort, was born Emacs-go-tag. emacs-go-tagimplemented two commands: go-tag-add add struct field tag, go-tag-remove delete struct field tag.

Installation dependencies

emacs-go-tagThere are two dependencies, gomodifytags and Go-mode.el, if using Emacs to do go development go-mode.el should already be in use. Gomodifytags installation is as follows:

go get -u github.com/fatih/gomodifytags


Currently Emacs-go-tag has been published on Melpa and can be installed using the following command:
M-x package-install [RET] go-tag [RET]
If you do not find Go-tag, you need to use the following command to refresh, and then use the above command to install:
M-x package-refresh-contents [RET]


gomodifytagsThree types of conversions are currently supported:

    • Snakecase:basedomain-Base_domain
    • Camelcase:basedomain-Basedomain
    • Lispcase:basedomain-Base-domain

Default use snakecase , if you are ready to use camelcase , can be configured as follows:

(setq go-tag-args (list "-transform" "camelcase"))

Example of a shortcut key configuration:

(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))

Instructions for use

If you have experience using Vim-go GoAddTags and GoRemoveTags commands, then you will be very quick to get started emacs-go-tag because the two behaviors are exactly the same (if different, please feedback).


:[range] go-tag-add [key],[option] [key1],[option] …
Add a tag to the struct field. If called in a struct, the JSON field tag is added automatically. If it is called outside the struct, or if the file is malformed, an error message is given.

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

The default JSON can be changed by providing one or more [key] parameters. Examples of adding XML and DB are:
:go-tag-add xml db

If provided, the tag [option] will be added together, option or the existing tag can be modified. As follows:
:go-tag-add json,omitempty

You can also define a constant value instead of the default field-based value. For example, the following command adds ' valid: ' 1 ' to all fields.
:go-tag-add valid=1


:[range] go-tag-add [key],[option] [key1],[option] …
Removes the field marker from the structure field. If called in a struct, it will automatically delete all the field tags. If called outside of the struct definition, or if the file is malformed, an error message is given.

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

If given [key] , only those key-related tags will be deleted. Only JSON-related tags are removed as follows:
:go-tag-remove json

If it is [option] [key] passed together, it will only be deleted option . For example, the following command removes the Omitempty option only from fields that contain JSON:
:go-tag-remove json,omitempty

At last

Thanks to GoCN每日新闻 The daily push, I was able to read the Go Ultimate guide: Write a go tool and get this done emacs-plugin . Project Address: Https://github.com/brantou/em, welcome to use and could be free questions, if you feel that it helps you 就给颗星 .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.