|
|
Supercool. Have to test it. So far I came with this solution:
(defun cw-find-function-header (arg)
"This function browses the C++ code and tries to find a point, where
the function body declaration starts. A very tricky function, uses cc-
mode
syntax checker which is used for indentation. We call a function which
guesses the syntax of the line currently under the position of the
cursor. If
successfull, this function given information about what syntax block
it is, and the tells the point where the block start. If we move our
pointer to
that position and try to do the same trick, we get an information for
the block preceding the one the cursor is pointing to. This allows us
to traverse
the code block. We look for special block called `defun-open'. This
one identifies the opening block of the function, and the position of
the block
is directing at the very beginning of the function declaration.
There is however a nasty bug. The syntax analyser apparently works
over lines and does not hint in what portion of the block we are. This
creates a
recognition error in cases where defun-open is not at a single line
within the function. The error behavior is, that such function is
skipped and another
preceding (if exists) function call is tried. This must be somehow
refurbished, but for the moment no idea how "
(interactive "P")
;; this is walk look to find defun-open (noone says that it will
find any, or it will find the one of the function
;; we are currently in
(while
(progn
(let* ((pos) (elem) (c-parsing-error nil)
(syntax (if (boundp 'c-syntactic-context)
;; Use `c-syntactic-context' in the same way as
;; `c-indent-line', to be consistent.
c-syntactic-context
(c-save-buffer-state nil
(c-guess-basic-syntax)))))
(if (not (consp arg))
(progn
(message "Syntactic analysis: %s" syntax)
;; get first element from the possible syntax stuff
(setq elem (pop syntax))
;; now check whether we can get a position
(if (setq pos (c-langelem-pos elem))
;; if so, go there
(goto-char pos)
;; if not, throw everything as without suggestion of another
syntactic element we cannot find function
(throw 'abort "ERROR: Template aborted - c++ mode syntactic
checker did not find a block start, try different location")
))
(throw 'abort "ERROR: Template aborted - unknown syntax structure
in core"))
;; now comparison whether this is the function declaration.
(not (eq (car elem) 'defun-open))
))))
It works, however functions like:
bool GL_line::containsPt (const Q_milsCoordinates& pt, const
Q_milsRectangle &selection) {Q_milsCoordinates
q_lefttop(selection.getLeftTop()); Q_milsCoordinates
q_rightbottom(selection.getRightBottom());return ((q_lefttop.x() <=
pt.x()) && (q_rightbottom.x() >= pt.x()) && (q_lefttop.y() >= pt.y())
&& (q_rightbottom.y() <= pt.y())); }
remain undetected :)
thanks
d.
|
|