Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1761013
  • 博文数量: 100
  • 博客积分: 10122
  • 博客等级: 上将
  • 技术积分: 4092
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-04 20:28
文章分类

全部博文(100)

文章存档

2010年(2)

2009年(28)

2008年(70)

我的朋友

分类: LINUX

2008-03-29 00:39:09

emacsprj, 用于将项目的TAGS,书签,session记录等等独立保存。

FILE : 00-emacsprj.el
(defun emacsprj-load (sourcedir)
(interactive "DLoad emacs project from directory:")
(setq emacsprj-source-directory
(replace-regexp-in-string "/*$" ""
(file-truename sourcedir)))
(setq emacsprj-id (file-name-nondirectory emacsprj-source-directory))
(setq emacsprj-directory
(expand-file-name (concat emacsprj-source-directory "/.emacsprj/")))
(setq emacsprj-config-file
(expand-file-name (concat emacsprj-directory "config.el")))
(setq emacsprj-data-directory
(expand-file-name (concat emacsprj-directory "data/")))
(setq emacsprj-session-save-file
(expand-file-name (concat emacsprj-data-directory ".session")))

;;
;; check sanity of emacs project
;;
;;; check emacs project dir
(unless (file-accessible-directory-p emacsprj-directory)
(error "emacsprj directory \"%s\" does not exist, create it first"
emacsprj-directory))
;;; check config filetsocsk
(unless (file-exists-p emacsprj-config-file)
(error "emacsprj config file \"%s\" does not exist, create it first"
emacsprj-config-file))
;;; check emacs project data, if it does not exist, initial the emacsprj
(unless (file-accessible-directory-p emacsprj-data-directory)
(make-directory emacsprj-data-directory)
(desktop-save emacsprj-data-directory)
(emacsprj-update-refs))

;;
;; loading project
;;
;;; set default variables
(setq default-directory emacsprj-source-directory)
(setq ecb-source-path (list (list emacsprj-source-directory emacsprj-id)))
(setq compile-command (concat "make -C " emacsprj-source-directory))
(setq bookmark-default-file (concat emacsprj-data-directory "bookmarks"))
(setq recentf-save-file (concat emacsprj-data-directory "recentf"))
(setq server-name emacsprj-id)
;;; run local expressions
(load emacsprj-config-file)
;;; initialize ecb
(ecb-activate)
;;; load desktop
(desktop-change-dir emacsprj-data-directory)
(desktop-save-mode)
;;; save bookmarks when exist
(add-hook 'kill-emacs-hook 'bookmark-save)
;;; load session
(setq session-save-file emacsprj-session-save-file)
(session-initialize)
;;; load project tags and cscope database
(setq cscope-initial-directory emacsprj-data-directory)
(visit-tags-table emacsprj-data-directory)
(server-start)
(message "emacsprj loaded\n"))

(defun emacsprj-update-refs ()
(interactive)
(if (boundp 'emacsprj-source-directory)
(progn (my-try-run "emacsprj-update-refs" emacsprj-source-directory)
(message "references updated : %s" emacsprj-source-directory))
(error "No emacsprj is loaded")))

(defun emacsprj-regen-refs ()
(interactive)
(if (boundp 'emacsprj-source-directory)
(progn (my-try-run "emacsprj-clean-refs" emacsprj-source-directory)
(my-try-run "emacsprj-update-refs" emacsprj-source-directory)
(message "references regenerated : %s" emacsprj-source-directory))
(error "No emacsprj is loaded")))

FILE : emacsprj-update-refs
#!/bin/sh

[ "$#" != 1 ] && exit 1

cd "$1"

EMACSPRJ_DIR=.emacsprj/
EMACSPRJ_DATADIR=${EMACSPRJ_DIR}/data
TAGS_FILE=${EMACSPRJ_DATADIR}/TAGS
LOCAL_TAGS_FILE=${EMACSPRJ_DATADIR}/TAGS.local
[ -f "${LOCAL_TAGS_FILE}" ] || LOCAL_TAGS_FILE_IS_NEW=1

INCLUDE_TAGS_FILES=$(cat "${EMACSPRJ_DIR}/include_tags_files.list" 2>/dev/null)
FILES_REGEX=$(cat "${EMACSPRJ_DIR}/files_regex.list" 2>/dev/null)

for file_regex in ${FILES_REGEX};do
REFFILES+=' '$(find . -regex "$file_regex")
done
# tags
# local tags
for reffile in ${REFFILES};do
if { [ ! -z "${LOCAL_TAGS_FILE_IS_NEW}" ] ||
[ "${reffiles}" -nt "${LOCAL_TAGS_FILE}" ] ;};then
etags -a "${PWD}/${reffile}" -o "${LOCAL_TAGS_FILE}"
fi
done
# generate tags
NEED_REGEN=
[ ! -f "${TAGS_FILE}" ] && NEED_REGEN=1
[ "${LOCAL_TAGS_FILE}" -nt "${TAGS_FILE}" ] && NEED_REGEN=1
for include_tags_file in ${INCLUDE_TAGS_FILES};do
[ "${include_tags_file}" -nt "${TAGS_FILE}" ] && NEED_REGEN=1
done
if [ "$NEED_REGEN" == 1 ];then
cat "$LOCAL_TAGS_FILE" > "${TAGS_FILE}"
for include_tags_file in ${INCLUDE_TAGS_FILES};do
cat ~/.tags/output/$include_tags_file >> "$TAGS_FILE"
done
fi

# cscope database
for reffile in ${REFFILES};do
echo "${PWD}/${reffile}"
done | (cd ${EMACSPRJ_DATADIR};cscope -b -i -)


FILE : emacsprj-clean-refs

#!/bin/sh

[ "$#" != 1 ] && exit 1

rm -f "${1}"/.emacsprj/data/TAGS
rm -f "${1}"/.emacsprj/data/TAGS.*
rm -f "${1}"/.emacsprj/data/cscope.*


使用例子

我的linux kernel项目目录 :
$ ls ~/mydoc/prog/linux/
build  linux-2.6  rootfs

linux-2.6 是 git clone, rootfs 是虚拟机里用的一些 nfs root, build 是一些辅助脚本。

为了使用 emacsprj,我需要创建这么两个文件:
$ cat ~/mydoc/prog/linux/.emacsprj/config.el
(setq c-default-style '((c-mode . "linux") (other . "linux")))
(setq c-basic-offset 4)

$ cat ~/mydoc/prog/linux/.emacsprj/files_regex.list
\./linux-2.6/.*\.h
\./linux-2.6/.*\.c
\./linux-2.6/.*\.S

然后就可以调用 emacsprj-load 这个文件夹了,我把这些都做了键绑定了:
(global-set-key (kbd "") 'emacsprj-update-refs)
(global-set-key (kbd "S-") 'emacsprj-regen-refs)
(global-set-key (kbd "C-x ") 'emacsprj-load)

截图(看不出emacsprj痕迹。。):
The image “http://blog.chinaunix.net/photo/8057_080329002910.png” cannot be displayed, because it contains errors.

阅读(2002) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~