PHP Manual in VIM
網路上提供的tags都太舊了,所以就自已動手產生吧!我今天在FreeBSD上做了一遍,現在用Mac寫文章,所以這邊就以Mac的環境說一下流程,我不太清楚Mac OS X Server和XCode預設裝了哪些東西,所以我把環境列上來提供參考:
操作環境Mac OS X Server v10.6.7
XCode 4.0.2
PHP 5.3.4
一、安裝PEAR
Mac OS X Server出廠就有LAMP stack的環境了,但PHP沒編—with-pear,所以要自已裝,基本上是照著pear官網的文件,但我沒有加_-d detect_unicode=0。_
$ curl http://pear.php.net/go-pear.phar > go-pear.phar
$ sudo php -q go-pear.phar
Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type ‘all’ to change all of them or simply press Enter to
accept these locations.
1. Installation base ($prefix) : /usr/local
2. Temporary directory for processing : /tmp/pear/install
3. Temporary directory for downloads : /tmp/pear/install
4. Binaries directory : /usr/local/bin
5. PHP code directory ($php_dir) : /usr/local/share/pear
6. Documentation directory : /usr/local/docs
7. Data directory : /usr/local/data
8. User-modifiable configuration files directory : /usr/local/cfg
9. Public Web Files directory : /usr/local/www
10. Tests directory : /usr/local/tests
11. Name of configuration file : /Users/gasol/.pearrc
1-11, ‘all’ or Enter to continue:預設會裝在個人的home目錄,這邊我把prefix改成/usr/local,如果是裝在別的地方,注意一下PATH要找的到pear,最後會詢問是否要在php.ini把pear的路徑加在include_path。
裝完再用pear裝待會兒會用到的PhD和XML_Parser
$ sudo pear install doc.php.net/phd_php
Did not download optional dependencies: phpdocs/PhD_PEAR, phpdocs/PhD_IDE, use —alldeps to download automatically
phpdocs/PhD_PHP can optionally use PHP extension “haru”
phpdocs/PhD can optionally use package “phpdocs/PhD_PEAR”
phpdocs/PhD can optionally use package “phpdocs/PhD_IDE”
phpdocs/PhD can optionally use PHP extension “haru”
phpdocs/PhD_Generic can optionally use PHP extension “haru”
downloading PhD_PHP-1.1.0.tgz …
Starting to download PhD_PHP-1.1.0.tgz (24,067 bytes)
……..done: 24,067 bytes
downloading PhD-1.1.0.tgz …
Starting to download PhD-1.1.0.tgz (42,303 bytes)
…done: 42,303 bytes
downloading PhD_Generic-1.1.0.tgz …
Starting to download PhD_Generic-1.1.0.tgz (28,104 bytes)
…done: 28,104 bytes
install ok: channel://doc.php.net/PhD_Generic-1.1.0
install ok: channel://doc.php.net/PhD-1.1.0
install ok: channel://doc.php.net/PhD_PHP-1.1.0
$ sudo pear install XML_Parser
downloading XML_Parser-1.3.4.tgz …
Starting to download XML_Parser-1.3.4.tgz (16,040 bytes)
……done: 16,040 bytes
install ok: channel://pear.php.net/XML_Parser-1.3.4
詳細安裝方式可以參考 https://wiki.php.net/doc/phd/install。
二、從SVN Repository產生PHP Documentation.
svn co http://svn.php.net/repository/phpdoc/modules/doc-en phpdoc
… ignore …
A phpdoc/en/features/figures/simple-array.png
A phpdoc/en/features/figures/simple-array2.png
A phpdoc/en/features/figures/leak-array.png
A phpdoc/en/features/commandline.xml
A phpdoc/en/features/sessions.xml
A phpdoc/en/features/gc.xml
A phpdoc/en/features/remote-files.xml
A phpdoc/en/features/cookies.xml
A phpdoc/en/features/http-auth.xml
A phpdoc/en/features/xforms.xml
U phpdoc/en
Checked out external at revision 311445.
Checked out revision 311445.
會clone一堆xml下來,接著執行./build.sh
$ cd phpdoc
phpdoc/ $ ./build.sh
configure.php: $Id: configure.php 310808 2011-05-06 16:11:39Z bjori $
PHP version: 5.3.4
LibXML 2.7.4+ added a ‘feature’ to break things, typically namespace related, and unfortunately we must require it.
For a few related details, see: http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg777646.html
Please recompile PHP with a LibXML version 2.7.4 or greater. Version detected: 2.7.3
Or, pass in —disable-libxml-check if doing so feels safe.
Checking for source directory… /Users/gasol/tmp/phpdoc/doc-base
Checking for output filename… /Users/gasol/tmp/phpdoc/doc-base/.manual.xml
Checking whether to include CHM… no
Checking for PHP executable… /usr/bin/php
Checking for language to build… en
Checking whether the language is supported… yes
Checking for partial build… no
Checking whether to enable detailed XML error messages… yes
Checking libxml version… 2.7.3
Checking whether to enable detailed error reporting (may segfault)… yes
Checking whether to optimize out the DTD (performance gain, but segfaults)… yes
Generating /Users/gasol/tmp/phpdoc/doc-base/manual.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/install-unix.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/install-win.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/developer.template.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/entities/version.ent… done
Generating /Users/gasol/tmp/phpdoc/doc-base/scripts/file-entities.php… done
Iterating over extension specific version files… OK
Saving it… OK
Creating file /Users/gasol/tmp/phpdoc/doc-base/entities/file-entities.ent… done
Checking for if we should generate a simplified file… no
Checking whether to save an invalid .manual.xml… no
Loading and parsing manual.xml… done.
Validating manual.xml… done.
All good. Saving .manual.xml… done.
All you have to do now is run ‘phd -d /Users/gasol/tmp/phpdoc/doc-base/.manual.xml’
If the script hangs here, you can abort with ^C.
(Run `nice php configure.php` next time!)
PHP will segfault now :) - Don’t worry though, the .manual.xml has been saved :D
[23:42:04 - Heads up ] Creating output directory..
[23:42:04 - Indexing ] Indexing…
[23:44:02 - Indexing ] Indexing done
[23:44:02 - Rendering Style ] Running full build
[23:44:03 - Rendering Format ] Starting PHP-Chunked-XHTML rendering
[23:46:30 - Rendering Format ] Writing search indexes..
[23:46:30 - Rendering Format ] Index written
[23:46:30 - Rendering Format ] Finished rendering
結束後就可以看到日期是今天最新的PHP Documentation.
到作者的網頁下載Parser,這隻script年代有點久遠,所以我加了點料 patch讓它可以順利執行
在phpdoc的上一層目錄執行parser2.php
$ curl http://blog.planetxml.de/uploads/source/php/phpdoc/parser2.php.txt > parser2.php
$ patch -p1 pathogen的話要把pathogen#helptags()拿掉,它會自動執行helptags把tags檔覆蓋過去,我個人是用pathogen擺在$HOME/.vim/bundle/phpdoc/doc底下,接著在.vimrc加上一行autocmd BufNewFile,BufRead *.php set keywordprg=”help”就大功告成了!
最後,開一個php檔到處在funciton按K測試看看吧,在沒有雙瑩幕的環境,用這方法看manual可以結省不少切換視窗的時間,helptags的應用可以參考李果正 - 大家來學VIM 12.5.2節。 http://dlvr.it/T67ZV





