<html lang="en">
<head>
<title>Completion - PHP Mode Manual</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="PHP Mode Manual">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="Editing.html#Editing" title="Editing">
<link rel="next" href="PHP-Comments.html#PHP-Comments" title="PHP Comments">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This manual documents PHP mode version 1.5.0 for
use with GNU Emacs.
Copyright (C) 2008 Aaron S. Hawley
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.2 or any later version published by the Free Software
Foundation; with no Invariant Sections, and no Cover Texts. A
copy of the license is included in the section entitled ``Copying
This Manual.''
A copy of the license is also available from the Free Software
Foundation Web site at `http://www.gnu.org/licenses/fdl.html'.
The document was typeset with
GNU Texinfo (http://www.texinfo.org/).
$Date: 2008-11-04 11:51:51 -0500 (Tue, 04 Nov 2008) $
$Revision: 90 $
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Completion"></a>
Next: <a rel="next" accesskey="n" href="PHP-Comments.html#PHP-Comments">PHP Comments</a>,
Previous: <a rel="previous" accesskey="p" href="Editing.html#Editing">Editing</a>,
Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">7 Completion</h2>
<p><a name="index-completion-177"></a>Completing function names, identifiers and PHP keywords is
possible in PHP mode. In PHP mode, it is possible to
complete identifiers defined by the PHP programming
language, and to complete functions defined by you.
<p><a name="index-customization_002c-PHP-manual-path-178"></a><a name="index-PHP-manual-path-179"></a><a name="index-php_002dmanual_002dpath-180"></a><a name="index-g_t_002eemacs_002c-php_002dmanual_002dpath-181"></a><a name="index-customize_002dvariable-182"></a><a name="index-M_002dx-customize_002dvariable-183"></a>For PHP mode to know the functions of keywords of PHP, it
must have access to the PHP manual. Download the HTML
archive of the manual made of separate files for each
function.<a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a>
Unpack the files to a directory, and define the variable
<code>php-manual-path</code> to the location of these files.
Configure this setting with either <kbd>M-x
customize-variable RET php-manual-path RET</kbd>, or by setting
its value in your Emacs initialization file
(<samp><span class="file">~/.emacs</span></samp>).
<!-- FIXME: Explain how the function name completion works, as -->
<!-- much as the user would need to know. -->
<!-- The following explains how to get completion to work in -->
<!-- detail, with any expectation that the reader knows how -->
<!-- completion works in Emacs. The more opportunities to -->
<!-- share features that come with Emacs as they apply to PHP -->
<!-- development, the better. -->
<p><a name="index-etags-184"></a><a name="index-tag-file-185"></a><a name="index-Makefile-186"></a>For functions and classes you define, you'll need to provide
them to Emacs as a <dfn>tag file</dfn>.<a rel="footnote" href="#fn-2" name="fnd-2"><sup>2</sup></a> Creating a
tag file (<samp><span class="file">TAGS</span></samp>) from a PHP source code file is done
by running the <samp><span class="command">etags</span></samp> command on the
file.<a rel="footnote" href="#fn-3" name="fnd-3"><sup>3</sup></a> The
<samp><span class="command">etags</span></samp> command can even generate tag files for
providing completion across multiple files. For larger
projects and PHP coded libraries, use a system like a
Makefile to generate and maintain the tag tables.
<p><a name="index-etags_002c-running-187"></a>Run,
<pre class="example"> etags <var>file</var>
</pre>
<p>to create a <samp><span class="file">TAGS</span></samp> file for <var>file</var>.
<p>To generate a <samp><span class="file">TAGS</span></samp> file for all the PHP files in the
current directory, run
<pre class="example"> etags *.php
</pre>
<p>To enable a tags file you need to use the following command.
<a name="index-tag-188"></a>
<a name="index-visit_002dtags_002dtable-189"></a>
<a name="index-M_002dx-visit_002dtags_002dtable-190"></a>
<dl><dt><kbd>C-u M-x visit-tags-table</kbd><dd>Specify the <samp><span class="file">TAGS</span></samp> file that PHP mode should use to
find completion candidates for the current buffer.
<br><dt><kbd>M-x visit-tags-table</kbd><dd>Specify the <samp><span class="file">TAGS</span></samp> file that PHP mode should use to
find completion candidates for all buffers, and even other
modes other than PHP mode.
</dl>
<p><a name="index-customization_002c-PHP-completion-file-191"></a><a name="index-PHP-completion-file-192"></a><a name="index-php_002dcompletion_002dfile-193"></a><a name="index-g_t_002eemacs_002c-php_002dcompletion_002dfile-194"></a>If you are interested in any one or more of the following
consider using the variable <code>php-completion-file</code>.
<ol type=1 start=1>
<li>avoid regenerating the completion table from the PHP manual
every Emacs session,
<li>generating a completion file from a facility external to
Emacs tags,
<li>or provide more granular control over the completion
rules for files;
</ol>
<p><a name="index-customize_002dvariable-195"></a><a name="index-M_002dx-customize_002dvariable-196"></a>Configure this setting with either <kbd>M-x
customize-variable RET php-completion-file RET</kbd>, or by
setting its value in your Emacs initialization file
(<samp><span class="file">~/.emacs</span></samp>).
<p>To create a file that can be set for
<code>php-completion-file</code>, create with the following shell
commands with the HTML version of the PHP manual installed
at <samp><span class="file">/usr/share/doc/php-manual/en/html</span></samp>.
<pre class="example"> $ cd /usr/share/doc/php-manual/en/html
$ ls -1 function*.html \
| sed -e 's/^function\.\([-a-zA-Z_0-9]*\)\.html/\1/' \
| tr - _ \
> ~/.emacs.d/php/php-completion-file
</pre>
<!-- PHP mode could ship with a php-completion-file, but that -->
<!-- could require releasing a new version of PHP mode -->
<!-- whenever significant changes occur to the API of PHP. -->
<!-- Keep the following notes on third-party packages updated -->
<!-- with respect to managing Emacs settings on a per-project -->
<!-- basis. Otherwise, delete the paragraph(s). Perhaps the -->
<!-- Emacs project will choose or develop a solution, soon. -->
<p>In larger projects or with other specific needs,
conventional methods of setting these and other variables
may be inadequate. As of 2008, third-party packages do
exist for Emacs to configure Emacs settings on groups of
files or for directory trees, including <samp><span class="file">dirvars.el</span></samp>.
<a name="index-complete-function-197"></a>
<a name="index-function_002c-complete-198"></a>
<a name="index-php_002dcomplete_002dfunction-199"></a>
<a name="index-M_002dTAB-200"></a>
<a name="index-ESC-TAB-201"></a>
<a name="index-C_002d_005b-TAB-202"></a>
<dl><dt><kbd>M-TAB</kbd><br><dt><kbd>ESC TAB</kbd><br><dt><kbd>C-[ TAB</kbd><dd>Complete function name at point
(<code>php-complete-function</code>).
<a name="index-argument-list_002c-function-203"></a><a name="index-function-argument-list-204"></a><a name="index-minibuffer-205"></a><a name="index-php_002dshow_002darglist-206"></a><a name="index-C_002d_002e-207"></a><br><dt><kbd>C-.</kbd><dd>Show in the minibuffer the argument list for the current
function at point (<code>php-show-arglist</code>). The argument
list is generated by finding and jumping to the respective
function's location specified in the tag file (see above).
The argument list is then read and printed to the
minibuffer.
</dl>
<div class="footnote">
<hr>
<h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> <a href="http://www.php.net/download-docs.php">http://www.php.net/download-docs.php</a></p>
<p class="footnote"><small>[<a name="fn-2" href="#fnd-2">2</a>]</small> See <a href="http://emacswiki.org/cgi-bin/info-ref?find=Tags.html#Tags">Tags Tables</a>.</p>
<p class="footnote"><small>[<a name="fn-3" href="#fnd-3">3</a>]</small> See <a href="http://emacswiki.org/cgi-bin/info-ref?find=Create-Tags-Table.html#Create-Tags-Table">Creating Tags Tables</a>.</p>
<hr></div>
</body></html>