;; This file goes along with cindexmode.el ;; The key bindings I use: (add to your .emacs after loading this file) ;; ;; (global-set-key [(alt ?x)] 'cxref) ;; (global-set-key [(alt ?f)] 'cfunc-lookup) ;; ;; note you have to generate an index using cfuncindex ;; before these functions will work! ;; ;; - Peter Amstutz (tetron@student.umass.edu) ;; ;; This ELisp code is licensed under the GNU General Public License, ;; just like the rest of Emacs. (defvar cxref-version "1.0") (defvar cxref-buffer-name "*cfuncindex*") (defun read-string-back-to (func &optional str) (unless str (setq str "")) (let ((c (preceding-char))) (unless (funcall func c) (setq str (read-string-back-to func (prog1 (setq str (concat (char-to-string c) str)) (backward-char)))))) str) (defun cxref () (interactive) (let* ((pointpos (point)) (funcname (concat (read-string-back-to (lambda (c) (or (char= c ?\ ) (char= c ?,) (char= c ?\() (char= c ?=) (char= c ?\t) (char= c ?\n)))) (progn (goto-char pointpos) (read-string-to (lambda (c) (char= c ?\()))))) (indexbuf (get-buffer cxref-buffer-name)) (filestart 0)) (set-buffer indexbuf) (goto-char 0) (search-forward funcname) (cfuncindex-load))) (defun extract-functions () (beginning-of-line) (read-string-to (lambda (c) (not (char= c ?\ )))) (cond ((or (eolp) (eobp)) nil) ((and (char= (char-after (point)) ?#) (char= (char-after (+ (point) 1)) ?#) (char= (char-after (+ (point) 2)) ?\ )) (next-line 1) (extract-functions)) ((numberp (read (char-to-string (following-char)))) (read-string-to (lambda (c) (char= c ?\())) (cons (prog1 (cons (read-string-back-to (lambda (c) (char= c ?\ ))) nil) (next-line 1)) (extract-functions))))) (defun cfunc-lookup (function) (interactive (list (completing-read "Function name: " (let* ((oldbuf (current-buffer)) (buf (get-buffer "*cfuncindex*")) (pos (point buf)) (olddepth max-lisp-eval-depth)) (setq max-lisp-eval-depth 500) (set-buffer buf) (goto-char 0) (prog1 (extract-functions) (goto-char pos) (set-buffer oldbuf) (setq max-lisp-eval-depth olddepth)))))) (set-buffer (get-buffer "*cfuncindex*")) (goto-char 0) (search-forward function) (cfuncindex-load))