How do I ag search into a specific set of folders using the -G option? - ag

How do I ag search into a specific set of folders using the -G option?
Here's an example where I use -G routes, but it's picking up another result from another folder, because routes is still in the path. Yet if I try -G ^routes, it doesn't seem like the regex is taking?
On that note, Atom has a nice path searching syntax which lets me do things like app,routes,!storage (search in app and routes folders, but ignore storage folder). Since I've switched to vim, I'm finding it hard to get a searching workflow down with ack/ag. Anyone have any tips for me?

I suppose you'd really like to try this plugin https://github.com/junegunn/fzf.vim. It will (among other things) run your ag search and present the result in a fuzzyfinder. Then you'll have the very same feature you mention in atom by running :Ag middleware followed by(in the fzf window) 'app/ 'routes/ !storage/'.
about the use of regex for the file pattern, you'll need to quote your regex
ag -G '^routes' middleware
that being said, the '^...' doesn't work as intended here on my computer either, although '\b' does. I started using ripgrep instead of the-silver-searcher not so much because it's faster but rather because it has a better documentation, maybe you'd like to give it a try. rg -g will take a glob which is easier to understand than the "FILEPATTERN" mentioned in the ag man page

Related

gnu make spaces in directory names vpath

We've been trying unsuccessfully to make VPATH or vpath search directories containing space characters.
My makefile contains:
vpath %cpp RTW/ModelRTW RTW/StandardTests RTW/TestFramework RTW/TestFromFile ../../../CommonCode ../04_Model/DLib/ ../04 Model/ELib/
make -p returns:
.
.
vpath %cpp RTW/ModelRTW:RTW/StandardTests:RTW/TestFramework:RTW/TestFromFile:../../../CommonCode:../04_Model/DLib
I have tried quoting, escaping '\ ' and several other incarnations to no avail.
Any help would be greatfully accepted.
Ed
Sadly, it is a very old known defect, #712, and people have looked in to it a few times since it was reported in 2002.
GNU make doesn't handle spaces in names, and never has.
If you do attempt to patch it you will have a serious challenge ahead, since an enormous number of projects rely on it. Those who need whitespace support move to more advanced build systems. Over the decades there have been many build script tools, but make still sticks around despite many major problems. The make format of tabs and spaces has been annoying developers for almost 40 years.
The source is available, feel free to attempt to patch it if you want. Most developers who try end up giving up or making yet another build script system.
The best way is to write an m-script to copy the file(s) to the build directory where path is space-free.
If you use Simulink then the m-script is invoked at "before_make" hook.

Emacs as an IDE for large C++ projects

I am a Emacs newbie. I have to trying to search on how to use Emacs for use with large C++ projects particularly to index code and auto-complete function names and behave Eclipse-like. I had been using Vim for some time where I used ctags to index code in my project and Vim used to try auto-completing my code using a drop down menu of options. I am trying to achieve the same with Emacs now. But, during my search, results pointed to CEDET and auto-complete and other 3rd party plugins.
I tried to use ctags with ctags -e -R . and etags, but with no success.
Am I missing a default way of Emacs to achieve the same behavior? Which is the best and easiest way to achieve what I want?
I use CEDET with autocomplete successfully. Basically, autocomplete is the drop-down box provider, and it takes its sources from various things, most interestingly from CEDET (but also from etags and Gnu Global, which I recommend too).
A good starting point for CEDET is http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html
Alex Ott's emacs config is there: https://github.com/alexott/emacs-configs -- it's an useful resource.
Note that you'll need to grab CEDET from bzr, and install/configure autocomplete correctly. I strongly recommend el-get to install autocomplete (and some other stuff too). You'll need to set up generic projects for EDE to have autocompletion working for random C/C++ files not part of a structured EDE project.
You'll have to spend some time to configure emacs, but it pays off. The tool is amazingly productive once set up correctly.
Indexing
You might want to use GNU/global instead of ctags: it supports C++ and is in my opinion more efficient with large projects (especially since you can update the index instead of rebuilding it from scratch). And it still is a lot simpler to use that CEDET/Semantic (which is also a fantastic tool if you spend the time to set it up).
Example use:
$ cd sources
$ gtags -v # create the index
$ cd subdirectory
$ [hack hack hack]
$ global -u # update the index (can be called from anywhere in the project)
In Emacs, activate gtags-mode in the source code buffers to get access to the gtags commands:
gtags-find-tag (M-.) : find the definition of the specified tag in your source files (gtags lets you choose between all possible definitions if there are several, or directly jumps if there is only one possibility)
gtags-pop-stack (M-*) : return to the previous location
gtags-find-rtag : find all uses of the specified tag in the source files
Below is my configuration for gtags, which automatically activates gtags-mode if an index is found:
;; gtags-mode
(eval-after-load "gtags"
'(progn
(define-key gtags-mode-map (kbd "M-,") 'gtags-find-rtag)))
(defun ff/turn-on-gtags ()
"Turn `gtags-mode' on if a global tags file has been generated.
This function asynchronously runs 'global -u' to update global
tags. When the command successfully returns, `gtags-mode' is
turned on."
(interactive)
(let ((process (start-process "global -u"
"*global output*"
"global" "-u"))
(buffer (current-buffer)))
(set-process-sentinel
process
`(lambda (process event)
(when (and (eq (process-status process) 'exit)
(eq (process-exit-status process) 0))
(with-current-buffer ,buffer
(message "Activating gtags-mode")
(gtags-mode 1)))))))
(add-hook 'c-mode-common-hook 'ff/turn-on-gtags)
Automatic completion
I don't know of any better tool than auto-complete. Even if it is not included within Emacs, it is very easily installable using the packaging system (for example in the marmalade or melpa repositories).
It depends what you are looking for in an IDE. I have been using Emacs for a fairly large C++ project. Of course you need to configure emacs to work as you want it to work in a greater extent they any other IDE.
But yes CEDET is a start, even though it is not perfect.
However there is a very good auto complete mode for Emacs http://cx4a.org/software/auto-complete/ it is not intelisense but it should integrate with CEDET in some way to give you a farily good auto complete.
Another important feature that I often use is the function ff-find-other-file to easy jump from header and implementation files.
Then of course you need to roll your own bulid. CEDET has some support for projects, but I have not tested it. However Emacs integrate well with command-line build tools such as make. Errors are printed in a buffer and you can jump to the correct line easily within Emacs.
GDB is also integrates well with Emacs M-x gdb, then just remember the gdb-many-windows command.
I recommend to watch Atila Neves lightning talk at CppCon 2015 titled Emacs as a C++ IDE.
For for details, see my answer to this related question.
See https://emacs.stackexchange.com/questions/26518/sequence-of-packages-to-be-installed-to-make-emacs-an-ide-for-c-c
I use GNU Global and two popular Emacs plugins:
company for code completion
emacs-helm-gtags for code navigation

Setting up vim as C++ IDE

I wish to setup vim as C++ IDE so I can do all work from it.
I'm using these plugins for vim:
Clang complete - accurate completion
nerdtree - browse files
snipmate - insert snippets
AutoComplPop - omni-completion
buffergator - buffer management
vim-powerline - nice statusbar
vundle - to manage plugins
But I lack things like Jump to definition and compiling multiple files in one executable, project view...
I'm using
nmap <F8> :w % <bar> :!g++ -W -Wall -Wextra -pedantic -std=c++11 % -o %:t:r<CR> <bar> :!./%:t:r<CR>
to compile current file, but it won't work if there are multiple file that create one executable.
I know I could just use eclipse, netbeans, code::blocks and such, but I really like vim... If such thing as vim ide isn't possible do I have to learn GNU build system or some other method?
Any advice is welcome.
You need to create a makefile which handles the build process.
Then from vim just run :make, it will run the build and pop all errors in quickfix window where you can navigate and jump to error locations.
First, to jump to definitions, you might try this:
http://www.santiagolizardo.com/article/vim-jump-to-classes-and-functions-defined-in-different-files/64003
I haven't tested it, so I can't tell you if it works.
Now, to build multiple file projects, it might be better for you to learn how to use makefiles and automake. These links might help you:
http://homepages.gac.edu/~mc38/2001J/documentation/g++.html
http://www.openismus.com/documents/linux/automake/automake
Good luck.
Edit: A similar question was answered on this link: https://stackoverflow.com/a/563992/1820837
"Jump to definition" is already there, it's <C-]> with the cursor on a keyword or :tag foo on the command line.
For these to work, you need a tags file generated by exuberant-ctags and to tell Vim where to find it. See :help tags and :help ctags.
Without a tags file, gd goes to the definition of the keyword under your cursor if it's in the same file. But it's not as generally useful as <C-]>.
For "Jump to definition" I can recommend the YouCompleteMe, plugin which is really easy to setup with vundle.
Otherwise there is also ctags, but I find it less useful.
To use vim as a IDE, I find this post useful.

Invoking doxygen search from the console

I'm using doxygen in a C++ project under Linux. Searching is possible using the search box on the documentation main page, but is there a way to call the search from the command line? For example, by using something like firefox myHelp.html/+search for myClass+.
Do you really want to start a browser with a search result from your doxygen documentation?
The URL to perform a search within a doxygen documentation page has the form:
...Doxygen/html/search.php?query=searchterm
So you could try something like
firefox file:///somepath/Doxygen/html/search.php?query=searchterm
However, I am not sure if that solves your problem.
Besides you can use typical command line tools to find terms in your file system:
grep -R searchterm

Using Eclipse CDT from command line

I need to have some of my C++ classes, functions and namespaces renamed as a part of my build script, which is runned by my CI system.
Unfortunatly a simple sad/awk/gsar/... technique is not enough, and I need smart rename refactoring, that carefully analyses my code.
Actually I found out, that CDT C/C++ rename refactoring does, what I need. But it does it from Eclipse IDE. So I need to find a way to start it from command line, and to make it a part of my CI build script.
I know that Eclipse has eclipsec executable, that allowes running some Eclipse functions from command line (see e.g. here).
But I can't find any suitable documentation for functions, CDT exports to command line. The only thing, I found is the this. But it doesn't solve my problem.
So, I need help to run CDT rename refactoring from command line (or someway like that). If it is not possible, may be someone will advice another tool, that can do rename refactoring for C++ from command line ?
Pragmatic Approach
"I need to have renamed as a part of my build script"
This sounds a bit like a design problem. However, I remember having been guilty of the same sin once writing a C++ application on AIX/Win32: most notably, I wanted to be able to link 'conflicting' versions of shared objects. I solved it using a simple preprocessor hack like this:
# makefile
#if($(ALTERNATIVE))
CPPFLAGS+=-DLIBNAMESPACE=MYLIB_ALTERNATIVE
#else
CPPFLAGS+=-DLIBNAMESPACE=MYLIB
#endif
./obj64/%.o: %cpp
xlC++ $(CPPFLAGS) $^ -o %#
Sample source/header file:
namespace MYLIB
{
class LibService :
{
};
}
As you can see, this required only a single
find -iname '*.[hc]pp' -o -iname '*.[hc]' -print0 |
xargs -0 sed -i 's/OldNamespace/MYLIB/g'
Eclipse Automation
You could have a look at eclim, which does most, if not all, of what you describe, however it targets the vim editor.
What eclim boasts, is full eclipse intergration (completion, refactoring, usage search etc.) from an external program. I'm not fully up to speed with the backend of eclim, but I do know that it works with a eclimd server process that exposes the service interface used by the vim plugin.
I suspect you should be able to reuse the code from eclimd if not just use eclim for your purposes.
We are completing a command-line rename tool for C++, that uses compiler accurate parsing and name resolution, including handling of shadowed names. Contact me (see bio) for further details or if you might be interested in a beta.