2015-10-19 53 views
0

我正在嘗試爲vim tagbar配置一個「自定義語言」,它允許tagbar用於查看Abaqus有限元分析輸入文件。vim tagbar:自定義語言配置

我複製從下面的鏈接例子:

http://github.com/majutsushi/tagbar/wiki

http://andrew.stwrt.ca/posts/vim-ctags/

ctags, vimwiki, vim and tagbar-plugin

http://ctags.sourceforge.net/EXTENDING.html

這是SOF tware我使用:

  • RHEL 6.7
  • VIM 7.4
  • tagbar 2.6.1
  • 旺盛Ctags的5.8

一個Abaqus的輸入文件example.inp的實施例

** Analyst: 
** Comments 
** More comments 
** 
**************************************** 
** Section Name One 
**************************************** 
*Keyword1 
*KEYWORD2 
** 
**************************************** 
** Section Name Two 
**************************************** 
*Keyword3 

這是我加入到我的vim配置文件的〜/ .vimrc

let g:tagbar_type_AbaqusINP = { 
    \ 'ctagstype' : 'AbaqusINP', 
    \ 'kinds' : [ 
     \ 's:Section', 
     \ 'k:Keyword' 
    \ ], 
    \ 'sort' : 0 
\ } 

我創建了一個ctags的配置文件〜/ .ctags

--langdef=AbaqusINP 
--langmap=AbaqusINP:.inp 
--regex-AbaqusINP=/^\*\*\*[\*]+\n\*\*[ \tA-Za-z]+/\3/s,Section/ 
--regex-AbaqusINP=/^\*[A-Za-z]+/\1/k,Keyword/ 

當我打開輸入文件和然後打開標籤欄沒有任何東西。從命令行調用以下內容時,AbaqusINP * .inp會出現在列表中。

$ ctags --list-maps 
Ant  *.build.xml 
... 
AbaqusINP *.inp 

當我嘗試手動創建標籤文件時,我會針對每個找到關鍵字的行獲取以下警告。

$ ctags example.inp 
ctags: Warning: example.inp:8: null expansion of name pattern "\1" 
ctags: Warning: example.inp:9: null expansion of name pattern "\1" 
ctags: Warning: example.inp:14: null expansion of name pattern "\1" 

標籤文件已創建,但僅填充了默認標頭。

!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/ 
!_TAG_PROGRAM_NAME Exuberant Ctags // 
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 
!_TAG_PROGRAM_VERSION 5.8 // 

上的ctags爲什麼不創造tagbar使用標籤有什麼想法?謝謝你的幫助。



更新:明確所需的正則表達式。

我想要部分名稱和關鍵字分配標籤。我在vim中嘗試了這些模式,他們似乎正確地工作。

例如。INP文件上面我想正則表達式部分返回:

  • 第一個命名爲
  • 節名稱的兩個

    section_regex = ^\*\*\*[\*]+\n\*\*[ \tA-Za-z]+


對於example.inp文件上面我想要返回關鍵字的正則表達式:

  • 關鍵字1
  • KEYWORD2
  • KEYWORD3

keyword_regex = ^\*[A-Za-z]+

+1

隨機的想法:儘量避免多行模式 – Vitor

+0

你能告訴我們你想要用你的正則表達式匹配和捕獲什麼嗎?此外,您沒有「分區」模式中的組,因此ctags將很難提取第三個分組。 – romainl

回答

0

根據this ctags的不支持多線路的正則表達式。

越接近解決方案,我能拿是:

--langdef=AbaqusINP 
--langmap=AbaqusINP:.inp 
--regex-AbaqusINP=/^\*\*([ \tA-Za-z0-9]+)/\1/s,Section/ 
--regex-AbaqusINP=/^\*([A-Za-z0-9]+)/\1/k,Keyword/ 

考慮到的是,在替換表達\1指的是在比賽中表現羣體,所以括號是圍繞感興趣的關鍵字必要的。這就是你收到這些警告的原因。 我也修復了關鍵字正則表達式以允許包含數字。上述

配置將返回下面的標籤爲您發佈的例子:

Analyst test.inp /^** Analyst:$/;" s 
Comments test.inp /^** Comments$/;" s 
KEYWORD2 test.inp /^*KEYWORD2$/;" k 
Keyword1 test.inp /^*Keyword1$/;" k 
More comments test.inp /^** More comments$/;" s 
Section Name One test.inp /^** Section Name One$/;" s 
Section Name Two test.inp /^** Section Name Two$/;" s 

這仍返回的意見,這是不可取的。 但是從我能收集的內容來看,你使用的是正常的註釋來定義段,所以我猜這個格式不是固定的。如果這是真的,一個可能的解決辦法是:

--langdef=AbaqusINP 
--langmap=AbaqusINP:.inp 
--regex-AbaqusINP=/^\*\* *(Section +[ \tA-Za-z0-9]+)/\1/s,Section/ 
--regex-AbaqusINP=/^\*([A-Za-z0-9]+)/\1/k,Keyword/ 

雖然它要求所有章節開始與關鍵字「節」,它會回報你在找什麼:

KEYWORD2 test.inp /^*KEYWORD2$/;" k 
Keyword1 test.inp /^*Keyword1$/;" k 
Section Name One test.inp /^** Section Name One$/;" s 
Section Name Two test.inp /^** Section Name Two$/;" s