星期五, 十一月 11, 2011

Sublime Text 2:编辑器新秀


主页:http://www.sublimetext.com

跨平台:windows / Linux / Mac OS

插件采用python语言开发,目前主程序和插件开发进展很快,目前已经足以作为一个强大的脚本开发 / Web开发 IDE 。

插件包控制 Sublime Package Control

按Ctrl+` 启动Sublime Text 2 console,输入如下回车安装package manager

import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())

推荐插件

python类

1. 代码导航


I) Sublime Code Intel 插件提供代码补全与函数跳转功能。

    Code intelligence plugin ported from Open Komodo Editor to the Sublime Text 2 editor.

    Supports all the languages Komodo Editor supports for Code Intelligence (CIX, CodeIntel2): PHP, Python, RHTML, JavaScript, Smarty, Mason, Node.js, XBL, Tcl, HTML, HTML5, TemplateToolkit, XUL, Django, Perl, Ruby, Python3.

II)SublimeRope: Python Completion and GotoDefinition plugin using Rope


2. 代码检查 Python PEP-8 and PyFlakes checker


 
I) SublimeLinter

II) sublimetext_python_checker

This project is a plugin for SublimeText 2 text editor. It checks all python files you opening and editing through two popular Python checkers - pep8 and PyFlakes.

https://github.com/vorushin/sublimetext_python_checker

代码中使用个某个函数却忘记import 相应模块怎么办?python 中的模块 mr.igor 可以自动添加 import 语句。这个 Sublime Text 2 插件可以让它在 Sublime Text 2 工作。

Package Control Add URL https://github.com/optilude/SublimeTextIgorPlugi


Ruby

https://github.com/maltize/sublime-text-2-ruby-tests

https://github.com/SublimeText/RSpec

Sublime Guard

C/C++

CTags/Cscope 经典

clang (C/C++/Objective-C/Objective-C++) autocomplete http://github.com/quarnster/SublimeClang


Web Dev

Zen Coding

    Zen Coding is an editor plugin for high-speed HTML coding and editing. The core of this plugin is a powerful abbreviation engine which allows you to expand expressions—similar to CSS selectors—into HTML code.


    This is a great plugin when you’re working with a lot of markup. Tag is a collection of packages about, predictably, tags, mixed together in an effort to provide a single package with utilities to work with tags. Close a tag on a slash and tag indenting? Sign me up!


    This plugin collection includes plugins to fold your code according to brackts, cycle through selecting tags and many more.


    And where will all us be without jQuery? This is a Sublime Text bundle to help with jQuery functions.


    JsFormat is a javascipt formatting plugin for Sublime Text 2. It uses the commandline/python-module javascript formatter from JS Beautifier to format the selected text, or the entire file if there is no selection.


    It’s a good practice to always minify your files during deploying to a production server. And this plugin will swiftly automate the process by minifying your JavaScript using the Google Closure Compiler or UglifyJS compilers.
 
JsLint可由 SublimeLinter 插件实现


    DocBlockr is a Sublime Text 2 package which makes writing JSDoc comments and PHPDoc comments a breeze.


    A plugin that runs CSS through the Prefixr API, written by our very own Jeffrey Way, for Sublime Text 2.


    Tired of constantly having to manually convert your colors’ hexcodes to HSL? This plugin will automatically do it for you with the press of a button. Well, ok, three buttons. [Shift+Ctrl+U]

4. General Program
版本管理 sublime_tortoise / Git


    I’m quite a stickler for properly formatted code. One thing to get right is lining up all those darn variable assignment so they look all organized and neat. With this plugin, all it takes is the press of key. A simple key-binding allows you align multi-line and multiple selections.

SublimeREPL

    Run your favorite interpreter [python, ruby, lua, prolog :)] or Telnet session to an external tool (MozRepl) inside a Sublime buffer.


    DetectSyntax is a plugin for Sublime Text 2 that allows you to detect the syntax of files that might not otherwise be detected properly. This is specially helpful when you run into custom file formats — files used in templating is an excellent example.


    Case conversion is a plugin for Sublime Text 2. It converts the current word/token between pascal, camel, and snake case.

5. Others

EncodingHelper 编码转换

sublime-gbk

RegReplace Plugin

SublimeFileTemplates

SFTP 远程开发

HexViewer

SideBarEnhancements

Tips

1. vim模式

Preferences/Global Settings – Default

"ignored_packages": ["Vintage"] --> "ignored_packages": []

or try this plugin: https://github.com/SublimeText/VintageEx

2. 设置字体

Preferences > File Settings – User

{
"font_face": "Meslo LG S DZ",
"font_size": 10,
}

3. Fuzzy Finder (Go to Anything)

CTRL+P (fuzzy finder)

4. Multi Selection: awesome

按住Ctrl,选择吧

You Can Still Use TextMate Bundles

TextMate snippets and themes port over nicely to Sublime Text. You only need to drop them in the Packages folder — .tmbundle extension intact, and Sublime will recognize the files. This means that the entire catalog of TextMate themes will work in Sublime!

参考:

星期一, 十一月 07, 2011

Vim代码补全与浏览(vim code completion/navigation)

vim本身的补全功能对于c++来说还有明显不足,在大项目中使用ctags建立索引的效率一直是为大家诟病的地方,而且ctags autocompletion does NOT work for boost shared pointers。有人开发了利用编译器(clanggccsense)生成的AST (Abstract Syntax Tree)来进行代码分析,目前已经有人开发出了emacs、vim、gedit 的 code assistance 插件。

vim插件 clang_complete,可以用来进行代码补全,但是没有代码跳转功能。(update:原版的clang_complete正在开发函数跳转功能,但是要求clang version >= 3.0)

于是又有人开发了 CLIC – the Clang Indexer for C/C++,这里是作者在博客中的介绍

1. 建立索引

$ git clone git://github.com/exclipy/clang_indexer.git
$ cd clang_indexer
$ mkdir build
$ cd build
$ cmake ..
$ make
 
得到三个二进制文件: clic_add, clic_rm and clic_clear,把它们放到PATH中。并不直接使用这三个命令,而是用项目根目录中的clic_update.sh,这个脚本唯一的参数是你的工程源码目录,示例如下

$ mkdir ~/src/project-index 
$ cd ~/src/project-index 
 $ clic_update.sh ~/src/project

会生成一个index.db索引文件。

2. 在vim中进行代码补全和跳转

需要对原来 Rip-Rip  clang_complete plugin 进行修改,这是作者的改版 a fork of clang_complete.

$ git clone https://github.com/exclipy/clang_complete.git 

.vim推荐设置

let g:clang_auto_select=1
let g:clang_complete_auto=0
let g:clang_complete_copen=1
let g:clang_hl_errors=1
let g:clang_periodic_quickfix=0
let g:clang_snippets=1
let g:clang_snippets_engine="clang_complete"
let g:clang_conceal_snippets=1
let g:clang_exec="clang"
let g:clang_user_options=""
let g:clang_auto_user_options="path, .clang_complete"
let g:clang_use_library=1
let g:clang_library_path="/directory/of/libclang.so/"
let g:clang_sort_algo="priority"
let g:clang_complete_macros=1
let g:clang_complete_patterns=0
nnoremap >Leader>q :call g:ClangUpdateQuickFix()

let g:clic_filename="/path/to/index.db"
nnoremap >Leader>r :call ClangGetReferences()
nnoremap >Leader>d :call ClangGetDeclarations()
nnoremap >Leader>s :call ClangGetSubclasses()
 
在源码目录新建 .clang_complete 文件,写入 clang/libclang 参数,示例:

-I/opt/local/include
-I/opt/local/include/db52
-std=c++0x

附1:用tab补全类属性时与snipMate冲突

myclass. turns to: myclass[]

snipMate/snippets/c.snippets 最后两行

snippet .
    [${1}]${2} 
 
注释掉

# snippet .
#     [${1}]${2} 

附2:预编译

clang/libclang都是实时编译的,所以效率可能会有问题,尤其是当代码非常多的时候。创建一个头文件,然后include你的那些文件,然后调用clang预编译一下。

pchheader.h内容

#include 
#include 
#include 
......

预编译
clang -x c++-header ./pchheader.h -fno-exceptions -fnu-runtime -o ./pchheader.pch

添加到.clang_complete
echo '-include-pch pchheader.pch -fgnu-runtime' >> .clang_complete 

附3:ubuntu 中 libclang.so 问题

参见此 bug