Skip to content

Commit

Permalink
Dynamic highlighting for Ruby source code (issue #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed May 23, 2011
1 parent f980d5d commit 45e97ff
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ There's just one problem: You have to manually keep your tags files up-to-date a

Unzip the most recent [ZIP archive](http://peterodding.com/code/vim/downloads/easytags.zip) file inside your Vim profile directory (usually this is `~/.vim` on UNIX and `%USERPROFILE%\vimfiles` on Windows), restart Vim and execute the command `:helptags ~/.vim/doc` (use `:helptags ~\vimfiles\doc` instead on Windows). Now try it out: Edit any file type supported by Exuberant Ctags and within ten seconds the plug-in should create/update your tags file (`~/.vimtags` on UNIX, `~/_vimtags` on Windows) with the tags defined in the file you just edited! This means that whatever file you're editing in Vim (as long as it's on the local file system), tags will always be available by the time you need them!

Additionally if the file you just opened is a C, C++, Objective-C, Java, Lua, Python, PHP or Vim source file you should also notice that the function and type names defined in the file have been syntax highlighted.
Additionally if the file you just opened is a C, C++, Objective-C, Java, Lua, Python, PHP, Ruby or Vim source file you should also notice that the function and type names defined in the file have been syntax highlighted.

The `easytags.vim` plug-in is intended to work automatically once it's installed, but if you want to change how it works there are several options you can change and commands you can execute from your own mappings and/or automatic commands. These are all documented below.

Expand Down Expand Up @@ -127,6 +127,7 @@ The easytags plug-in defines new highlighting groups for dynamically highlighted
* **Python:** `pythonFunctionTag`, `pythonMethodTag`, `pythonClassTag`
* **Java:** `javaClassTag`, `javaMethodTag`
* **C#:** `csClassOrStructTag`, `csMethodTag`
* **Ruby:** `rubyModuleNameTag`, `rubyClassNameTag`, `rubyMethodNameTag`

As you can see each of these names ends in `Tag` to avoid conflicts with the syntax modes shipped with Vim. And about the singular/plural confusion: I've tried to match the existing highlighting groups defined by popular syntax modes (except of course for the `Tag` suffix).

Expand Down
23 changes: 22 additions & 1 deletion autoload/xolox/easytags.vim
@@ -1,6 +1,6 @@
" Vim script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: May 6, 2011
" Last Change: May 23, 2011
" URL: http://peterodding.com/code/vim/easytags/

let s:script = expand('<sfile>:p:~')
Expand Down Expand Up @@ -628,6 +628,27 @@ call xolox#easytags#define_tagkind({
highlight def link csClass Identifier
highlight def link csMethod Function

" Ruby. {{{2

call xolox#easytags#define_tagkind({
\ 'filetype': 'ruby',
\ 'hlgroup': 'rubyModuleName',
\ 'filter': 'get(v:val, "kind") ==# "m"'})

call xolox#easytags#define_tagkind({
\ 'filetype': 'ruby',
\ 'hlgroup': 'rubyClassName',
\ 'filter': 'get(v:val, "kind") ==# "c"'})

call xolox#easytags#define_tagkind({
\ 'filetype': 'ruby',
\ 'hlgroup': 'rubyMethodName',
\ 'filter': 'get(v:val, "kind") =~# "[fF]"'})

highlight def link rubyModuleName Type
highlight def link rubyClassName Type
highlight def link rubyMethodName Function

" }}}

" Restore "cpoptions".
Expand Down
6 changes: 4 additions & 2 deletions doc/easytags.txt
Expand Up @@ -36,8 +36,8 @@ file you're editing in Vim (as long as it's on the local file system), tags
will always be available by the time you need them!

Additionally if the file you just opened is a C, C++, Objective-C, Java, Lua,
Python, PHP or Vim source file you should also notice that the function and
type names defined in the file have been syntax highlighted.
Python, PHP, Ruby or Vim source file you should also notice that the function
and type names defined in the file have been syntax highlighted.

The 'easytags.vim' plug-in is intended to work automatically once it's
installed, but if you want to change how it works there are several options
Expand Down Expand Up @@ -269,6 +269,8 @@ by the easytags plug-in:

- C#: 'csClassOrStructTag', 'csMethodTag'

- Ruby: 'rubyModuleNameTag', 'rubyClassNameTag', 'rubyMethodNameTag'

As you can see each of these names ends in 'Tag' to avoid conflicts with the
syntax modes shipped with Vim. And about the singular/plural confusion: I've
tried to match the existing highlighting groups defined by popular syntax
Expand Down
4 changes: 2 additions & 2 deletions plugin/easytags.vim
@@ -1,10 +1,10 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
" Last Change: May 2, 2011
" Last Change: May 23, 2011
" URL: http://peterodding.com/code/vim/easytags/
" Requires: Exuberant Ctags (http://ctags.sf.net)
" License: MIT
" Version: 2.2.7
" Version: 2.2.8

" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip
Expand Down

0 comments on commit 45e97ff

Please sign in to comment.