Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Many modern IDEs provide the ability to jump to the function declaration by using a simple shortcut or special mouse click on a function call. This is the one thing that stops TextMate from being my one IDE to rule them all.

So far I find TextMate great for web development and scripting, but doing large scale C++ or Java development on it can feel a little handicapped.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

Here's how to do it in TextMate (from Google cache):

Many IDEs have the capability to 'jump' to a function declaration within the project you are working in. This is how to do it in TextMate. Assuming you understand bundles the Bash script below should be placed in a Command with output set to Show As Tool Tip, then finally picking the key combination you want.

Once ready simply press the key combination while the Caret is placed over your function. The script below will iterate through PHP related files look for the declaration, then opening a TextMate document at the proper line. When this script fails a tooltip mention so will be displayed.

FUNC="$TM_CURRENT_WORD"
DIR="$TM_PROJECT_DIRECTORY"
OUTPUT=''

FILES=(`find "$DIR" -type f | egrep '\.(module|inc|php|engine|install)$'`)

#
# Look for a function declaration within a files contents.
#
# <file> <function>
#
function lookup_function {
  local line=`nl -b a "$1" | grep 'function '"$2"'(' | awk '{print $1}'`
  if [[ "$line" -gt 0 ]]; then
    mate "$1" -l "$line"
    exit 0
  fi
}

# Iterate files
for (( i=0; i < ${#FILES[*]}; i++)); do
  file="${FILES[${i}]}"
  lookup_function "$file" "$FUNC"
done

# Nothing found
echo 'Function '${FUNC}' was not found within the current project.'

Also, Check this out:

http://www.cocoabits.com/TmCodeBrowser/

share|improve this answer

I modified ghoppe's script to work for Python class & function definitions (also runs a little faster):

FUNC="$TM_CURRENT_WORD"
DIR="$TM_PROJECT_DIRECTORY"
OUTPUT=''

# Define the class or function definition string that we're looking for.
FUNCDEF='(def|class) '$FUNC

# Find all files that contain FUNCDEF
FILES=(`egrep "$FUNCDEF" $DIR/* -r -l --include=*.py`)

#
# Look for a function declaration within a files contents.
#
# <file>
#
function lookup_function {
    local line=`nl -b a "$1" | egrep "$FUNCDEF" | awk '{print $1}'`
    if [[ "$line" -gt 0 ]]; then
      # echo 'Jumping to --> '$1':'$line
      mate "$1" -l "$line"
      exit 0
    fi
}

# Iterate files
for file in ${FILES[@]}; do
    echo $file
    lookup_function "$file"
done

# Nothing found
echo 'Function '${FUNC}' was not found within the current project.'
share|improve this answer

While TextMate has lexical formatting (bolding, italics, coloring, etc.) it doesn't have a true grasp of the actual code which you are typing in it. In order to do more complicated things like you are wanting, TextMate would need to do another type of analysis in addition to the formatting which is getting closer to a compiler.
From what I know TextMate doesn't support this functionality right now.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.