分类: LINUX
2008-03-29 00:39:09
(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")))
#!/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 -)
#!/bin/sh
[ "$#" != 1 ] && exit 1
rm -f "${1}"/.emacsprj/data/TAGS
rm -f "${1}"/.emacsprj/data/TAGS.*
rm -f "${1}"/.emacsprj/data/cscope.*