https://github.com/brantou/emacs-go-tag
Edit field tags for golang struct fields
https://github.com/brantou/emacs-go-tag
emacs-lisp emacs-plugin go-tools golang
Last synced: about 1 month ago
JSON representation
Edit field tags for golang struct fields
- Host: GitHub
- URL: https://github.com/brantou/emacs-go-tag
- Owner: brantou
- License: gpl-3.0
- Created: 2017-11-08T07:02:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T11:44:21.000Z (over 2 years ago)
- Last Synced: 2025-04-09T12:21:50.917Z (about 2 months ago)
- Topics: emacs-lisp, emacs-plugin, go-tools, golang
- Language: Emacs Lisp
- Homepage:
- Size: 181 KB
- Stars: 62
- Watchers: 1
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+TITLE: emacs-go-tag
[[http://www.gnu.org/licenses/gpl-3.0.html][file:https://img.shields.io/badge/license-GPL_v3-green.svg]]
[[https://melpa.org/#/go-tag][file:https://melpa.org/packages/go-tag-badge.svg]]
[[https://stable.melpa.org/#/go-tag][file:https://stable.melpa.org/packages/go-tag-badge.svg]]* Introduction
:PROPERTIES:
:ID: 433a1d5f-9353-496f-a783-8c123cc0a633
:END:Edit field tags for golang struct fields, based on [[https://github.com/fatih/gomodifytags][gomodifytags]].
This package is inspired by ~GoAddTags~ of [[https://github.com/fatih/vim-go][vim-go]] and [[https://github.com/syohex/emacs-go-add-tags][go-add-tags]].* gomodifytags
:PROPERTIES:
:ID: f51e9e98-85ed-428a-90ba-d0727a257402
:END:
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
#+BEGIN_SRC shell :eval strip-export
go install github.com/fatih/gomodifytags@latest
#+END_SRC* Installation
:PROPERTIES:
:ID: edb6d6eb-9d05-418c-81d9-7452b9db3d69
:END:Available on all major ~package.el~ community maintained repos -
[[https://stable.melpa.org/#/][MELPA Stable]] and [[https://melpa.org/#/][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:
#+BEGIN_SRC elisp
(unless (package-installed-p 'go-tag)
(package-refresh-contents)
(package-install 'go-tag))
#+END_SRCIf the installation doesn't work try refreshing the package list:
~M-x package-refresh-contents~
* Commands
:PROPERTIES:
:ID: dbee016c-6edd-4999-9303-419d35469ad2
:END:
If you are familiar with ~GoAddTags~ AND ~GoRemoveTags~ of [[https://github.com/fatih/vim-go][vim-go]] , ~go-tag~ you will get started quickly.
- ~go-tag-add~
#+BEGIN_QUOTE
:[range]go-tag-add [key],[option] [key1],[option] ...
#+END_QUOTEAdds 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:#+BEGIN_QUOTE
:go-tag-add xml db
#+END_QUOTEIf [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:
#+BEGIN_QUOTE
:go-tag-add json,omitempty
#+END_QUOTEYou can define a constant value instead of the default field based value.
For example the following command will add ~`valid:"1"`~ to all fields.
#+BEGIN_QUOTE
:go-tag-add valid=1
#+END_QUOTE[[https://github.com/brantou/emacs-go-tag/blob/master/img/go-tag-add.gif]]
- ~go-tag-remove~#+BEGIN_QUOTE
:[range]go-tag-remove [key],[option] [key1],[option1] ...
#+END_QUOTERmove 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
formattedIf [range] is given, only the selected fields will be changed.
If [key] is given, it will only remove those keys. Example:
#+BEGIN_QUOTE
:go-tag-remove json
#+END_QUOTEIf [option] is passed with a [key], it will only remove the options.
Example, this will only remove ~omitempty~ options from fields containing
~json~:#+BEGIN_QUOTE
:go-tag-remove json,omitempty
#+END_QUOTE
[[https://github.com/brantou/emacs-go-tag/blob/master/img/go-tag-remove.gif]]- ~go-tag-refresh~ (Useful when designing structures)
#+BEGIN_QUOTE
:[range]go-tag-refresh [key],[option] [key1],[option] ...
#+END_QUOTEEqual to:
#+BEGIN_QUOTE
:[range]go-tag-remove [key] [key1] ...
:[range]go-tag-add [key],[option] [key1],[option] ...
#+END_QUOTE* Configuration
:PROPERTIES:
:ID: 9f364afb-69ae-47dc-ae2e-d76bdcefc928
:END:support the following transformations:
- ~snakecase~: ~BaseDomain~ -> ~base_domain~
- ~camelcase~: ~BaseDomain~ -> ~baseDomain~
- ~lispcase~: ~BaseDomain~ -> ~base-domain~#+BEGIN_SRC elisp :eval strip-export
(setq go-tag-args (list "-transform" "camelcase"))
#+END_SRC#+BEGIN_SRC elisp :eval strip-export
(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))
#+END_SRC