Emacs and Global

本文介绍如何安装并配置Emacs作为默认编辑器及Global作为源代码标记系统,用于快速定位符号定义及其引用。
Would you please install emacs and global on two build servers?1.Emacs: default editor for KreaTV coding.

2.Global is used to tag the codes. See http://wiki.mot-mobility.com/KreaTV/GnuGlobal 


sudo yum install emacs
sudo yum install global

 

sudo yum install emacs
Introduction:
GNU Global is a source code tagging system (similar to etags, ctags and idutils) that makes it possible to almost instantly find where tags/symbols are defined and referred to in the source code. Read more on http://www.gnu.org/software/global/.
Installation:    sudo yum install global

Configuration

The worst thing about GNU Global is its configuration format, and unfortunately you have to modify the configuration to make Global treat .h files as C++ source code. Do like this:
Copy /usr/share/gtags/gtags.conf to ~/.globalrc
Edit ~/.globalrc so that langmap says something like c\:.c and cpp\:.c++.cc.cpp.cxx.hxx.hpp.C.H.h

Creating the database
The gtags command recursively parses the source files under the current directory and writes cross-reference data to four database files: GTAGS, GRTAGS, GSYMS and GPATH. The standard way of creating the database is by running gtags at the root of the source tree. However, if you run gtags in a built source tree, it finds all 3pps and tries to index all the unpacked source code. This will fail because the database will be too large; GNU Global currently can't create files larger than 2 GiB.
Therefore, there is a convenience script called gtags-update (located in ~tools/bin) that you can run in an SVN working copy containing a built source tree. The script tells GNU Global to only index the source code files known to SVN. To use it, cd to the SVN working copy and run the script:
  cd .../ITEM_XXXX
  ~tools/bin/gtags-update
You can rerun gtags-update at any time to update the index with the current state of the source code. The script can also be run from any subdirectory; it changes directory to the top SVN directory and then runs the indexing from there.

Command-line usage:
The global command can be used to query the database from the command-line. For example,
 global -g FOO
will print all lines that match the pattern FOO. See the documentation for more information.

 

Bash completion
If you want completion support in bash, copy benromach:/etc/profile.d/global-complete.sh to your workstation/server.

Emacs usage
To use Global in Emacs, put
  (require 'gtags "/usr/share/gtags/gtags.el")
in your ~/.emacs. If you get the error Required feature `gtags' was not provided, use this line instead:
  (load "/usr/share/gtags/gtags.el")
You can then use these commands:
Command     Description
gtags-find-tag     Find definition of a tag
gtags-find-rtag     Find all references to a tag
gtags-find-file     Find files matching a pattern
gtags-find-symbol     Find all locations of a symbol
You can also define a gtags-update command:
  (defun gtags-update ()
    (interactive)
    (message "Updating GTAGS database...")
    (if (= (call-process "/home/tools/bin/gtags-update") 0)
        (message "Updating GTAGS database...done")
      (message "Updating GTAGS database...FAILED")))
Suggested key bindings to put in ~/.emacs:
  (global-set-key (kbd "M-.") 'gtags-find-tag)
  (global-set-key (kbd "M-,") 'gtags-find-rtag)
  (global-set-key (kbd "M-g M-f") 'gtags-find-file)
  (global-set-key (kbd "M-g M-s") 'gtags-find-symbol)
  (global-set-key (kbd "M-g M-u") 'gtags-update)
Also try gtags-pop-stack, bound to M-*, after a tag search — it returns the window state to the one prior to the search.

 

vim ~/bin/gtags-update   //(will be set on /home/leosu/bin/gtags-update  or other bin directory,  and set chmod 777  /home/leosu/bin/gtags-update)

#! /bin/sh

set -eu

error() {
    echo "$(basename $0): error: $*"
    exit 1
}

usage() {
cat <<EOF
Usage: $(basename $0) [options]

Options:
    -h, --help     Display this help and exit.
    -v, --verbose  Verbose mode.

Creates or updates a GTAGS (GNU Global) database from C and C++ files
in an SVN working copy.

Current directory is expected to be part of an SVN working copy and
the GTAGS database will be created from the top directory of the
SVN working copy. Files unknown to SVN are ignored.

To include non-SVN directories in the index, list them in
~/.gtags-update-dirs. The directories can be absolute or relative to
the root.
EOF
}

cd_to_svn_top_dir() {
    while [ -d ../.svn ]; do
        cd ..
    done
    test -d .svn
}

verbose=
while [ "$#" -gt 0 ]; do
    case $1 in
        -h|--help)
            usage
            exit 0
            ;;

        -v|--verbose)
            verbose=-v
            ;;

        *)
            usage
            exit 1
            ;;
    esac

    shift
done

if ! which svn >/dev/null 2>&1; then
    error "Could not find the svn command; have you installed Subversion?"
fi

if ! which gtags >/dev/null 2>&1; then
    error "Could not find the gtags command; have you installed GNU Global?"
fi

if ! cd_to_svn_top_dir; then
    error "Current directory is not part of an SVN working copy"
fi

tmpfile=$(mktemp)
trap "rm -f $tmpfile" EXIT

if [ -e ~/.gtags-update-dirs ]; then
    for path in $(cat ~/.gtags-update-dirs); do
        find $path -name ".svn" -prune -o -type f >>$tmpfile
    done
fi

svn status --verbose |
     perl -ane '$_ = pop(@F); print "$_\n" if -f;' >>$tmpfile

gtags -i $verbose -f $tmpfile

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值