Match on full filename in Textmate bundle fileTypes section - textmatebundles

I want to modify the existing Textmate Groovy bundle so that it can be used for my Jenkinsfile files.
In Syntaxes/Groovy.tmLanguage, there is the fileTypes section:
<key>fileTypes</key>
<array>
<string>groovy</string>
<string>gvy</string>
</array>
However, these are file extensions, not file names, as the reference doc I've found says:
fileTypes (line 2) — this is an array of file type extensions that the grammar should (by default) be used with.
How can I make the bundle match on full filename for my Jenkinsfile?

It turns out that full filenames are actually supported in the fileTypes section, despite what the doc said (possibly because that doc is from version 1). There's an example of a match on Rakefile here.
Therefore, I could just do this:
<array>
<string>groovy</string>
<string>gvy</string>
<string>Jenkinsfile</string>
</array>

Related

Vim c++ indexing that differentiates between symbols with same names

I've been trying out vim with exuberant tags and cscope but when listing the usages of a variable it also lists variables with the same name that aren't really the symbol I'm looking at. For example if I want to jump to the declaration or other usages of a variable called "temp", it will give me all variables called "temp" in the whole repo. Am I using tags and cscope wrong or is there another plugin I should be using instead?
Ctags and cscope use parsers and even regular expressions to find symbols in files. They "understand" syntax, in a way, but they don't understand code so they have no idea about what specific function is called where.
Consequently…
that relationship is not encoded in the resulting database,
and it is lost to any program using ctags or cscope.
If you want a tool that knows exactly which temp is referenced, then you don't want csope or ctags. You want something based on a compiler, like clang.

How to create a centralized syntax file that be able to recognize multiple parts with different syntaxes?

For i.e: I'd like to have a custom syntax file, may be called sugar.vim that includes multiple other syntax files(?) to have the ability to highlight, maybe a paragraph as python.vim and another paragraph as javascript.vim, may be separated by newline (paragraphs often distinct by newline)
The real case that I often catch myself writing a document (non-extension file) other than real config a specific filetype (specific extension file), but for clear readability in the document filetype (we called sugar above). I'm thinking about a mechanism to recognize and highlight different parts of a filetype as different syntaxes.
To narrow down this case. How would it be to have a syntax file called sugar.vim that would be able to recognize python syntax and javascript syntax in files that have an extension of .sugar then the recognized python text should have highlights applied as a normal python file, same for javascript part. All recognized text must be separated by newline (at least one before and one after that text)
Sample:
# this is a sample text for this question
# i'm writing a document that has an extension of `.sugar`
def py_func1(arg1, arg2) # python.vim and its highlights applied here.
print("bello world!")
square = function(x) { # javascript.vim and its highlights applied here.
return x * x;
};
System: gvim 8.1 / windows10
Thanks in advances.
Vim supports that with the :help :syn-include command. As it's intended for syntax script writers leveraging other syntaxes, its use is somewhat complicated, and it's not really suited for interactive, on-demand use.
My SyntaxRange plugin provides commands and functions to set up regions in the current buffer that either use a syntax different from the buffer's 'filetype', or completely ignore the syntax. With it, it's trivial to dynamically add a particular syntax highlighting for a range of lines, and public API functions also make the programmatic definition easier.
You're looking for :help :syn-include.
Excerpt from vim help :
If top-level syntax items in the included syntax file are to be
contained within a region in the including syntax, you can use the
":syntax include" command:
:sy[ntax] include [#{grouplist-name}] {file-name}
All syntax items declared in the included file will have the
"contained" flag added. In addition, if a group list is specified,
all top-level syntax items in the included file will be added to
that list. >
" In perl.vim:
:syntax include #Pod :p:h/pod.vim
:syntax region perlPOD start="^=head" end="^=cut" contains=#Pod
When {file-name} is an absolute path (starts with "/", "c:", "$VAR"
or "") that file is sourced. When it is a relative path
(e.g., "syntax/pod.vim") the file is searched for in 'runtimepath'.
All matching files are loaded. Using a relative path is
recommended, because it allows a user to replace the included file
with his own version, without replacing the file that does the ":syn
include".
As long as you can clearly define boundaries for your embedded language regions it is fairly straight forward to achieve this.
You can also refer to https://github.com/tpope/vim-markdown/blob/master/syntax/markdown.vim for reference on how tpope embeds other syntax definitions within the markdown syntax, driven by configuration to minimise the number of language syntax's that need embedding for optimal performance.

In Vim how to know if function is defined

I am using Vim editor v7.4 .
I have a huge C Code library , and i make constant changes to it.
Is there a way ( before compilation) to know if a function i am adding to some file is defined for this file.
Thanks
I'm not sure to correctly understand your need. In my definition, when I add a function to a file, I add its definition, so it's defined. But when I'm using a function in a file, I only need its declaration. Then there is also the problem of being sure that a function defined in a translation unit is declared somewhere (privately in the same TU as a static function, or in a header file).
For the latter, I have a solution (that checks functions definitions and declarations are balanced in lh-cpp). For the case of being sure a function is declared in the UT it's used, it won't be that simple: we need to do the preprocessor work (and recursively follow includes) and search whether a function is indeed declared. It's not impossible, but it's best to have vim know the paths where header files are in order to look for them.
Look at a tool like exuberant ctags. It parses C-style files to find any identifier and store them in a tag file, so that each of them can be accessed quickly, inside Vim for example.
Once installed, in the shell command line, you have to create a tag file with this kind of command:
$ ctags *.c *.h
This will create an new file called tags, where all the c files and header files in the current directory are parsed. Please note that there are many options for this tool (like recursively include all lib headers, which can lead to a huge file, though), you may look at the doc for more details.
Once done, in Vim, there are several commands to use transparently the infos in this file. First check your current directory is the same as the tag file; then, to check if an identifier (like a function name) is already present in the tag file, you can use:
:ts myFunctionName
I don't think tag is a good enough solution to check whether function is defined. The flexibility of C syntax make it worse, because most tag tool is syntax-based other than semantics-based.
For example, at present, the most powerful code-completion plug-in for vim is
YouCompleteMe, which is semantic-based by virtue of Clang.
So IMHO, the answer to your question is: compile it!
In order to do compiling more convenience, you can add the following configuration in your .vimrc.
map <F6> :make install<CR>
After this, when you press F6, compiler will be launched to check your code.

Why is vim -t ctags not enough? I cannot jump to the function I want

ctags -R dirName, vim -t tags is very powerful, since after these two commands, you can now have the ability to navigate between code of that project, for example you can just jump to the code of certain function using :tag functionName, but this operation still have some pitfalls, as is usual case that one source code could include some function calls such as va_start(), while this code is not included in the dirName directory, so indexs are not generated for this function, and you cannot navigate to the definition of va_start(), but it is needed to navigate to this function? how to find that code? i don't even know where va_start() is defined exactly. How do I generate ctags index for the system functions or function of third party?
When you are using "ctags -R dirName" you are only indexing symbols for the content of the directory dirName.
What happens there is that "va_args" is defined in stdarg.h which is a header of the C standard library.
You'll encounter the same issue every time you'll be using a symbol from an external library.
So if you want to have all symbols available, you have, in addition to your program , to also index the code for external libraries.
It means :
The source code should be available (which is not always the case)
Once you have found on your system where the file is, it should be parsed to be included in your "tag" file.
So once you have executed ctags -R projectPath you can execute ctags -Ra /usr/include to append all the content of /usr/include to your tag file.
More generally you want to do something like ctags -Ra librarySourcePath to get all symbols used in your program available.
Edit :
Be careful however : /usr/include might include lots of file, so the size of you tag file can greatly increase, and as consequence, every time you'll search for a symbol to jump to it, it could be much slower !

Create tags file for latex for labels and bib items

I'm using ctags to create a tags file for use in Vim, so that I can jump to definitions of labels and citations. However, I have two problems:
ctags includes \ref in the tags file, so when I hit jump on a \ref label, I don't necessarily jump to the definition of the label, but might end up on another reference to that label.
I'd like to be able to jump to the corresponding entry in a .bib file from a \cite command, but ctags doesn't generate entries for that (I'm using ctags *.tex *.bib).
I wanted to redefine ctags's definition for tex files, so that I could remove \ref entries, but that didn't work.
My ~/.ctags file:
--langdef=tex2
--langmap=tex2:.tex
--regex-tex2=/\\label[ \t]*\*?\{[ \t]*([^}]*)\}/\1/l,label/
I realized that I didn't use exuberant ctags, but another ctags program, so the content in ~/.ctags was never used.
I also managed to add another entry in ~/.ctags for bib entries:
--langdef=tex2
--langmap=tex2:.tex
--regex-tex2=/\\label[ \t]*\*?\{[ \t]*([^}]*)\}/\1/l,label/
--langdef=bib
--langmap=bib:.bib
--regex-bib=/^#[A-Za-z]+\{([^,]*)/\1/b,bib/
ctags *.tex *.bib works now as I want it.
You can put a regex into an online regex explainer to understand what it is doing, like https://regexr.com/.

Resources