---
cbrow
(setq cbrow--buffer-name "*Class Browser*")
(setq cbrow--buffer nil)
(global-set-key [kp-enter] (function (lambda () (interactive)
(message "cbrow--inside-method=%s"
(cbrow--inside-method)))))
(global-set-key [kp-enter] (function (lambda () (interactive)
(message "cbrow--inside-class=%s"
(cbrow--inside-class)))))
(defun cbrow--inside-namespace-p1-and-p2 ()
(save-match-data
(save-excursion
(let (orig squiggly result)
(setq orig (point))
(setq result (cons nil nil))
(when (re-search-backward "^{" nil t)
(setq squiggly (point))
(forward-line -1)
(beginning-of-line)
(when (looking-at "^namespace _*[a-zA-Z][a-zA-Z0-9_]*[ \t]*$")
(goto-char squiggly)
(forward-sexp 1)
(if (< orig (point))
(setq result (cons squiggly (point))))))
(if (not (car result)) (setcar result (point-min)))
(if (not (cdr result)) (setcdr result (point-max)))
result
))))
(defun cbrow--inside-class-p1-and-p2 ()
(save-match-data
(save-excursion
(let (orig squiggly result)
(setq result (cons nil nil))
(setq orig (point))
(cond
((save-excursion
(beginning-of-line)
(looking-at (if *namespace* "^[ ][ ][ ]{" "^{")))
(setq squiggly (point))
(forward-sexp 1)
(when (< orig (point))
(setq result (cons squiggly (point)))))
((save-excursion
(beginning-of-line)
(when (looking-at (concat
(if *namespace* "^[ ][ ][ ]" "^")
"\\([A-Z]+ \\)*class \\(_*[a-zA-Z][a-zA-Z0-9_]*\\)"))
(forward-line 1)
(looking-at (if *namespace* "^[ ][ ][ ]{" "^{"))
(setq squiggly (point))
(forward-sexp 1)
(when (< orig (point))
(setq result (cons squiggly (point)))))))
((save-excursion
(re-search-backward (if *namespace* "^[ ][ ][ ]{" "^{") nil t)
(setq squiggly (point))
(forward-sexp 1)
(when (< orig (point))
(setq result (cons squiggly (point))))))
)
(if (not (car result)) (setcar result (point-min)))
(if (not (cdr result)) (setcdr result (point-max)))
result
))))
(defun cbrow--inside-method-p1-and-p2--inner ()
(cond
((and *namespace* *class*) "^[ ][ ][ ][ ][ ][ ]{")
((or *namespace* *class*) "^[ ][ ][ ]{")
(t "^{")))
(defun cbrow--inside-method-p1-and-p2 ()
(save-match-data
(save-excursion
(let (orig squiggly space-squigglies result p)
(setq *namespace* (cbrow--inside-namespace))
(setq *class* (cbrow--inside-class))
(setq orig (point))
(setq space-squigglies (cbrow--inside-method-p1-and-p2--inner))
(setq result (cons nil nil))
(cond
((save-excursion
(when (looking-at space-squigglies)
(setq squiggly (point))
(forward-sexp -1) (beginning-of-line)
(when (looking-at (concat "^[ \t]*" cbrow--inside-method--regexp "("))
(setq p (point))
(goto-char squiggly)
(forward-sexp 1) (when (< orig (point))
(setq result (cons p (point)))
result))))
result)
((save-excursion
(when (re-search-backward space-squigglies nil t)
(setq squiggly (point))
(forward-sexp -1) (beginning-of-line)
(setq p (point))
(when (looking-at (concat "^[ \t]*" cbrow--inside-method--regexp ")"))
(goto-char squiggly)
(forward-sexp 1) (when (< orig (point))
(setq result (cons p (point)))
result
))))
result)
((save-excursion
(when (re-search-forward space-squigglies nil t)
(forward-char -1)
(setq squiggly (point))
(forward-sexp 1) (setq squiggly-end (point))
(goto-char squiggly)
(forward-sexp -1) (beginning-of-line)
(if (looking-at (concat "^[ \t]*" cbrow--inside-method--regexp "("))
(setq result (cons (point) squiggly-end)))
))
result))
(if (not (car result)) (setcar result (point-min)))
(if (not (cdr result)) (setcdr result (point-max)))
result))))
(defun cbrow--inside-namespace ()
(save-match-data
(save-excursion
(let ((namespace nil)
(oldp (point)))
(if (re-search-backward "^{" nil t)
(progn
(forward-line -1)
(when (looking-at "namespace[ \t]+\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)")
(setq namespace (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
(forward-line 1)
(forward-sexp 1)
(if (> (point) oldp)
namespace))))))))
(defun cbrow--inside-class ()
(save-match-data
(save-excursion
(let ((oldp (point))
(*namespace* (class-point nil)
(p1 nil)
(p2 nil)
(*class* nil)
(*namespace* (cbrow--inside-namespace))
(meth-class nil))
(cond
((save-excursion
(beginning-of-line)
(looking-at (concat (if *namespace* "^[ ][ ][ ]" "^") "\\([A-Z]+[ \t]+\\)*class[ \t][a-zA-Z0-9_:]+")))
(beginning-of-line)
(forward-line 1)
(when (save-excursion
(beginning-of-line)
(looking-at "^-+$"))
(beginning-of-line)
(forward-line 2))
(forward-line 1)
)
((save-excursion
(beginning-of-line)
(looking-at "^-+$"))
(beginning-of-line)
(forward-line 2)
)
((save-excursion
(beginning-of-line)
(looking-at (if *namespace* "^[ ][ ][ ]{" "{")))
(beginning-of-line)
(forward-line 1)
)
(t
(forward-line 1)
)
)
(when (re-search-backward (if *namespace* "^[ ][ ][ ]{" "^{") nil t)
(setq class-point (point))
(skip-chars-forward " \t")
(if 123 (forward-sexp 1))
(when (> (point) oldp)
(goto-char class-point)
(forward-line -1)
(while (looking-at "^-+$")
(forward-line -1)
(beginning-of-line))
(beginning-of-line)
(if (looking-at (concat "^"
(if *namespace* "[ ][ ][ ]")
"\\([A-Z0-9_]+[ \t]+\\)*class[ \t]\\([a-zA-Z0-9_:]+\\)"))
(progn
*namespace* (setq meth-class (buffer-substring-no-properties (match-beginning 2) (match-end 2))))
(setq meth-class nil)
)
(if (and *namespace* meth-class)
(concat *namespace* "::" meth-class)
meth-class)))))))
(setq cbrow--inside-class--regexp "^\\([A-Z]+[ \t]+\\)?class \\(_*[a-zA-Z][a-zA-Z0-9_]*::\\)?\\([A-Za-z][A-Za-z0-9_]*\\)[^;\n]*\n")
(setq cbrow--identifier--chars "~A-Za-z0-9_")
(setq cbrow--inside-method--regexp
(concat "\\(_*[a-zA-Z][A-Za-z0-9_<]*[> ]*[&*]*[ \t]+\\)*"
"\\(_*[a-zA-Z][~a-zA-Z0-9_:]*\\)"))
(defun cbrow--number-of-commas (method)
(let ((count 0) (method-2 method))
(while (string-match "," method-2)
(incf count)
(setq method-2 (concat
(substring method-2 0 (match-beginning 0))
"."
(substring method-2 (match-end 0)))))
count))
(defun cbrow--remove-spaces (s)
(let ((len (length s))
(i 0)
(answer ""))
(while (< i len)
(let ((ch (aref s i)))
(if (or (= ch ?\t)
(= ch ?\r)
(= ch ?\n))
(setq ch ? ))
(setq answer (format "%s%c" answer ch)))
(if (cbrow--is-space s i)
(while (and (< i len)
(cbrow--is-space s i))
(incf i))
(incf i))
)
answer))
(defun cbrow--trim-spaces-in-args (method)
(progn
(while (string-match "( " method)
(setq method (concat (substring method 0 (match-beginning 0))
"("
(substring method (match-end 0)))))
(while (string-match ", " method)
(setq method (concat (substring method 0 (match-beginning 0))
","
(substring method (match-end 0)))))
(while (string-match " )" method)
(setq method (concat (substring method 0 (match-beginning 0))
")"
(substring method (match-end 0)))))
method))
(defun cbrow--change-args (method)
(when (not (string-match "()" method))
(let (count beg end len len+1)
(progn
(setq count 0)
(setq method (cbrow--remove-spaces method))
(setq method (cbrow--trim-spaces-in-args method))
(setq len (cbrow--number-of-commas method))
(setq len+1 (1+ len))
(while (< count len+1)
(progn
(if (= count 0)
(setq beg "(")
(setq beg ","))
(if (= count len)
(setq end ")")
(setq end ","))
(cons beg end))
(when (string-match (concat beg
"\\(\\(const \\|unsigned \\|signed\\)*[a-zA-Z0-9_<:]+[ >]*[&*]*\\) "
"\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)\\(\\( ?= ?_*[a-zA-Z][a-zA-Z0-9_]*\\)?\\)"
end)
method)
(setq method (concat (substring method 0 (match-end 1))
(substring method (match-end 4))
)))
(incf count)))
)
)
method
)
(defun cbrow--space-regexp ()
(cond
((and *namespace* *class*)
"^[ ][ ][ ][ ][ ][ ]{"
)
((or *namespace* *class*)
"^[ ][ ][ ]{")
(t
"^{")))
(defun cbrow--sqiggly-regexp ()
(cond
((and *namespace* *class*)
"^[ ][ ][ ][ ][ ][ ]{"
)
((or *namespace* *class*)
"^[ ][ ][ ]{")
(t
"^{")))
(defun cbrow--inside-method ()
(save-match-data
(save-excursion
(let ((orig (point)) p *namespace* *class* found squiggly result namespace-ps class-ps)
(beginning-of-line)
(setq *namespace* (cbrow--inside-namespace))
(setq *class* (cbrow--inside-class))
(if *namespace*
(setq namespace-ps (cbrow--inside-namespace-p1-and-p2)))
(if *class*
(setq class-ps (cbrow--inside-class-p1-and-p2)))
(if (and *class* (string-match (concat "\\(" *namespace* "::\\)") *class*))
(setq *class* (substring *class* (match-end 1))))
(cond
((save-excursion
(beginning-of-line)
(when (looking-at (cbrow--space-regexp))
(setq squiggly (point))
(forward-sexp -1) (beginning-of-line)
(setq p (point))
(goto-char squiggly)
(forward-sexp 1) (when (< orig (point))
(goto-char p)
(when (re-search-forward (concat (cbrow--space-regexp) cbrow--inside-method--regexp "(")
(if *namespace* (cdr namespace-ps) (cdr class-ps))
t)
(setq found (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
(forward-char -1)
(setq p (point))
(forward-sexp 1) (setq found (concat found (cbrow--change-args (buffer-substring-no-properties p (point)))))
found))))
found)
((save-excursion
(beginning-of-line)
(when (re-search-forward (cbrow--sqiggly-regexp)
(cond
((and namespace-ps class-ps)
(min (cdr namespace-ps) (cdr class-ps)))
(namespace-ps
(cdr namespace-ps))
(class-ps
(cdr class-ps))
(t
nil)) t)
(forward-char -1)
(setq squiggly (point))
(forward-sexp -1) (beginning-of-line)
(setq p (point))
(goto-char squiggly)
(forward-sexp 1) (when (< orig (point))
(goto-char squiggly)
(if 'foomatic (forward-sexp -1)) (beginning-of-line)
(when (re-search-forward (concat (cbrow--space-regexp) cbrow--inside-method--regexp "(")
(if *namespace* (cdr namespace-ps) (cdr class-ps) )
t)
(setq found (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
(forward-char -1)
(setq p (point))
(forward-sexp 1) (setq found (concat found (cbrow--change-args (buffer-substring-no-properties p (point)))))
found))))
found)
((save-excursion
(when (re-search-backward (cbrow--sqiggly-regexp) nil t)
(setq squiggly (point))
(if 'mac (forward-sexp -1)) (beginning-of-line)
(setq p (point))
(goto-char squiggly)
(forward-sexp 1) (when (< orig (point))
(goto-char p)
(when (re-search-forward (concat (cbrow--space-regexp) cbrow--inside-method--regexp "(")
(if *namespace* (cdr namespace-ps) (cdr class-ps))
t)
(setq found (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
(forward-char -1)
(setq p (point))
(forward-sexp 1) (setq found (concat found (cbrow--change-args (buffer-substring-no-properties p (point)))))
found
))))
found)
((save-excursion
(and (not *namespace*)
(prog1
(re-search-backward (if *class* "^[ ][ ][ ]{" "^{")
(car class-ps)
t)
(setq squiggly (point)))
(progn
(if 'args (forward-sexp -1)) (beginning-of-line)
(setq p (point))
(goto-char squiggly)
(if 'zed (forward-sexp 1)) (when (< orig (point))
(goto-char p)
(when (re-search-forward (concat (if *class* "^[ ][ ][ ]" "^")
cbrow--inside-method--regexp "(") (point-at-eol) t)
(setq found (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
)))))
found)
((save-excursion
(and (not *namespace*)
(progn
(beginning-of-line)
(when (setq result (re-search-forward (if *class* "^[ ][ ][ ]{" "^{")
(if *namespace* (cdr namespace-ps) (cdr class-ps))
t))
(forward-char -1)
(setq squiggly (point))
result))
(progn
(forward-line -1)
(end-of-line)
(if 'banana (forward-sexp -1))
(beginning-of-line)
(setq p (point))
(goto-char squiggly)
(if 'id (forward-sexp 1))
(when (< orig (point))
(goto-char p)
(when (re-search-forward (concat (if *class* "^[ ][ ][ ]" "^")
cbrow--inside-method--regexp "(") (point-at-eol) t)
(setq found (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
(forward-char -1)
(setq p (point))
(forward-sexp 1) (setq found (concat found (cbrow--change-args (buffer-substring-no-properties p (point)))))
found)))))
found)
)
(if found
(concat (if *namespace* (concat *namespace* "::"))
(if *class* (concat *class* "::"))
found))
)
)
)
)
(defun cbrow--current-line-as-string ()
(buffer-substring-no-properties (point-at-bol)
(point-at-eol)))
(defun cbrow--skip-word (word)
(assert (looking-at word))
(let ((i 0)
(len (length word)))
(while (< i len)
(assert (eq (char-after) (aref word i)))
(incf i)
(forward-char 1))))
(defun cbrow--is-space (string index)
(or (= (aref string index) ? )
(= (aref string index) ?\t)
(= (aref string index) ?\n)
(= (aref string index) ?\r)))
(defun cbrow--trim-left (s)
(let (i len ch)
(setq i 0)
(setq len (length s))
(while (and (< i len)
(setq ch (aref s i))
(or (eq ch ?\ )
(eq ch ?\t)
(eq ch ?\r)
(eq ch ?\n)))
(incf i))
(setq s (substring s i)))
s)
(defun cbrow--trim-right (s)
(let (i ch)
(setq i (1- (length s)))
(while (and (>= i 0)
(setq ch (aref s i))
(or (eq ch ?\ )
(eq ch ?\t)
(eq ch ?\r)
(eq ch ?\n)))
(decf i))
(setq s (substring s 0 (1+ i)))
)
)
(defun cbrow--trim-string (s)
(if (or (not s) (string= s ""))
""
(if s (d-trim-left (d-trim-right s)))))
(defun cbrow--trim-return-value (method-spec)
(if (string-match "\\(^[ \t]*\\)\\([a-zA-Z0-9_<>]+[ >]*[&*]*[ \t]+\\)*\\([~a-zA-Z0-9_:]+(\\)" method-spec)
(setq method-spec (substring method-spec (match-beginning 3)))))
(defun cbrow--what-line ()
"Different from what-line in that it returns the result rather than printing it"
(save-excursion
(beginning-of-line)
(1+ (count-lines 1 (point)))))
(defun cbrow--message (string)
(message "Class Browser: %s" string)
)
(defun cbrow--tail (string)
(while (string-match "[\r\n]+[^\r\n]*[\r\n]+" string)
(setq string (substring string (match-end 0)))
)
string)
(defun cbrow--log--simple (string)
(save-excursion
(set-buffer cbrow--buffer-name)
(goto-char (point-max))
(if (not (null string))
(insert string))))
(defun cbrow--log--complex (string &optional not-here)
(let ((what-line (cbrow--what-line))
(spaces 0)
(string-last-line nil))
(while (and (> (length string) 0)
(= (aref string 0) ?\n))
(setq string (substring string 1)))
(if (and (not (string= "" string))
(not (string-match "{$" string))
(not (string-match "[\r\n]+$" string))
(not (string-match "^class[ \t][a-zA-Z0-9_:]+" string))
(not (string-match "^public:" string))
(not (string-match "^private:" string))
(not (string-match "^protected:" string))
(not (string-match "^#" string)))
(when (/= (aref string (1- (length string))) ?\;)
(setq string (concat string ";"))
))
(when (string-match "\\([\r\n]+$\\)" string)
(setq string (substring string 0 (match-beginning 0))))
(setq string-last-line (cbrow--tail string))
(progn
(setq f-w (frame-width))
(setq spaces
(if (<= (length string-last-line) f-w)
(make-string (max 0 (- f-w 20 (length string-last-line))) ? )
" "))
(setq string (concat string spaces)))
(if not-here
(setq string (concat string "//LINE:" (format "%d" what-line) " NOT HERE!"))
(setq string (concat string "//LINE:" (format "%d" what-line))))
(save-excursion
(set-buffer cbrow--buffer)
(goto-char (point-max))
(insert string "\n")
)
)
)
(defun cbrow--scan-comment--this-line ()
(save-match-data
(let ((comment-end nil)
(comment-start nil)
(answer nil))
(save-excursion
(forward-line -1)
(beginning-of-line)
(while (string-match "^[ \t]*$" (cbrow--current-line-as-string))
(forward-line -1))
(forward-line 1)
(setq comment-end (point-at-bol))
(forward-line -1)
(while (and (looking-at (concat (if *namespace* "^[ ][ ][ ][ ][ ][ ]" "^[ ][ ][ ]") "//[^\n\r]*$"))
(not (bobp)))
(forward-line -1)
(beginning-of-line))
(forward-line 1)
(setq comment-start (point))
(setq answer (buffer-substring-no-properties comment-start comment-end))
answer))))
(defun cbrow--scan-method ()
(save-excursion
(save-match-data
(if (string= (buffer-substring-no-properties (point-min) (point-max)) "")
(error "*Class Browser* is empty"))
*namespace* (let* (str)
(setq str (buffer-substring-no-properties
(point-at-bol)
(if (progn
(beginning-of-line)
(search-forward "(" (point-at-eol) t))
(progn
(backward-char 1)
(forward-sexp 1)
(point-at-eol))
(point-at-eol))))
(cbrow--change-args str)
)
)
)
)
(defun cbrow--scan-property--this-line ()
(save-match-data
(let ((str (buffer-substring-no-properties
(point-at-bol)
(save-excursion
(progn
(beginning-of-line)
(search-forward ";")
(point)
)))))
(concat " " (cbrow--remove-spaces str))
)))
(defun cbrow--found-a-method (class-max)
(save-match-data
(let* ((*namespace* (f1 (save-excursion
(re-search-forward
(concat (if *namespace* "^[ ][ ][ ][ ][ ][ ]" "^[ ][ ][ ]")
"\\(_*[a-zA-Z][a-zA-Z0-9_:<]*[ >]*[*&]*[ \t]+\\)*~?\\([a-zA-Z][a-zA-Z0-9_]*\\)(")
class-max
t)))
(f2 (save-excursion
(re-search-forward
(concat (if *namespace* "^[ ][ ][ ][ ][ ][ ]" "^[ ][ ][ ]")
"\\(_*[a-zA-Z][a-zA-Z0-9_:<]*[ >]*[*&]*[ \t]+\\)*operator[ \t]+"
"\\(=\\|==\\|!=\\|+\\|+=\\|-\\|-=\\|<<\\|<<=\\|>>\\|>>=\\)[ \t]+(")
class-max
t))))
(cond
((and (numberp f1) (numberp f2))
(min f1 f2))
((numberp f1)
f1)
((numberp f2)
f2)
nil))))
(defun cbrow--found-a-property (class-max)
(save-match-data
(save-excursion
(re-search-forward (concat (if *namespace* "^[ ][ ][ ][ ][ ][ ]" "^[ ][ ][ ]")
"\\([a-zA-Z_][a-zA-Z0-9_<>:]*[> ]*[&*]*[ \t]+\\)*"
"[a-zA-Z_][a-zA-Z0-9_]*\\([ \t]*=[^;]+\\)?;")
class-max
t))))
(defun cbrow--found-a-template (class-max)
(save-match-data
(save-excursion
(re-search-forward (concat (if *namespace* "^[ ][ ][ ][ ][ ][ ]" "^[ ][ ][ ]")
"template.*;")
class-max
t))))
(defun cbrow--found-an-outer-template ()
(cond
((looking-at "^class")
(setq p (point)))
((save-excursion
(prog2
(forward-line -1)
(looking-at "^class")
(setq p (point)))))
((save-excursion
(prog1
(re-search-backward "^class" nil t)
(setq p (point))))))
(save-excursion
(goto-char p)
(forward-line -1)
(if (looking-at "^template.*$")
(concat (cbrow--current-line-as-string) "\n"))))
(defun cbrow--found-a-hash (class-max)
(save-match-data
(save-excursion
(re-search-forward "^#.*$" class-max t))))
(progn
(setq *verbose* nil)
*namespace* *class* )
(defun cbrow--found-a-public (class-max)
(save-match-data
(save-excursion
(re-search-forward (if *namespace* "^ public:" "^public:") class-max t))))
(defun cbrow--found-a-private (class-max)
(save-match-data
(save-excursion
(re-search-forward (if *namespace* "^ private:" "^private:") class-max t))))
(defun cbrow--found-a-protected (class-max)
(save-match-data
(save-excursion
(re-search-forward (if *namespace* "^ protected:" "^protected:") class-max t))))
(defun cbrow--found-empty-line (class-max)
(save-match-data
(save-excursion
(re-search-forward "^[ \t]*$" class-max t))))
(defun cbrow--found-a-friend (class-max)
(save-match-data
(save-excursion
(re-search-forward (concat (if *namespace*
"^[ ][ ][ ][ ][ ][ ]friend[ \t]"
"^[ ][ ][ ]friend[ \t]")
".*$") class-max t))
))
(defun cbrow--generate-browser-inner (*class* class-min class-max)
(save-match-data
(save-excursion
(goto-char class-min)
(forward-line -1)
(cbrow--log--simple (cbrow--found-an-outer-template))
(if (string-match "^_*[a-zA-Z][a-zA-Z0-9_]*::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)" *class*)
(setq class-only (substring *class* (match-beginning 1))))
(cbrow--log--complex (concat "class " (if *namespace* (concat *namespace* "::" class-only) *class*)))
(cbrow--log--simple
"---------------------------------------------------------------------------------------\n")
(cbrow--log--complex "{")
(let ((found-friend nil)
(found-method nil)
(found-property nil)
(found-public nil)
(found-private nil)
(found-protected nil)
(found-template nil)
(found-hash nil)
(comment nil)
(min nil))
(while (progn (setq found-friend (cbrow--found-a-friend class-max))
(setq found-method (cbrow--found-a-method class-max))
(setq found-property (cbrow--found-a-property class-max))
(setq found-public (cbrow--found-a-public class-max))
(setq found-private (cbrow--found-a-private class-max))
(setq found-protected (cbrow--found-a-protected class-max))
(setq found-template (cbrow--found-a-template class-max))
(setq found-hash (cbrow--found-a-hash class-max))
(or found-friend
found-method
found-property
found-public
found-private
found-protected
found-template
))
(if (not found-friend) (setq found-friend 1e100))
(if (not found-method) (setq found-method 1e100))
(if (not found-property) (setq found-property 1e100))
(if (not found-public) (setq found-public 1e100))
(if (not found-private) (setq found-private 1e100))
(if (not found-protected) (setq found-protected 1e100))
(if (not found-template) (setq found-template 1e100))
(if (not found-hash) (setq found-hash 1e100))
(setq min (min found-friend
found-method
found-property
found-public
found-private
found-protected
found-template
found-hash
))
(cond
((= min found-friend)
(goto-char found-friend)
(cbrow--log--complex (concat
" "
(if *verbose* "friend:")
(cbrow--trim-string (cbrow--current-line-as-string)))))
((= min found-method)
(let ((method-name nil)
(method-comment nil))
(goto-char found-method)
(setq method-name (cbrow--scan-method))
(setq method-comment (cbrow--scan-comment--this-line))
(cbrow--log--simple method-comment)
(if (eq ?\; (aref method-name (1- (length method-name))))
(cbrow--log--complex (concat " "
(if *verbose* "METHOD NOT HERE:")
(cbrow--trim-string method-name)
) 'not-here)
(cbrow--log--complex (concat " "
(if *verbose* "METHOD HERE:")
(cbrow--trim-string method-name)))
)
))
((= min found-property)
(let ((property-name nil)
(property-comment nil))
(goto-char found-property)
(setq property-name (cbrow--scan-property--this-line))
(setq property-comment (cbrow--scan-comment--this-line))
(cbrow--log--simple property-comment)
(cbrow--log--complex (concat
" "
(if *verbose* "PROPERTY:")
(cbrow--trim-string property-name)
))
))
((= min found-public)
(goto-char found-public)
(setq comment (cbrow--scan-comment--this-line))
(cbrow--log--complex comment)
(cbrow--log--complex "\npublic:"))
((= min found-private)
(goto-char found-private)
(setq comment (save-excursion
(cbrow--scan-comment--this-line)))
(cbrow--log--complex comment)
(cbrow--log--complex "\nprivate:")
)
((= min found-protected)
(goto-char found-protected)
(setq comment (cbrow--scan-comment--this-line))
(cbrow--log--complex comment)
(cbrow--log--complex "\nprotected:")
)
((= min found-template)
(goto-char found-template)
(setq comment (cbrow--scan-comment--this-line))
(cbrow--log--complex comment)
(cbrow--log--complex (cbrow--current-line-as-string)))
((= min found-hash)
(goto-char found-hash)
(setq comment (cbrow--scan-comment--this-line))
(cbrow--log--complex comment)
(cbrow--log--complex (cbrow--current-line-as-string)))
(t
(error "Function cbrow--generate-browser-inner: should never happen")))
)
(re-search-forward (if *namespace* "^[ ][ ][ ]}" "^}") nil t)
(cbrow--log--simple (cbrow--scan-comment--this-line))
(cbrow--log--simple "};\n\n")
(cbrow--level--begin-or-end 1 "END" *class*)
))))
(defun cbrow--line-ptr ()
(save-match-data
(save-excursion
(beginning-of-line)
(if (re-search-forward "LINE:" (point-at-eol) t)
(read-str (buffer-substring-no-properties (point) (save-excursion
(skip-chars-forward "0-9")
(point))))
1e100))))
(defun cbrow--level--begin-or-end (level begin-or-end *class*)
(cbrow--log--simple (concat (make-string (frame-width) ?/) "\n"))
(cbrow--log--simple "///\n")
(cbrow--log--simple (concat "/// CLASS BROWSER LEVEL "
(format "%d" level)
" "
begin-or-end
" : "
*class*
" "
(cadr (assoc *class* cbrow--header-alist))
"\n"
))
(cbrow--log--simple "///\n")
(cbrow--log--simple (concat (make-string (frame-width) ?/) "\n"))
)
(defun cbrow--generate-browser (*class* line-or-method-or-class)
'*class*"*class* *class* (save-match-data
(save-excursion
(setq *namespace* (cbrow--inside-namespace))
(if (get-buffer cbrow--buffer-name)
(kill-buffer cbrow--buffer-name))
(setq cbrow--buffer (generate-new-buffer cbrow--buffer-name))
(unwind-protect
(let ((header nil)
(buf nil)
(extra nil)
(case-fold-search nil)
(found nil)
)
(setq header (cadr (assoc *class* cbrow--header-alist)))
(cond
((not header)
(error "(1) Header file is nil for class %s" *class*))
((not (file-exists-p header))
(error "(2) Header file %s not found for class %s" header *class*))
(t
(setq buf (find-file header))
(goto-char (point-min))
))
(cbrow--level--begin-or-end 1 "BEGIN" *class*)
*class* (let* ((ptr (cdr (assoc *class* cbrow--superclass-alist)))
(len (length ptr)))
(while ptr
(cbrow--log--simple (concat "SUPERCLASS: " (car ptr) "\n"))
(setq ptr (cdr ptr)))
(if (/= len 0)
(cbrow--log--simple "\n")))
(let* ((ptr (cdr (assoc *class* cbrow--subclass-alist)))
(len (length ptr)))
(while ptr
(cbrow--log--simple (concat "SUBCLASS: " (car ptr) "\n"))
(setq ptr (cdr ptr)))
(if (/= len 0)
(cbrow--log--simple "\n")))
(if (string-match "[a-zA-Z0-9_]*::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)" *class*)
(setq class-only (substring *class* (match-beginning 1) (match-end 1)))
(setq class-only *class*))
(setq strobe 0)
(cond
((progn
(goto-char (point-min))
(re-search-forward (concat "^\\(\\([A-Z]+[ \t]+\\)*\\)class[ \t]+"
*class*
"\\([ \t].*[\r\n]\\|[\r\n]+\\){") nil t))
(progn
(setq strobe 1)
(setq *namespace* nil)
(setq extra (buffer-substring-no-properties (match-beginning 1) (match-end 1)))))
((progn
(goto-char (point-min))
(re-search-forward (concat "^[ ][ ][ ]\\(\\([A-Z]+[ \t]+\\)*\\)class[ \t]+"
*class*
"\\([ \t].*[\r\n]\\|[\r\n]+\\)[ ][ ][ ]{") nil t))
(progn
(setq strobe 2)
(setq *namespace* (cbrow--inside-namespace))
(setq extra (buffer-substring-no-properties (match-beginning 1) (match-end 1)))))
((progn
(goto-char (point-min))
(re-search-forward (concat "^\\(\\([A-Z]+[ \t]+\\)*\\)*class*[ \t]+"
class-only
"\\([ \t].*[\r\n]\\|[\r\n]+\\){") nil t))
(progn
(setq strobe 3)
(setq *namespace* nil)
(setq extra (buffer-substring-no-properties (match-beginning 1) (match-end 1)))))
((progn
(goto-char (point-min))
(re-search-forward (concat "^[ ][ ][ ]\\(\\([A-Z]+[ \t]+\\)*\\)class[ \t]+"
class-only
"\\([ \t].*[\r\n]\\|[\r\n]+\\)[ ][ ][ ]{") nil t))
(progn
(setq strobe 4)
(setq *namespace* (cbrow--inside-namespace))
(setq extra (buffer-substring-no-properties (match-beginning 1) (match-end 1)))))
((progn
(goto-char (point-min))
(setq strobe 5)
(setq *namespace* (cbrow--inside-namespace))
(re-search-forward (cond
((and *namespace* *class*)
"^[ ][ ][ ][ ][ ][ ]{")
((or *namespace* *class*)
"^[ ][ ][ ]{")
(t
"^{")) nil t)))
(t
(error "(3) Class %s not found in namespace %s in header file %s" *class* *namespace* header)))
(cbrow--log--simple (concat extra (if (string= extra "") nil "\n")))
(forward-char -1)
(assert (looking-at "{"))
(let ((p1 nil)
(p2 nil))
(setq p1 (point))
(setq p2 (save-excursion
(forward-sexp 1) (point)))
(cbrow--generate-browser-inner *class* p1 p2)
))
(switch-to-buffer cbrow--buffer) <--------- (cond
((numberp line-or-method-or-class)
(let ((orig-line line-or-method-or-class))
(progn
(goto-char (point-max))
(while (and (not (bobp))
(< orig-line (cbrow--line-ptr))) LINE:333 (forward-line -1))
(if (bobp)
(error "(5) Function cbrow--generate-browser: Line %s not found" orig-line)
(setq found t)))
)
)
((stringp line-or-method-or-class)
(let ((orig-method line-or-method-or-class))
(goto-char (point-min))
(re-search-forward "^-+$")
(beginning-of-line)
(forward-line 1)
(re-search-forward (concat "\\($\\|[ \t]\\)" orig-method "(")) (beginning-of-line)
(setq found t)
))
((eq 'class line-or-method-or-class)
(goto-char (point-min))
(re-search-forward (concat "class[ \t]+" *class*) nil t)
(beginning-of-line)
(setq found t)
)
(t (error "(6) Function cbrow--generate-browser: should never happen"))
)
(when (eq (current-buffer) (get-buffer cbrow--buffer))
(switch-to-buffer cbrow--buffer)
(c++-mode)
(use-local-map cbrow--map1)
(read-only-mode 1)
(set (make-local-variable 'truncate-lines) t)
(when (not found)
(goto-char (point-min))
(if (and *namespace* (not (string-match "_*[a-zA-Z][a-zA-Z0-9_]*::_*[a-zA-Z][a-zA-Z0-9_]*" *class*)))
(re-search-forward (concat "^class " *namespace* "::" *class*) nil t)
(re-search-forward (concat "^class " *class* "\\>") nil t))
(beginning-of-line))
(cbrow--message "Level 1")
)))))
(defun cbrow--global--f5 ()
(interactive)
(let (line
line2
*namespace*
*class*
*method*
result
found
namespace-class-method
class-method
class-only
class-2
method-only
args
method-args
class-method-args-quoted
namespace-ps
class-ps
method-ps)
(if (not cbrow--init-done)
(cbrow--init))
(setq *namespace* (cbrow--inside-namespace))
(setq cbrow--file (buffer-file-name (current-buffer)))
(setq cbrow--point (point))
(if (eq major-mode 'c++-mode)
(save-excursion
(setq namespace-ps (cbrow--inside-namespace-p1-and-p2))
(setq class-ps (cbrow--inside-class-p1-and-p2))
(setq method-ps (cbrow--inside-method-p1-and-p2))
(setq *method* (cbrow--inside-method))
*method* (setq *class* (cbrow--inside-class))
*method* *method*
*method* (when *method*
(when (string-match (concat "\\(^\\|[ \t\r\n]\\)" cbrow--inside-method--regexp "(") *method*)
(setq namespace-class-method (substring *method* (match-beginning 3) (match-end 3)))
(when (string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\([~a-zA-Z0-9_]+\\)" *method*)
(setq class-method (concat (substring *method* (match-beginning 1) (match-end 2))))))
(when (string-match "\\(^\\|[ \t\r\n]\\)\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\([~a-zA-Z0-9_]+\\)" *method*)
(setq class-method (substring *method* (match-beginning 2) (match-end 3)))
(setq class-only (substring *method* (match-beginning 2) (match-end 2))))
(when (string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*::\\)\\([~a-zA-Z0-9_]+\\)" *method*)
(setq method-only (substring *method* (match-beginning 2) (match-end 2))))
*class* *class* *class* *class*
(when (and (not *class*) class-method (string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::" class-method))
*class* (setq class-only (substring class-method (match-beginning 1) (match-end 1))))
)
(cond
((save-excursion
(beginning-of-line)
(looking-at "^ *\\([A-Z]+ \\)*class _*[a-zA-Z][a-zA-Z0-9_]*"))
(setq class-2 (cbrow--inside-class))
(when (and class-2 456)
(cbrow--generate-browser class-2 'class)
(goto-char (point-min))
(re-search-forward "class " nil t)
(beginning-of-line)
))
(*method*
(cond
((and *namespace*
*class*
(string-match (concat "\\(" *namespace* "\\)::\\(" *class* "\\)::\\(.*\\)(") *method*))
(setq class-method (substring *method*
(match-beginning 2)
(match-end 3)))
(setq method-only (substring *method*
(match-beginning 2)
(match-end 2))))
((and *class* (string-match (concat "\\(" *class* "\\)::\\(.*\\)(") *method*))
(setq class-method (substring *method*
(match-beginning 1)
(match-end 2)))
(setq method-only (substring *method*
(match-beginning 2)
(match-end 2))))
((string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\([~a-zA-Z0-9_]+\\)(" *method*)
(setq *namespace* (substring *method*
(match-beginning 1)
(match-end 1)))
(setq *class* (substring *method*
(match-beginning 1)
(match-end 2)))
(setq class-only (substring *method*
(match-beginning 2)
(match-end 2)))
(setq class-method (substring *method*
(match-beginning 1)
(match-end 2)))
(setq method-only (substring *method*
(match-beginning 3)
(match-end 3)))
)
((string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\([~a-zA-Z0-9_]+\\)(" *method*)
(setq *class* (concat *namespace*
(substring *method*
(match-beginning 1)
(match-end 1))))
(setq class-only (substring *method*
(match-beginning 1)
(match-end 1)))
(setq class-method (substring *method*
(match-beginning 1)
(match-end 2)))
(setq method-only (substring *method*
(match-beginning 2)
(match-end 2)))
))
(when (string-match "(.*)" *method*)
(setq args (substring *method*
(match-beginning 0)
(match-end 0)))
(setq method-args (concat method-only args)))
(when (and (not *class*) (not (string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)" *method*)))
(cbrow--message "Cannot find a class for a function"))
(if (and (not *class*) (string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)" *method*))
(setq *class* (substring *method* (match-beginning 1) (match-end 1))))
(when *class*
(if 'cat (cbrow--generate-browser *class* 'class))
(progn
(switch-to-buffer cbrow--buffer-name)
(goto-char (point-min))
(re-search-forward (if (= (aref method-only 0) ?~)
(regexp-quote method-args)
(concat "\\<" (regexp-quote method-args))))
(beginning-of-line)
)
)
)
((setq class-2 (cbrow--inside-class))
(if 456 (cbrow--generate-browser class-2 (cbrow--what-line)))
(setq found t)
)
(*class*
(if 789 (cbrow--generate-browser (if *namespace*
(concat *namespace* "::" class-only)
*class*) 'class))
(switch-to-buffer cbrow--buffer-name)
(goto-line (point-min))
(re-search-forward "^class" nil t)
(forward-line 2)
(re-search-forward method-only nil t)
(beginning-of-line)
(debug "sausages")
)
(t
*class* *method* (setq result (cbrow--inside-method))
(when (string-match "^\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\([a-zA-Z0-9]+\\)::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)$" result)
(setq *namespace* (substring result (match-beginning 1) (match-end 1)))
(setq *class* (substring result (match-beginning 2) (match-end 2)))
(setq *method* (substring result (match-beginning 3) (match-end 3)))
)
(when (string-match "^\\([a-zA-Z0-9]+\\)::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)$" result)
(setq *class* (substring result (match-beginning 1) (match-end 1)))
(setq *method* (substring result (match-beginning 2) (match-end 2)))
)
(when (and *class* *method*)
(set-buffer (find-file (cadr (assoc *class* cbrow--header-alist))))
(setq meth (cbrow--trim-return-value *method*))
(re-search-forward meth nil t)
(beginning-of-line)
(if 1230 (cbrow--generate-browser *class* meth))
(debug "Tom Clancy")
)
)
)
)
(if 123 (cbrow--map1--f5))
)))
(defun cbrow--map1--enter ()
(interactive)
(let (*class* class-only *namespace* file line)
(setq *class* (cbrow--inside-class))
(setq *namespace* (cbrow--inside-namespace))
(d-quote if (save-excursion
(re-search-forward "//LINE:" (point-at-eol) t))
(setq line (save-excursion
(re-search-forward "//LINE:\\([0-9]+\\)" (point-at-eol) t)
(read-str (buffer-substring-no-properties (match-beginning 1) (match-end 1))))))
(cond
((save-excursion
(beginning-of-line)
(looking-at "^\\(SUPERCLASS\\|SUBCLASS\\): "))
(save-excursion
(beginning-of-line)
(skip-chars-forward "A-Z") (skip-chars-forward ":")
(skip-chars-forward " \t")
(setq *class* (buffer-substring-no-properties (point) (save-excursion
(skip-chars-forward (concat cbrow--identifier--chars ":"))
(point))))
(if (string-match "^_*[a-zA-Z][a-zA-Z0-9_]*::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)$" *class*)
(setq class-only (substring *class* (match-beginning 1) (match-end 1))))
(setq file (cadr (assoc *class* cbrow--header-alist)))
(if file
(cbrow--generate-browser *class* 'class)
(setq file (cadr (assoc class-only cbrow--header-alist)))
(if file
(cbrow--generate-browser class-only 'class)
(if 'nerd (error "No header file for class %s" *class*))))
*class* ))
((save-excursion
(re-search-forward "=[ \t]*null;" (point-at-eol) t))
(cbrow--message "Cannot browse a pure virtual function"))
((save-excursion
(re-search-forward "NOT HERE!" (point-at-eol) t))
(let ((method nil)
(method-signature nil)
(method-only nil)
(class-method nil)
(namespace-class-method nil)
(class-only nil)
(file nil))
(progn
(setq method-signature (cbrow--trim-string (cbrow--current-line-as-string)))
(if (string-match "\\(operator[ \t]+[^;]+\\)[ \t](" method-signature)
(setq method-only (substring method-signature (match-beginning 1) (match-end 1)))
(assert (string-match "\\([^ ]*\\)(" method-signature))
(setq method-only (substring method-signature
(match-beginning 1)
(match-end 1)))
(assert *class*)
(setq method (concat *class* "::" method-only))
*class* *class*
(when (string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*::\\)?\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)" *class*)
(setq class-only (substring *class* (match-beginning 2) (match-end 2)))
*class* )
(setq class-method (concat class-only "::" method-only))
(if *namespace*
(setq namespace-class-method (concat *namespace* *class* "::" method-only))
(setq namespace-class-method class-method))
(progn
(setq file (cadr (assoc (if *namespace* (concat *namespace* "::" class-only) *class*)
cbrow--header-alist)))
(if (cbrow--find-file file *class*)
'foo
(setq file (cadr (assoc (if *namespace* (concat *namespace* "::" class-only) class-only)
cbrow--footer-alist))))
(when (not (cbrow--find-file file *class*))
(d-beeps "Tags file search")
(if (string-match "\\(friend\\|operator\\)" method-signature)
(tags-search method-only)
(tags-search class-method))
(beginning-of-line)))))))
((save-excursion
(re-search-forward "//LINE:" (point-at-eol) t))
(let ((what-line nil)
(file nil))
(save-excursion
(re-search-forward "//LINE:" (point-at-eol) t)
(setq what-line (read (buffer-substring-no-properties (point)
(save-excursion
(skip-chars-forward "0-9")
(point)))))
(setq file (cadr (assoc *class* cbrow--header-alist)))
)
(if (not file)
(if 123 (error "Variable file is nil")))
(if (not (file-exists-p file))
(if 456 (error "Header file %s for class %s does not exist" file *class*)))
(if 'ibm-computers (find-file file))
(goto-line what-line)
(recenter)
(message "Here it is in the header file")
(read-only-mode -1)
))
(t
(beep)
)
)
)
)
(defun cbrow--find-file (file *class*)
(let ((found nil)
(found-namespace nil)
(*namespace* nil)
line
line2)
(cond
((not file)
(setq found nil))
((not (file-exists-p file))
(setq found nil))
((progn
(find-file file)
(goto-char (point-min))
(when (string-match "([^()]*)" method-signature)
(setq args (substring method-signature (match-beginning 0) (match-end 0)))
(setq args (cbrow--change-args args))
)
(when (string-match "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)" *class*)
(setq namespace-only (substring *class* (match-beginning 1) (match-end 1)))
(setq class-only (substring *class* (match-beginning 2) (match-end 2)))
)
(setq class-method (concat (if class-only (concat class-only "::")) method-only))
(setq class-method-args (concat (if class-only (concat class-only "::")) method-only args))
(setq class-method-args-quoted (regexp-quote class-method-args))
(cond
((string= method-only class-only)
(while (and (not found) (re-search-forward (concat class-method "(") nil t))
(setq line (cbrow--scan-method))
(setq line2 (cbrow--trim-return-value line))
(when (string-match "([^()]*)" method-signature)
(setq args (substring method-signature (match-beginning 0) (match-end 0)))
(setq args (cbrow--change-args args))
)
(when (string-match class-method-args-quoted line2)
(setq found t)))
(beginning-of-line)
found)
((eq (aref method-only 0) ?~)
(re-search-forward (concat class-method "("))
(beginning-of-line)
(setq found t)
)
(t
(progn
(setq found nil)
(while (and (not found) (re-search-forward (concat class-method "(") nil t))
(setq line (cbrow--scan-method))
(setq line (cbrow--trim-return-value line))
(setq found-namespace t)
(beginning-of-line)
(if (progn
(beginning-of-line)
(re-search-forward (concat *namespace* "::") (point-at-eol) t))
(setq found-namespace t)
(setq found-namespace nil))
(when (string= *namespace* (cbrow--inside-namespace))
(setq found-namespace t))
(if (not found-namespace) (debug "Anchor milk"))
(when found-namespace
(when (string-match class-method-args-quoted line)
(setq found t))))
(beginning-of-line))))
)))
(if (not found)
(kill-buffer)
(message "Here it is in file %s" file))
found))
(defun cbrow--map1--f5 ()
(interactive)
(let* ((list nil)
(ptr cbrow--header-alist)
(*class* (cbrow--inside-class))
(result nil))
(assert (boundp '*class*))
(while ptr
(setq list (cons (caar ptr) list))
(setq ptr (cdr ptr)))
(progn
(if (get-buffer cbrow--buffer-name)
(kill-buffer cbrow--buffer-name))
(switch-to-buffer (generate-new-buffer cbrow--buffer-name))
(c++-mode)
(cbrow--level--begin-or-end 2 "BEGIN" nil)
(setq ptr list)
(while ptr
(goto-char (point-max))
(let (class)
(setq class (car ptr))
*class* (setq *template* (cadr (assoc class cbrow--template-list))))
(let* ((c (car ptr))
(r (cadr (assoc c cbrow--rest-alist))))
(insert (concat "class " (if *template* *template* c)))
(insert (if r (concat " : " r "\n") "\n"))
)
(backward-delete-char 1)
(insert "\n")
(setq ptr (cdr ptr)))
(let ((sort-fold-case t))
(sort-lines nil (save-excursion (goto-char (point-min))
(re-search-forward "class" nil t)
(forward-line -1)
(point)) (point-max))
)
(cbrow--level--begin-or-end 2 "END" nil)
(goto-char (point-min))
(re-search-forward "class")
(if (not *class*)
(progn
(cbrow--message "Class is nil")
)
(if (string-match (concat "^" *namespace* "::") *class*)
(setq result *class*)
(setq result (concat (if *namespace* (concat *namespace* "::")) *class*)))
(goto-char (point-min))
(let ((search (concat "class[ \t]+" result "\\([ \t<>]\\|$\\)")))
(if (not (re-search-forward search nil t))
(error (format "*** Cbrow Search failed: %s" *class*))
(cbrow--message "Level 2"))))
(beginning-of-line)
(use-local-map cbrow--map2)
(read-only-mode 1)
))
)
(defun cbrow--map2--enter ()
(interactive)
(save-excursion
(let (*class* class-only)
(beginning-of-line)
(cbrow--skip-word "class")
(skip-chars-forward " \t")
(cond
((looking-at "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)")
(setq *namespace* (buffer-substring-no-properties
(match-beginning 1)
(match-end 1)))
(setq *class* (buffer-substring-no-properties
(match-beginning 1)
(match-end 2)))
(setq class-only (buffer-substring-no-properties
(match-beginning 2)
(match-end 2))))
((looking-at "\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)")
(setq *class* (buffer-substring-no-properties (match-beginning 1)
(match-end 1))))
)
*class* *class* *class* *class* (if 'banana (cbrow--generate-browser *namespace* *namespace* *class* *class* *class*
'class))
)
)
)
(defun cbrow--map2--f5 ()
(interactive)
(if (not cbrow--file)
(bury-buffer)
(find-file cbrow--file)
(goto-char cbrow--point))
(cbrow--message "Back to editing")
)
(defvar cbrow--map1 (make-keymap))
(define-key cbrow--map1 "\C-m" 'cbrow--map1--enter)
(define-key cbrow--map1 [f5] 'cbrow--map1--f5)
(global-set-key [f5] 'cbrow--global--f5)
(defvar cbrow--map2 (make-keymap))
(define-key cbrow--map2 "\C-m" 'cbrow--map2--enter)
(define-key cbrow--map2 [f5] 'cbrow--map2--f5)
:test(defun cbrow--init--header-alist ()
(let* ((search-list (reverse cbrow--headers))
(ptr search-list))
(setq cbrow--header-alist nil)
(setq cbrow--template-list nil)
(while ptr
(let ((auto-mode-alist (cons '("" . fundamental-mode) auto-mode-alist)))
(save-buffer (find-file-read-only (car ptr))))
(let ((class-list nil))
(goto-char (point-min))
(while (re-search-forward "^[ ][ ][ ]\\([A-Z]+[ \t]+\\)?class" nil t)
(if (setq *namespace* (cbrow--inside-namespace))
(when (progn
(forward-line 1)
(looking-at "^[ ][ ][ ]{"))
(forward-line -1)
(skip-chars-forward " \t")
(skip-chars-forward "A-Z")
(skip-chars-forward " \t")
(cbrow--skip-word "class")
(skip-chars-forward " \t")
(let ((*class* (buffer-substring-no-properties
(point) (save-excursion
(skip-chars-forward (concat cbrow--identifier--chars ":"))
(point))))
(template (buffer-substring-no-properties
(save-excursion
(forward-line -1)
(beginning-of-line)
(point))
(save-excursion
(forward-line -1)
(end-of-line)
(point)))))
*class* (if (string-match "template<class \\(_*[a-zA-Z][a-zA-Z0-9_]*\\)>" template)
(progn
(setq template (concat *class*
"<"
(substring template (match-beginning 1) (match-end 1))
">")))
(setq template nil))
(setq cbrow--template-list (cons (list *class* template) cbrow--template-list))
(setq class-list (cons (concat (if *namespace* (concat *namespace* "::"))
*class*) class-list))))))
(goto-char (point-min))
(while (re-search-forward "^\\([A-Z]+[ \t]+\\)?class" nil t)
(when (progn
(forward-line 1)
(looking-at "^{"))
(forward-line -1)
(skip-chars-forward "A-Z")
(skip-chars-forward " \t")
(cbrow--skip-word "class")
(skip-chars-forward " \t")
(let ((class-only (buffer-substring-no-properties
(point) (save-excursion
(skip-chars-forward (concat cbrow--identifier--chars ":"))
(point))))
(template (buffer-substring-no-properties
(save-excursion
(forward-line -1)
(beginning-of-line)
(point))
(save-excursion
(forward-line -1)
(end-of-line)
(point)))))
(if (string-match "template<class \\(_*[a-zA-Z][a-zA-Z0-9_]*\\)>" template)
(progn
(setq template (concat class-only
"<"
(substring template (match-beginning 1) (match-end 1))
">")))
(setq template nil))
(setq cbrow--template-list (cons (list class-only template) cbrow--template-list))
*class* *class* *class* *class* *class* (setq class-list (cons class-only class-list))
)))
(let ((ptr2 class-list))
(setq ptr2 class-list)
(while ptr2
(setq cbrow--header-alist (cons (list (car ptr2) (car ptr)) cbrow--header-alist))
(setq ptr2 (cdr ptr2)))))
:test (kill-buffer (find-file (car ptr)))
(setq ptr (cdr ptr)))
cbrow--header-alist)
)
(defun cbrow--init--footer-alist ()
(let ((ptr cbrow--header-alist))
(setq cbrow--footer-alist nil)
(while ptr
(let ((*class* (caar ptr))
(header-file (cadar ptr)))
(if (string-match "^\\(.*\\)\\.hh$" header-file)
(let ((footer-file (concat (substring header-file (match-beginning 1) (match-end 1)) cbrow--footer)))
(setq cbrow--footer-alist (cons (list *class* footer-file) cbrow--footer-alist))))
(setq ptr (cdr ptr))))
(setq cbrow--footer-alist (reverse cbrow--footer-alist))
)
)
(defun cbrow--split-string (string)
(let* ((string (format "%s%c" string ? ))
(len (length string))
(i 0)
(buf "")
(answer-list nil))
(while (< i len)
(let ((ch (aref string i)))
(if (and (not (= ch ? ))
(not (= ch ?\t))
(not (= ch ?,)))
(setq buf (format "%s%c" buf ch))
(setq answer-list (cons buf answer-list))
(setq buf "")))
(incf i))
(setq answer-list (delete "" answer-list))
(setq answer-list (delete "public" answer-list))
(setq answer-list (delete "private" answer-list))
(setq answer-list (delete "protected" answer-list))
(reverse answer-list)
)
)
(defun cbrow--init--superclass-alist ()
(let ((ptr cbrow--header-alist))
(setq cbrow--superclass-alist nil)
(setq cbrow--rest-alist nil)
(while ptr
(let ((*class* (caar ptr))
(file (cadar ptr))
(rest nil)
(superclasses nil)
(class-only nil))
(if (string-match "\\(<[a-zA-Z0-9]+>\\)" *class*)
(setq *class* (substring *class* 0 (match-beginning 0))))
(if (string-match "^[a-zA-Z0-9_]*::\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)$" *class*)
(setq class-only (substring *class* (match-beginning 1) (match-end 1)))
(setq class-only *class*))
(save-excursion
(let ((auto-mode-alist (cons '("" . fundamental-mode) auto-mode-alist)))
(save-buffer (find-file-read-only file))) (goto-char (point-min))
(cond
((re-search-forward (concat "^\\([A-Z]+[ \t]+\\)?class[ \t]+" class-only "\\($\\|[ \t][^;\n\r]*$\\)") nil t)
(beginning-of-line)
(forward-line 1)
(assert (looking-at "{"))
(forward-line -1))
((re-search-forward (concat "^ \\([A-Z]+[ \t]+\\)?class[ \t]+" class-only "\\($\\|[ \t][^\n\r;]*$\\)") nil t)
(beginning-of-line)
(forward-line 1)
(skip-chars-forward " \t")
(if 123 (assert (looking-at "{")))
(forward-line -1)
(beginning-of-line)
)
((re-search-forward (concat "^\\([A-Z]+[ \t]+\\)?class[ \t]+" *class* "\\($\\|[ \t][^;\n\r]*$\\)") nil t)
(beginning-of-line)
(forward-line 1)
(assert (looking-at "{"))
(forward-line -1))
((re-search-forward (concat "^ \\([A-Z]+[ \t]+\\)?class[ \t]+" *class* "\\($\\|[ \t][^\n\r;]*$\\)") nil t)
(beginning-of-line)
(forward-line 1)
(skip-chars-forward " \t")
(if 123 (assert (looking-at "{")))
(forward-line -1)
(beginning-of-line)
)
(t
(error "(123) Class %s not found in file %s" *class* file)))
(skip-chars-forward " \t")
(skip-chars-forward "A-Z")
(skip-chars-forward " \t")
*class*
(assert (looking-at "class"))
(cbrow--skip-word "class")
(skip-chars-forward " \t")
(assert (looking-at "\\(\\(_*[a-zA-Z][a-zA-Z0-9_]*::\\)?\\(_*[a-zA-Z][a-zA-Z0-9_]*\\)\\)"))
*class* (skip-chars-forward "a-zA-Z0-9_:")
(if (re-search-forward ":" (point-at-eol) t)
(progn
(setq *namespace* (cbrow--inside-namespace))
(skip-chars-forward " \t")
(let* ((rest (buffer-substring-no-properties (point) (point-at-eol)))
(superclasses (cbrow--split-string rest)))
(defun add-prefix (x)
(concat (if *namespace* (concat *namespace* "::")) x))
(setq superclasses (mapcar 'add-prefix superclasses))
*namespace* *namespace* *namespace* *namespace* *namespace* *namespace* (setq cbrow--superclass-alist (cons (cons *class* superclasses) cbrow--superclass-alist))
(setq cbrow--rest-alist (cons (list *class* rest) cbrow--rest-alist))
*class* *class* )
)
*class* )
(kill-buffer (find-file file))
))
(setq ptr (cdr ptr))))
)
(defun cbrow--init--subclass-alist ()
(let ((ptr cbrow--superclass-alist))
(setq cbrow--subclass-alist nil)
(while ptr
(let ((ptr2 nil)
(subclass nil))
(setq ptr2 (car ptr)) (setq subclass (car ptr2))
(setq ptr2 (cdr ptr2)) (while ptr2
(let* ((superclass (car ptr2))
(a (assoc superclass cbrow--subclass-alist)))
(if (not a)
(setq cbrow--subclass-alist (cons (list superclass subclass)
cbrow--subclass-alist))
(setcdr (last a) (list subclass))))
(setq ptr2 (cdr ptr2))))
(setq ptr (cdr ptr))))
)
(defvar cbrow--footer ".cc")
(defvar cbrow--init-done nil)
(defun cbrow--init ()
(interactive)
(let (list1 list2 list3 list4 list5)
(setq list1 (directory-files "~/lisp++-projects/2006/Tritus-II/" t "\\.hh$"))
(setq list2 (directory-files "~/lisp++-projects/2006/Tritus-II/level-editor/" t "\\.hh$"))
(setq list3 (directory-files "~/lisp++-projects/2006/gui-menus/" t "\\.hh$"))
(setq list4 (directory-files "~/lisp++-projects/2006/gui-widgets/" t "\\.hh$"))
(setq list5 (directory-files "~/lisp++-projects/2006/libd/" t "\\.hh$"))
(setq cbrow--headers (append list1 list2 list3 list4 list5)))
(cbrow--init--header-alist) (cbrow--init--footer-alist) (cbrow--init--superclass-alist) (cbrow--init--subclass-alist) (setq cbrow--init-done t)
(message "cbrow--init done")
)
(provide 'cbrow)