views:

194

answers:

6

I feel like I often name files in such a way that my computer constantly beeps while I program because the tab completion is ambiguous. Before doing a lot of Unix programming, I tended to name related files with the same prefix to indicate their relation. Now I must re-think my approach to folder and file structures and names to program more effectively.

What heuristics or rules do you apply when programming to simplify tab completion? Do you use any tools to make tab completion smoother (e.g., emacs icicles)?

EDIT: Wow, thanks for the fantastic insights. I think every possible weakspot of mine was accounted for in the answers. I accepted the one that seems like the best productivity improvement, although they're all worth reading.

+1  A: 

I must admit that I names my files without regard to tab completion and instead adjust my urge to hit tab until I know that I have typed enough characters to not get tab-silly.

Don
+6  A: 

I've generally worked on projects where related files are all in the same directory, and the file names themselves are specialized to indicate their contents.

Of course, this begs the question, why are you doing tab completion on file names? If you're perusing source code, there are TAGS, CEDET, and a plethora of other utilities that will let you bypass the file name and jump directly the the function/variable you're really after.

It all depends on what you're really trying to do, and finding a particular file is usually the means to a different end.

Trey Jackson
This. Overloading naming to describe relationship is rarely the best way to go.
dmckee
Yup, and "module_part1.ext, module_part2.ext, ..." isn't any shorter than "module/part1.ext, module/part2.ext, ...". (It's only one character if you use CamelCase, and the tab completion will give you the slash anyway!)
Jefromi
A: 

I tend to go with whatever makes sense for the organisation of the code, not tab completion - this can vary depending on the code in question, so it's hard to give a direct answer, but use of proper sub-directories does make life easier. I agree with Don.

Instead, I navigate sources using tools like find . -name {expr} (file names), grep -r {expr} * (function defs, protos and usage) and combinations thereof. It's possible to write shell scripts to effectively do find/replace operations using sed i 's/find/replace' across your entire source tree. I have a little folder in my ~/ on the path that provides a few useful scripts like this.

I combine this with IDEs like Eclipse for editing, or VIM, depending on what I'm doing. I like both equally, really, as I use both for different purposes.

Regarding Emacs, I've tried it, I don't like it. It's far too big and complicated and I've got better things to do than learn how to use it (ok let's stop there before we start a "real programmers use..." discussion). So I can't comment on the Emacs tool you've linked to. I guess try it and see if it helps.

Ninefingers
I used to use ctags for navigation to other files, but lately I've been finding http://betterthangrep.com/ "fast enough" on my projects. `ack -G expr` for filenames, `ack expr` for searching content, and `:set grepprg=ack` in Vim makes life awesome.
ephemient
I can understand not liking Emacs because it's too big and complicated, but I can't understand using Eclipse instead -- from what I've seen, that's even bigger and more complicated!
Ken
+2  A: 

In general,

setterm -blength 0

will disable the terminal's beep. GNU screen and some graphical terminals have their own beep notification settings.

Specifically for Bash and other Readline-using software, tab completion behavior can be changed using $INPUTRC, /etc/inputrc, and ~/.inputrc configuration files. For example,

bell-style none     # never ring the bell
bell-style visible  # use visual bell, if available

show-all-if-ambiguous on  # list all completions instead of ringing the bell
ephemient
+1  A: 

Directories for files with commonality are usually a good idea, but may not always be possible. In those cases, a simple approach that works well is to put the commonality in the suffix, rather than the prefix. For example, I name my unit tests with '_test.py' as the suffix. Doing it the other way round (e.g. test_foo.py) would stump tab completion for every test file.

You can extend this idea to the general case for flattening hierarchies. For example, if you have the class hierarchy Person->Employee->Programmer, you could avoid mirroring the directory structure of the code by calling the test programmer_employee_person_test.py. Again, more general components of the identifier come later in the name.

ire_and_curses
A: 

You can use menu-complete instead of complete:

bind '"\C-i": menu-complete'
echo '"\C-i": menu-complete' >>~/.inputrc
Mark Edgar