Note: You are currently viewing documentation for Moodle 2.6. Up-to-date documentation for the latest stable version of Moodle may be available here: ctags.

Development:ctags: Difference between revisions

From MoodleDocs
(tags for emacs)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Moodle 1.9.5 and older ==
The root directory of the Moodle CVS distribution contains a file called '''tags'''. This contains information about the location of symbols throughout the moodle code. An editor can make use of this to automatically jump to the place where a function is defined.
The root directory of the Moodle CVS distribution contains a file called '''tags'''. This contains information about the location of symbols throughout the moodle code. An editor can make use of this to automatically jump to the place where a function is defined.
== Moodle 1.9.6 and newer ==
As of Moodle 1.9.6 the tags file is no longer included in the Moodle distribution. Instead a file tags.txt is included providing instructions on creating the tag file yourself. The text of this file is as follows:
<pre>
Generating a tags file
======================
If you need a tags file so that you can jump around Moodle code
easily in your editor (eg vim or emacs), you can generate one:
Exuberant ctags (default on Linux, can be compiled on other platforms):
----------------------------------------------------------------------
ctags -R --languages=php --exclude="CVS" --php-kinds=f \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'
Downloading the tags file
=========================
If for some reason you can't generate one, you can download a recent one from here:
http://download.moodle.org/tags            (for head)
http://download.moodle.org/stable19/tags  (Moodle 1.9.x)
http://download.moodle.org/stable18/tags  (Moodle 1.8.x)
</pre>


== Using tags with Vim ==
== Using tags with Vim ==
Line 5: Line 35:
In order to use the tags file with the Vim editor (on a Unix style system), you should first add the following line to the file '''.vimrc''' in your home directory:
In order to use the tags file with the Vim editor (on a Unix style system), you should first add the following line to the file '''.vimrc''' in your home directory:


     set tags = tags;/
     set tags=tags;/


If .vimrc does not exist you should create it. This directive will force Vim to search for the tags file in the directory tree in which you are working (it searched up from where you are) so it will work for multiple versions of the code automatically.
If .vimrc does not exist you should create it. This directive will force Vim to search for the tags file in the directory tree in which you are working (it searches up from where you are) so it will work for multiple versions of the code automatically.


=== How to jump to a tag with Vim ===
=== How to jump to a tag with Vim ===
Line 13: Line 43:
There are a number of things you can do:
There are a number of things you can do:


* Place the cursor over the tag (e.g., function name) and press '''CTRL+]'''
* Place the cursor over the tag (e.g., function name) and press '''CTRL+]'''.
* Type the command ''':tag <tagname>'''
* Type the command ''':tag <tagname>'''
* To open in a new editor window type the command ''':stag <tagname>'''
* To open in a new editor window type the command ''':stag <tagname>'''
* To return to your previous location type '''CTRL+t'''
* To return to your previous location type '''CTRL+t'''


=== Generating the tags file ===
== Using tags with Emacs ==
 
To create the TAGS file add a -e to the command of tags.txt, like this:
If you need to generate your own tags file (perhaps because you are working on optional modules), from the Moodle root directory issue the command:
<pre>
 
ctags -e -R --languages=php --exclude="CVS" --php-kinds=f \
    find  . -name "*.php" | xargs ctags
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'
</pre>


The file should be of the order of 1MB in size.
For instructions about how to use it look to the emacs wiki page [http://www.emacswiki.org/emacs/EmacsTags EmacsTags]


==See also==
==See also==


* [[http://www.vim.org/tips/tip.php?tip_id=94 Vim tags usage tip]]
* [http://www.vim.org/tips/tip.php?tip_id=94 Vim tags usage tip]
* [http://vimdoc.sourceforge.net/htmldoc/usr_29.html#29.1 Vim documentation: Using tags]
* [http://vimdoc.sourceforge.net/htmldoc/tagsrch.html Vim documentation: Tags and special searches]


[[Category:Developer|Ctags]]
[[Category:Developer|Ctags]]

Latest revision as of 15:04, 11 August 2010

Moodle 1.9.5 and older

The root directory of the Moodle CVS distribution contains a file called tags. This contains information about the location of symbols throughout the moodle code. An editor can make use of this to automatically jump to the place where a function is defined.

Moodle 1.9.6 and newer

As of Moodle 1.9.6 the tags file is no longer included in the Moodle distribution. Instead a file tags.txt is included providing instructions on creating the tag file yourself. The text of this file is as follows:

Generating a tags file
======================

If you need a tags file so that you can jump around Moodle code
easily in your editor (eg vim or emacs), you can generate one:

Exuberant ctags (default on Linux, can be compiled on other platforms):
----------------------------------------------------------------------

ctags -R --languages=php --exclude="CVS" --php-kinds=f \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'


Downloading the tags file
=========================

If for some reason you can't generate one, you can download a recent one from here:

http://download.moodle.org/tags            (for head)
http://download.moodle.org/stable19/tags   (Moodle 1.9.x)
http://download.moodle.org/stable18/tags   (Moodle 1.8.x)

Using tags with Vim

In order to use the tags file with the Vim editor (on a Unix style system), you should first add the following line to the file .vimrc in your home directory:

   set tags=tags;/

If .vimrc does not exist you should create it. This directive will force Vim to search for the tags file in the directory tree in which you are working (it searches up from where you are) so it will work for multiple versions of the code automatically.

How to jump to a tag with Vim

There are a number of things you can do:

  • Place the cursor over the tag (e.g., function name) and press CTRL+].
  • Type the command :tag <tagname>
  • To open in a new editor window type the command :stag <tagname>
  • To return to your previous location type CTRL+t

Using tags with Emacs

To create the TAGS file add a -e to the command of tags.txt, like this:

ctags -e -R --languages=php --exclude="CVS" --php-kinds=f \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'

For instructions about how to use it look to the emacs wiki page EmacsTags

See also