9 ms·
Efficiently Browsing Text or Code (esp. with Emacs)
- KC8ZKF 15y ago(find-grep-dired DIR REGEXP) Find files in DIR containing a regexp REGEXP and start Dired on output.
- kirubakaran 15y agoThat is definitely useful. However the scenarios I explored needed two or more keywords occurring on different lines in a file. This is so that I can significantly reduce the number of files that needed a closer look. Is that easily done with find-grep-dired?
- walexander 15y agoI'm an emacs coder myself, so I'm wondering.. why no mention of cscope?
- kirubakaran 15y agoI haven't used cscope. I'll check it out. Thanks.
- jbp 15y ago"cscope + ascope" is the best thing ever I found for groking the code(in emacs). It is great for getting your way around huge code base. I find myself using "ascope-find-this-symbol" all the time, which gives me all occurrences/usages of that symbol.
- codemac 15y agoI know there is at least, cscope.el, xcscope.el, acscope.el, bcscope.el... What's the advantage to acscope vs. the others? I personally use xcscope, I don't even remember why I initially chose it...
- jbp 15y agoFrom: http://www.emacswiki.org/emacs/CScopeAndEmacs http://www.emacswiki.org/emacs/CScopeAndEmacs ascope is an improvement over xcscope that runs all queries through a single cscope process, instead of starting a new process and reloading the database for each query. It was made by Staton Sun as a merge between xscope and another single-process interface, bscope
- signa11 15y agoyeah without cscope it would be impossible to follow huge code bases. though i am not sure how good is cscope at generating symbol database for non-c languages. ideally, it would be really nice if cscope/xcscope provided some means of creating (and saving) bunch of call-stacks, which you can navigate in forwards/reverse direction (not sure if i am making much sense here...)
- jbp 15y agoI agree. For static callgraphs I use doxygen, for dynamic I use "m-x gdb" :-)
- codemac 15y agoYou can "pop" as you navigate around. Also, I've had a lot of luck with pycscope.py for python code + cscope tools. GNU Global needs some love though. It'd be awesome to see it handle more stuff.
- mark_h 15y agoI wrote this some time ago for navigating with (g|e)tags, allowing you to view the current stack as you drill down: https://github.com/markhepburn/tags-view https://github.com/markhepburn/tags-view (you can prune the stack too, so you only see the important bits of context) It worked well for my own usage, but it probably needs some love. I'm not sure how *cscope works though, and if it would be possible to add it as another backend.
- Peaker 15y agocscope and ascope still cannot find particular struct fields.
- dw5ight 15y agoawesome article, thanks K!
- kirubakaran 15y agoThank you :-)
- decklin 15y agoNo mention of M-x grep?
- zacharypinter 15y agoI find M-x rgrep extremely useful as well.
- kirubakaran 15y agoI left that out as I needed to filter for files with two or more keywords occurring on possibly different lines. I don't know of an easy way to make M-x grep do that.
- wladimir 15y agoIt's 2012 and we're still navigating source code, which is effectively a nested graph structure, using grep and simple keyword queries. No (reverse) call trees, no high-level views, no help on how data propagates through the program. We could do so much better, especially in static languages. Sometimes it seems like reverse engineering tools that work without source code (such as IDA) do a better job of cross-referencing than tools that have the actual source code. Is there any good/usable point and click code browser / code comprehension tool these days? Or is the state of the art of 1998 still that of today?
- drv 15y agoVisual Studio has some fairly decent tools ("Find all references", "Go to definition/declaration"), although they tend to fall over in macro-heavy C++. A lot of my coworkers swear by Understand, but I haven't tried it myself.
- Derbasti 15y agoIf only these tools would wirk reliably. I have seen too many cases when find all references did not find the reference I was looking for (even though it was in no way special or obfuscated). Goto definition works pretty well though.
- tikhonj 15y agoWe're still doing this for two reasons: it's easy and it works surprisingly well. More complicated solutions would be difficult to implement and would probably be less flexible. It's just difficult to be significantly more efficient than somebody really good with Emacs using mostly code agnostic tools, except in real edge-cases (finding the right variable named x our of hundreds of xs is going to be difficult, but if your code looks like that you have bigger problems). Also, I really wish the myth that "point and click" is inevitably superior would go away. It may be easier to learn, but my experience is that with some practice keyboard-based programming tools are almost invariably faster.
- wladimir 15y ago
- aristus 15y agoThere are many roads to Damascus. (global-set-key "\M-/" 'tags-search) (global-set-key "\M-'" 'tags-apropos)
- res0nat0r 15y agoack and ack.vim = bliss.
- heretohelp 15y agoIndexing is better, but ack is still nice to have for ad-hoc searches. Ack plugins for Emacs: http://www.emacswiki.org/emacs/Ack http://www.emacswiki.org/emacs/Ack http://rooijan.za.net/code/emacs-lisp/ack-el http://rooijan.za.net/code/emacs-lisp/ack-el https://github.com/jhelwig/ack-and-a-half https://github.com/jhelwig/ack-and-a-half http://www.emacswiki.org/emacs/FullAck http://www.emacswiki.org/emacs/FullAck
- docgnome 15y agoAck is great
- tptacek 15y agoHighly, highly recommend hilock-mode for browsing code; hilock does ad-hoc syntax highlighting, so, as you read code and notice patterns, you write regexes for them and let Emacs spot them for you. This turned out to be so useful for code reviews (we do a lot of those) that I "ported" it to a web app that lets us set hilocks that follow us from buffer to buffer (along with xrefs, class/method/fn definition sites, bookmarks, and a lot of other junk).
- kaeluka 15y agowow, that's amazing! Thanks for that :)
- abc_lisper 15y agoUm. I thought I was inefficient at browsing Emacs and this sucks more. Here's what I do. 1. Generate a file index, every now and then(read cron). > find . > fileList 2. Write a script(can also do this in emacs) in bash that takes two arguments viz., filename and search string. The script does a two level grep(regex), first on filenames and then in each of those files for the search string 3. If the previous routine was written in bash written a elisp function that calls the bash script. That's mostly it. I could use cscope but it sucks donkey balls with java. When I ask for definition it finds a declaration.
- Peaker 15y agoThen you want to search all uses of the Linux kernel's struct scsi_device field "vendor". Unfortunately, there are hundreds of structs with a "vendor" field. cscope, etags, etc can't really handle this task. Eclipse and Visual Studio can. I am really disappointed that emacs and vim who spout productivity over learning curve allow important productivity tasks such as this to remain more than a decade behind the state of the art.
- counterpunt 15y agoif it's really that important to you, quit bitchin and start coding!
- Peaker 15y agoI am coding, but it's actually a more ambitious project to get rid of text in the toolchain altogether, making searches such as this much simpler cross-reference searches.
- Erwin 15y agoThere's an affordable (USD 299, free 7 day trial) commercial tool for C/C++/Javaallowing structured, context-sensitive code browsing and refactoring that actually integrates into Emacs: http://www.xref.sk/xrefactory/emacs.html http://www.xref.sk/xrefactory/emacs.html In fact it seems the pure C version is free now; it claims full indexing of 3 million lines of Linux source code in 15 minutes. I used to keep track of it many years back back while it was being developed, but then C++ starting making up 1% of my projects rather than 99% (nowadays I use the JetBrains PyCharm for those 99% which does a reasonable effort). It seems the tool hasn't seen updates in a while (forget about C++11 support), but I remember it working much better than just tags, cscope last time I tried it many years ago.