Tags for variable and function with the same name


 
Thread Tools Search this Thread
Top Forums Programming Tags for variable and function with the same name
# 1  
Old 05-03-2013
Tags for variable and function with the same name

I ran into a slight problem with vi jumping to a variable definition and not function when both have the same name.

Does anybody know if I can influence ctags to give preference to function over the variable?

Details of my setup:

in $MYLIB/myedi.h I have a struct with
Code:
short procname

in it.

in $SHLIB/mycode.c I have a function procname (old, new, off_days) { ... }

in $MYCODE directory I have a bunch of .c and .h files, the makefile that builds an executable and updates tags like this
Code:
 
ctags $MYCODE/*.[ch] $MYLIB/*.[ch] $SHLIB/*.[ch]

The ctags is
Code:
 
$ ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Dec 10 2012, 15:42:51
  Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex

The resulting tags file has following:
Code:
 
procname        ../mylib/edi.h      /^      short          procname;\/*                             *\/$/;" m       struct:__anon35
procname        ../shlib/mycode.c /^procname(old, new, off_days)$/;"f

So, when in vi (vim 7.0) I press ctrl-] (vi's jump to command) I am landing in the mylib/edi.h, but my intesion is to jump to the function instead.

Any ideas would be appreciated.
# 2  
Old 05-03-2013
I haven't looked at the vim code, but I believe that when you have multiple entries in your ctags file with the same tag, the one you'll go to with the vi ctl-] command varies depending on what else is in the ctags file. (I.e., you won't always go to the first matching definition found in the ctags file.)

One thing I used to do when ctl-] took me to the wrong entry was to edit the crags file (:e ctags), search for the matching entries (:g/^tag/p), and then edit the file that contained the tag I wanted. (The entry in the ctags will will give you both the filename and the line or search pattern in that file you need to get to the entry you want.)

You can also manually edit the ctags file to only contain function names (or at least to remove the entries with duplicate names that you are least likely to want to jump to in vi).

Hope this helps.
These 2 Users Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass variable from one function to another function?

updateEnvironmentField() { linewithoutquotes=`echo $LINE | tr -d '"'` b() } I want to pass variable named $linewithoutquotes to another method called b(), which is called from updateEnvironmentField() method. How to do the above requirement with shell script (1 Reply)
Discussion started by: pottic
1 Replies

2. Shell Programming and Scripting

Passing variable value in a function to be used by another function

Hello All, I would like to ask help from you on how to pass variable value from a function that has been called inside the function. I have created below and put the variables in " ". Is there another way I can do this? Thank you in advance. readtasklist() { while read -r mod ver... (1 Reply)
Discussion started by: aderamos12
1 Replies

3. Shell Programming and Scripting

function for variable files

hi all this is my function #! /bin/sh awk '/ Type/ { print "m;" $4 } /IDf/ {print $3 } /IuSac/ { print $3 } /IuSac/ { print $1 }' / IBM.txt |tr '\n' ';'| perl -pi -e 's/;m//g'|cut -d ";" -f 2-5 ' >> 2m 1) i wanna make it to save output of awk in a file named by date in order not to... (3 Replies)
Discussion started by: teefa
3 Replies

4. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

Hello again :) Am currently trying to write a function which will delete a record from a file. The code currently looks as such: function deleteRecord() { clear read -p "Please enter the ID of the record you wish to remove: " strID ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

5. UNIX for Dummies Questions & Answers

function not see variable in script

Hi Forum Can anyone tell me whats wrong with my script. What i want to do read in values from a input file using a while loop then taking that input from the file into a function that i created. Every time i execute the script it goes through the while loop but the function doesn't see the... (10 Replies)
Discussion started by: ShinTec
10 Replies

6. Shell Programming and Scripting

Variable value not retaining outside function

Hi All, As per my understanding, value of variable is retained outside function. But the value of array myarrayDriver is not retained outside function. Could you please tell the reason for the same.. code: readingConfigFile() { search_keyword="$1" i=0 for pointer in $(cat... (7 Replies)
Discussion started by: ajincoep
7 Replies

7. UNIX for Dummies Questions & Answers

Calling a function through a variable

Hey folks, I'm pretty new to unix programming. I was trying to get something to work but it's not doing what I expected. #!/bin/ksh . ./functions.sh STRING=function_1 FUNCTION="$STRING" RETURN=eval $FUNCTION echo "value of $FUNCTION function is: $RETURN" All i'm... (5 Replies)
Discussion started by: Irrational
5 Replies

8. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

9. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

10. UNIX for Dummies Questions & Answers

passing variable to function

Hi, I am trying to sum up numbered columns and in order to tidy up the program I have wrote a function to do the adding of some numbers. I have a problem though with passing a variable to the function in the UNIX bash shell. The function only gives the first number in the variable list and does... (4 Replies)
Discussion started by: Knotty
4 Replies
Login or Register to Ask a Question