web developer & system programmer

coder . cl

ramblings and thoughts on programming...


changes in my ecb hooks

published: 08-08-2010 / updated: 08-08-2010
posted in: emacs, programming, tips
by Daniel Molina Wegener

As you know I’m an emacs user. I use emacs due its flexibility and extensibility, I’m using some major modes like CEDET and ECB. I use some hooks to integrate emacs and my common programming tasks. For example, I can’t imagine programming large projects like the FreeBSD Kernel or Linux Kernel only by using grep(1), egrep(1) or find(1), so I need to index large amount of code files…

For indexing tasks I’ve integrated ECB and cscope-mode, and created some hooks for certain directories. To let ECB know which hook must run on each directory, I’ve created the following variable in my .emacs file:

(defvar dmw-ecb-directory-change-alist
  '(("/work/src/caffeine" caffeine-c-mode-hook)
    ("/work/src/caffeine++" caffeine-c++-mode-hook)
    ("/work/src/fireservice" caffeine-c++-mode-hook)
    ("/work/src/Linux" caffeine-c-mode-hook)
    ("/work/src/FreeBSD" caffeine-c-mode-hook)
    ("/work/src/jaxer/products/server/src" caffeine-c++-mode-hook)
    ("/work/src/syslog-ng" caffeine-c-mode-hook)
    ("/work/src/pyxser" python-c-mode-hook)
    ("/work/gae/gae-1.3.5/cclp" python-mode-hook)
    ("/work/gae/gae-1.3.5" python-mode-hook)))

To let emacs know which directories requires automatic indexing of C code files I’ve created the following variable:

(defvar dmw-ecb-cscope-autoindexing-projects
  '("/work/src/caffeine"
    "/work/src/caffeine++"
    "/work/src/fireservice"
    "/work/src/Linux"
    "/work/src/FreeBSD"
    "/work/src/jaxer/products/server/src"
    "/work/src/syslog-ng"
    "/work/src/pyxser"))

And created the following hook to make each emacs sessions something really productive:

(defun dmw-ecb-directory-change-hook (dirold dirnew)
  (dolist (prji dmw-ecb-directory-change-alist)
    (let ((prj-name (first prji))
          (prj-match (string-match (concat (first prji) ".*") dirnew))
          (prj-hook (last prji))
          )
      (if (numberp prj-match)
          (progn
            (if (>= prj-match 0)
                (dolist (h (last prji))
                  (run-hook-with-args h)))
            (dolist (cscope-auto dmw-ecb-cscope-autoindexing-projects)
              (let ((newpath (concat dirnew "/cscope.out"))
                    (dirnew dirnew))
                (if (and (string= prj-name cscope-auto)
                         (not (file-exists-p cscope-auto)))
                    (progn
                      (setq cscope-database-file newpath
                            cscope-do-not-update-database nil
                            cscope-use-relative-path t
                            cscope-initial-directory dirnew)
                      (cscope-index-files dirnew)))))
            )))))

(defun dmw-cedet-hook ()
  (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "C-c>" 'semantic-complete-analyze-inline)
  (local-set-key "C-cp" 'semantic-analyze-proto-impl-toggle))

(add-hook 'c-mode-common-hook
          'dmw-cedet-hook)

(add-hook 'ecb-after-directory-change-hook
          'dmw-ecb-directory-change-hook)

(global-ede-mode t)

The dmw-ecb-directory-change-hook run each hook associated with project directories in the dmw-ecb-directory-change-alist list and also, it verify if the directory is present in the dmw-ecb-cscope-autoindexing-projects, and if the directory is on the list, it will call the cscope-index-files function to index the directory using cscope(1).

Also, here is my ecb-activate-hook, which makes coding under emacs quite more productive, and make its behaviour very similar to any another IDE:

(defun dmw-ecb-activate-hook ()
  (custom-set-variables
   '(ecb-display-default-dir-after-start t)
   '(ecb-auto-activate nil)
   '(ecb-options-version "2.32")
   '(ecb-source-path dmw-ecb-working-projects)
   '(ecb-tip-of-the-day nil)
   '(cache-directory-contents
     (quote ((".*caffeine" . 10000)
             (".*caffeine++" . 10000)
             (".*pyxser" . 10000)
             (".*fireservice" . 10000)
             (".*src/" . 10000))))
   )
  (setq-mode-local c-mode semanticdb-find-default-throttle
                   '(project unloaded system recursive))
  (setq-mode-local c++-mode semanticdb-find-default-throttle
                   '(project unloaded system recursive))
  (semantic-add-system-include "/usr/include" 'c++-mode)
  (semantic-add-system-include "/usr/local/include" 'c++-mode)
  (semantic-add-system-include "/usr/include" 'c-mode)
  (semantic-add-system-include "/usr/local/include" 'c-mode)
  (message "ECB Activate Hook Done!"))

emacs rocks ;)


No coments yet.

post a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>