Ctags: ctags -R -x์˜ ์ถœ๋ ฅ์—์„œ โ€‹โ€‹ํƒœ๊ทธ ์ด๋ฆ„๊ณผ ์ข…๋ฅ˜๋ฅผ ๊ตฌ๋ฌธ ๋ถ„์„ํ•˜๋Š” ๋ฐฉ๋ฒ•

์— ๋งŒ๋“  2019๋…„ 03์›” 12์ผ  ยท  8์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: universal-ctags/ctags


ํŒŒ์„œ ์ด๋ฆ„: ์•„๋ฌด๊ฑฐ๋‚˜

ctags๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•œ ๋ช…๋ น์ค„:

$ ctags --options=NONE -R -x

์ž…๋ ฅ ํŒŒ์ผ์˜ ๋‚ด์šฉ:

$ git clone https://github.com/liuchengxu/vista.vim
$ cd vista.vim
$ ctags --options=NONE -R -x

๊ท€ํ•˜๊ฐ€ ๋งŒ์กฑํ•˜์ง€ ๋ชปํ•˜๋Š” ํƒœ๊ทธ ์ถœ๋ ฅ:

ctags -R -x ์˜ ์ถœ๋ ฅ์„ ๊ตฌ๋ฌธ ๋ถ„์„ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ctags -R -x ์˜ ์ถœ๋ ฅ์—์„œ โ€‹โ€‹ํƒœ๊ทธ ์ด๋ฆ„๊ณผ ๋ฒ”์œ„๋ฅผ ํ•„ํ„ฐ๋งํ•˜๊ณ  ์‹ถ์ง€๋งŒ ์ œ๋Œ€๋กœ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ชจ๋ฆ…๋‹ˆ๋‹ค.

์˜ˆ์ƒํ•˜๋Š” ํƒœ๊ทธ ์ถœ๋ ฅ:

ctags -R ์— ๋Œ€ํ•œ ํŠน์ • ํ˜•์‹๋„ ์žˆ๋Š” ๊ฒฝ์šฐ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

{tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..]

ctags ๋ฒ„์ „:

$ ctags --version
Universal Ctags 0.0.0(1208e45), Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Mar 11 2019, 17:01:27
  URL: https://ctags.io/
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +case-insensitive-filenames, +packcc

ctags ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•:

macOS์˜ brew install ctags

๋ชจ๋“  8 ๋Œ“๊ธ€

๋‚˜๋Š” ๋‹น์‹ ์˜ ์งˆ๋ฌธ์„ ์ดํ•ดํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค.

ctags -R ์˜ ์ถœ๋ ฅ์— ๋งŒ์กฑํ•˜์‹ญ๋‹ˆ๊นŒ? ๊ทธ๋ ‡๋‹ค๋ฉด -x ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?
๊ท€ํ•˜์˜ ์งˆ๋ฌธ์— ๋‹ต๋ณ€ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ ์‚ฌ๋ก€์˜ ๋ฐฐ๊ฒฝ์„ ๋” ์•Œ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

vim ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋ชจ๋ฆ…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ctags์˜ vim ํŒŒ์„œ์ธ vim.c๋ฅผ ์ฝ๋Š” ํ•œ ๋ฒ”์œ„ ํ•„๋“œ๋ฅผ ์ฑ„์šฐ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋ฒ„๊ทธ๋ผ๊ณ  ์ƒ๊ฐ๋˜๋ฉด vim ํŒŒ์„œ๊ฐ€ ์–ด๋–ค ์ข…๋ฅ˜์˜ ์ž…๋ ฅ์— ๋Œ€ํ•œ ๋ฒ”์œ„ ํ•„๋“œ๋ฅผ ์ฑ„์šฐ๋Š”์ง€ ์•Œ๋ ค์ฃผ์‹ญ์‹œ์˜ค.

๋ช…ํ™•ํžˆ ํ•˜์ง€ ๋ชปํ•ด ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค.

-x ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

ctags -R ๊ฐ€ ๋‚ด ํ•„์š”๋ฅผ ์ถฉ์กฑํ•˜์ง€๋งŒ ํƒœ๊ทธ ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ  ์‹ถ์ง€ ์•Š์œผ๋ฏ€๋กœ -x ์˜ต์…˜์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๋‚ด ์‚ฌ์šฉ ์‚ฌ๋ก€.

ํ˜„์žฌ vista.vim์€ ์ผ๋ถ€ ํŒŒ์ผ์˜ ํƒœ๊ทธ ํ‘œ์‹œ๋งŒ ์ง€์›ํ•˜์ง€๋งŒ ์ผ๋ถ€ ์‚ฌ์šฉ์ž๋Š” ํ”„๋กœ์ ํŠธ์˜ ๋ชจ๋“  ํƒœ๊ทธ ํ‘œ์‹œ๋ฅผ ์›ํ•ฉ๋‹ˆ๋‹ค(https://github.com/liuchengxu/vista.vim/issues/14). ctags -R ์ง€์›์„ ์ถ”๊ฐ€ํ•˜๋ ค๊ณ  ํ–ˆ์ง€๋งŒ ์ด๋Ÿฌํ•œ ์ถœ๋ ฅ์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ถ”์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.

ํ•œ๋งˆ๋””๋กœ vista#util#Trim , function , 18 , autoload/vista/util.vim , vista#util#Trim(str) ๋ฅผ ๊ฐ๊ฐ ์ถ”์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

ctags -R -x :

...
vista#util#Trim  function     18 autoload/vista/util.vim function! vista#util#Trim(str)
vista#util#Truncate function     13 autoload/vista/util.vim function! vista#util#Truncate(msg) abort
vista#util#Warning function     90 autoload/vista/util.vim function! vista#util#Warning(msg) abort
vista#viewer#Display function     90 autoload/vista/viewer.vim function! vista#viewer#Display(data) abort
vista#viewer#Render function     86 autoload/vista/viewer.vim function! vista#viewer#Render(data) abort
vista#viewer#prefixes function     94 autoload/vista/viewer.vim function! vista#viewer#prefixes() abort

-o - ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ctags๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅ์„ stdout์œผ๋กœ ๋‚ด๋ณด๋ƒ…๋‹ˆ๋‹ค.

[yamato@slave]/tmp/vista.vim% u-ctags -R -o - | head 
/   ftplugin/vista.vim  /^nnoremap <buffer> <silent> \/    :<c-u>call vista#finder#fzf#Run()<CR>$/;"    m
<CR>    ftplugin/vista.vim  /^nnoremap <buffer> <silent> <CR> :<c-u>call vista#cursor#FoldOrJump()<CR>$/;"  m
Commands    README.md   /^### Commands$/;"  S
Contributing    README.md   /^## Contributing$/;"   s
Features    README.md   /^## Features$/;"   s
Installation    README.md   /^## Installation$/;"   s
Introduction    README.md   /^## Introduction$/;"   s
License README.md   /^## License$/;"    s
NeoVim  README.md   /^#### NeoVim$/;"   t
Options README.md   /^### Options$/;"   S

--_xformat= ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅ์„ ์‚ฌ์šฉ์ž ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 u-ctags -R -x --_xformat='TAGNAME:%N @@@ KIND:%K !!! LINE:%n +++ INPUT-FILE:%F === PATTERN:%P' | head
TAGNAME:/ @@@ KIND:map !!! LINE:38 +++ INPUT-FILE:ftplugin/vista.vim === PATTERN:/^nnoremap <buffer> <silent> \/    :<c-u>call vista#finder#fzf#Run()<CR>$/
TAGNAME:<CR> @@@ KIND:map !!! LINE:37 +++ INPUT-FILE:ftplugin/vista.vim === PATTERN:/^nnoremap <buffer> <silent> <CR> :<c-u>call vista#cursor#FoldOrJump()<CR>$/
TAGNAME:Commands @@@ KIND:subsection !!! LINE:101 +++ INPUT-FILE:README.md === PATTERN:/^### Commands$/
TAGNAME:Contributing @@@ KIND:section !!! LINE:164 +++ INPUT-FILE:README.md === PATTERN:/^## Contributing$/
TAGNAME:Features @@@ KIND:section !!! LINE:37 +++ INPUT-FILE:README.md === PATTERN:/^## Features$/
TAGNAME:Installation @@@ KIND:section !!! LINE:69 +++ INPUT-FILE:README.md === PATTERN:/^## Installation$/
TAGNAME:Introduction @@@ KIND:section !!! LINE:25 +++ INPUT-FILE:README.md === PATTERN:/^## Introduction$/
TAGNAME:License @@@ KIND:section !!! LINE:168 +++ INPUT-FILE:README.md === PATTERN:/^## License$/
TAGNAME:NeoVim @@@ KIND:subsubsection !!! LINE:90 +++ INPUT-FILE:README.md === PATTERN:/^#### NeoVim$/
TAGNAME:Options @@@ KIND:subsection !!! LINE:113 +++ INPUT-FILE:README.md === PATTERN:/^### Options$/

http://docs.ctags.io/en/latest/news.html?highlight=--_xformat#customizing -xref-output ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

ํŒŒ์„œ๋ฅผ ์ž‘์„ฑํ•˜์ง€ ์•Š์œผ๋ ค๋ฉด --output-format=json ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

u-ctags -R --output-format=json | head
{"_type": "tag", "name": "/", "path": "ftplugin/vista.vim", "pattern": "/^nnoremap <buffer> <silent> \\/    :<c-u>call vista#finder#fzf#Run()<CR>$/", "kind": "map"}
{"_type": "tag", "name": "<CR>", "path": "ftplugin/vista.vim", "pattern": "/^nnoremap <buffer> <silent> <CR> :<c-u>call vista#cursor#FoldOrJump()<CR>$/", "kind": "map"}
{"_type": "tag", "name": "Commands", "path": "README.md", "pattern": "/^### Commands$/", "kind": "subsection"}
{"_type": "tag", "name": "Contributing", "path": "README.md", "pattern": "/^## Contributing$/", "kind": "section"}
{"_type": "tag", "name": "Features", "path": "README.md", "pattern": "/^## Features$/", "kind": "section"}
{"_type": "tag", "name": "Installation", "path": "README.md", "pattern": "/^## Installation$/", "kind": "section"}
{"_type": "tag", "name": "Introduction", "path": "README.md", "pattern": "/^## Introduction$/", "kind": "section"}
{"_type": "tag", "name": "License", "path": "README.md", "pattern": "/^## License$/", "kind": "section"}
{"_type": "tag", "name": "NeoVim", "path": "README.md", "pattern": "/^#### NeoVim$/", "kind": "subsubsection"}
{"_type": "tag", "name": "Options", "path": "README.md", "pattern": "/^### Options$/", "kind": "subsection"}

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! brew์— ์˜ํ•ด ์„ค์น˜๋œ ctags ๋Š” brew install ctags ์ด๋“  brew install --HEAD universal-ctags/universal-ctags/universal-ctags ์ด๋“  ๊ธฐ๋ณธ์ ์œผ๋กœ --output-format=json ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— $ --_xformat= ์˜ต์…˜์„ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.

@KazuakiM , ctags๋ฅผ libjansson.so.4์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†๋‚˜์š”?
u-ctags์—๋Š” json ์ถœ๋ ฅ ๋ชจ๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. u-ctags๊ฐ€ libjansson์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์œผ๋ฉด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
์ด๊ฒƒ์„ homebrew-universal-ctags repo์—์„œ ์ƒˆ๋กœ์šด ๋ฌธ์ œ๋กœ ๋ณด๊ณ ํ•ด์•ผ ํ•˜๋Š”์ง€ ์•Œ๋ ค์ฃผ์„ธ์š”.

@liuchengxu , ํƒœ๊ทธ ํŒŒ์ผ, ctags์˜ ๊ธฐ๋ณธ ํ˜•์‹์€ readtags.c์˜ ํ•จ์ˆ˜๋กœ ๊ตฌ๋ฌธ ๋ถ„์„๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
readtags ๋ช…๋ น ๋ฐ python-ctags3, python ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” readtags.c๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@masatake
์•ˆ๋…•ํ•˜์„ธ์š”, homebrew-universal-ctags๋Š” jansson์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

$ brew info universal-ctags
universal-ctags/universal-ctags/universal-ctags: HEAD
Maintained ctags implementation
https://github.com/universal-ctags/ctags
Conflicts with:
  ctags (because this formula installs the same executable as the ctags formula)
/usr/local/Cellar/universal-ctags/HEAD-1b747b3 (325 files, 4.3MB) *
  Built from source on 2019-02-02 at 16:45:17
From: https://github.com/universal-ctags/homebrew-universal-ctags/blob/master/universal-ctags.rb
==> Dependencies
Build: autoconf โœ”, automake โœ”, pkg-config โœ”
Optional: jansson โœ”, libyaml โœ”
==> Options
--with-jansson
        Build with jansson support
--with-libyaml
        Build with libyaml support
--without-doc
        Compile without man pages
--without-xml
        Compile without libxml2
--HEAD
        Install HEAD version
==> Caveats
Under some circumstances, emacs and ctags can conflict. By default,
emacs provides an executable `ctags` that would conflict with the
executable of the same name that ctags provides. To prevent this,
Homebrew removes the emacs `ctags` and its manpage before linking.
However, if you install emacs with the `--keep-ctags` option, then
the `ctags` emacs provides will not be removed. In that case, you
won't be able to install ctags successfully. It will build but not
link.

@KazuakiM ์ข‹์€ ์บ์น˜, ๋„์›€์„ ๋†“์ณค์Šต๋‹ˆ๋‹ค. JSON ์ง€์›์—๋Š” --with-jansson ์˜ต์…˜์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

$ brew reinstall --with-jansson universal-ctags/universal-ctags/universal-ctags
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰

๊ด€๋ จ ๋ฌธ์ œ

fommil picture fommil  ยท  19์ฝ”๋ฉ˜ํŠธ

masatake picture masatake  ยท  18์ฝ”๋ฉ˜ํŠธ

jagjordi picture jagjordi  ยท  9์ฝ”๋ฉ˜ํŠธ

lvc picture lvc  ยท  8์ฝ”๋ฉ˜ํŠธ

jespinal picture jespinal  ยท  8์ฝ”๋ฉ˜ํŠธ