Navigating C/C++ functions

I use the following key mappings to go to the previous/next top-level function in C/C++ files:

define-command -override go-to-function-begin %@
    execute-keys ';<a-/>^[^ \t\n#}]<ret>l[p'
    try %!
        execute-keys 'f{'
    ! catch %!
        execute-keys '<a-i>p'
    !
    execute-keys '<a-x><a-:><a-;>'
@

# select surrounding (or next) function
define-command -override select-function %@
    # go left twice, in case cursor is on newline immediately following closing brace
    execute-keys 'hh'

    # search for end of function (and any following empty lines)
    execute-keys '/^\};?\n+<ret>'

    # extend to top of function
    execute-keys '<a-:><a-;>M{p'

    execute-keys '<a-:>'
@

define-command -override extend-function %@
    execute-keys 'Z: select-function<ret><a-z>u'
@

map global normal '<up>' ': go-to-function-begin<ret>'
map global normal '<down>' ': select-function<ret>'
map global normal '<s-down>' ': extend-function<ret>'

They only work for functions that are not indented. So they don’t work for functions nested inside a class definition.