How to get emacs grep to search based on project root? - emacs

I want emacs grep to always search from the root project directory, not the directory of the currently opened file. The assumption here is that all of your coding projects are under the same folder (like ~/repositories/).
I tried to prefix the grep command with a command that cds into the project root, but this leaves the emacs working directory variable untouched, so while the grep is performed in the correct filesystem location, jumping to search results is broken, because the partial file paths of the grep matches are appended to the emacs working directory.
To summarize, I want to be in ~/repositories/my_project/folder1/file1.c, invoke grep command which will search from ~/repositories/my_project/, and have the jump to file functionality of the grep buffer work.
How can I achieve this?

This does not answer directly your grep question but especially when working with projects, I always find projectile to be a great tool.
Projectile, amongst other things, provides a grep, ack and ag search on a project level which is probably what you are looking for.
E.g.
C-c p s g runs grep on the files in the project.

you can simply run this using project.el builtin project package
manager in emacs
project-execute-extended-command
with keybinding C-x p x and then execute the
extended command rgrep or grep depending on what you want.
So I normaly do
C-x p x -> rgrep -> enter-query
et voila!

Related

Automatic folding with dosini files in neovim on Linux

I have config files in the DOS INI format.
As explained in the link above, to make vim automatically fold the DOS INI files by section, I need to create a new file ~/.vim/after/syntax/dosini.vim
with:
syn region dosiniSection start="^\[" end="\(\n\+\[\)\#=" contains=dosiniLabel,dosiniHeader,dosiniComment keepend fold
setlocal foldmethod=syntax
" Following opens all folds (remove line to start with folds closed).
setlocal foldlevel=20
I did exactly that and it does not work with neovim (folders after/syntax did not exist, I had to create them).
Is the location of the after/syntax folders different in neovim than in vim? Or is the problem somewhere else?
Is the location of the after/syntax folders different in neovim than in vim?
Yes. Nvim follows the XDG Base Directory Specification.
What ~/.vim is to Vim, is ~/.config/nvim to Nvim.
So, either create ~/.config/nvim/after/syntax/dosini.vim or, do what most people do and, create a symlink ~/.config/nvim that points to ~/.vim.
If you also want to share the vimrc between both then create a symlink ~/.config/init.vim that points to your ~/.vim/vimrc (or ~/.vimrc).

Files Listed in Emacs Find-Files

I was using Emacs on another terminal today and I noticed that when I hit C-x C-f to open a file that Emacs showed "Loading Tramp..." and then listed the files. I could either type my desired directory/file or I could use the left/right arrow key and Return to shift through directories and open a file. I was totally awesome. I am familiar with Tramp mode and started fiddling with it but I could not figure out how to get it to work, or if the two are even related, on my machine.
How do I get a file tree that I can use arrow keys with in Emacs?
This is how it appears on the other terminal:
Find file: .../dir1/dir1/{css/ | try.org | misc.txt | .emacs}
That likely was ido-mode, which is bundled with Emacs. Put this in the init file:
(ido-mode)
While it's on, it will rebind some common commands to its own versions that use this visual interface.
Tramp mode is not related. It just gets loaded if ido-use-virtual-buffers is t and you visited some remote files recently.

How do I get eshell working correctly in emacs?

For some reason, when I type in commands I'm used to on linux, it works perfectly, as it does in bash... But in eshell, it doesn't work.
I've narrowed the problem to a trivial and small sample, as follows:
$ du
c:/Program: command not found
$ which bash
c:/Program Files (x86)/Git/bin/bash.exe
How do I get this working? (du is whatever it is by default... It's implemented in elisp, I haven't made any unusual changes there, that is, it's a compiled lisp function in `em-unix.el')
I would've expected something along the lines of "You have used 1.3 GiB of disk space", rather than that command not found error.
It doesn't use bash.exe, but it can use du.exe, when present.
On my system:
c: gutov $ which bash.exe
which: no bash.exe in ...
c: gutov $ which du.exe
h:/Apps/System/gnuwin32/bin/du.exe
From your error message I can tell that it calls some command and fails because it doesn't properly quote the path to executable (which contains spaces). Maybe you should do M-x report-emacs-bug.
Overall, I recommend:
1) Uninstall Git and reinstall it selecting the second option when asked about your PATH environment ("Run Git from the Windows Command Prompt"). This will remove the unix tools packaged with it from PATH.
2) Install in some directory without spaces and add to PATH unix tools from GnuWin32 project, or from Eli Zaretski's ports. The latter contains fewer packages overall, but it has a much faster find, for example. You can mix them.
Alternatively, maybe you can get away with just reinstalling Git into directory without spaces.

How to adjust the path that Emacs' compile-goto-error gets from the compilation buffer?

I am using Emacs 23 and have the following problem:
I run our project's build system from within Emacs like M-x compile -> cd /foo/bar && ./build
The build system now does some magic, "cd"s into some subdirectory for the build process and then gcc throws an error:
../src/somesource.cc:50 error: blablabla
Now the problem is that Emacs won't find that path, because it assumes the compile process started out in /foo/bar, and not in /foo/bar/builddir. So the leading "../" is not working for Emacs, e.g. when running compile-goto-error. Is there a way to tell Emacs to try skipping leading "../"?
The best solution might be to change the build system to emit messages when it changes directories. Emacs looks for
Entering directory `...'
...
Leaving directory `...'
(See the compilation-directory-matcher variable. If your build system does emit messages when it changes directories, but they're not in the format Emacs is looking for, you can add new regexps to compilation-directory-matcher.)
The other solution is to change compilation-search-path (which is a list of directories).
On a few occasions I solved by passing output of the make through sed.
First, debugged it interactively 'Compile command: make | sed 's/x/y/' . And then repackaged it as a custom emacs interactive function.

a question about clearcase: how to open a file checked out in emacs?

I have a question about clearcase. in linux, I open a terminal, and use "xclearcase" command to lunch file browser of clearcase. Then I check out a file and I want to open it in Emacs, I know I should cd to the folder contains the checked out file, but before I do this, the terminal still effected by the "xclearcase" command, how could I type some commands now?
When you launch xclearcase, do so by adding a & to the end of it. This will make the shell send it to the background so you can do more stuff in your shell. E.g.
xclearcase &
That will allow you to further interact with your shell while xclearcase is running.
Also, if you're working in the terminal, I would recommend getting comfortable with cleartool for basic operations. For example, to checkout and edit a file:
cleartool co src/path/to/file.c
emacs src/path/to/file.c
Then, to checkin the file:
cleartool ci src/path/to/file.c
As Nemo mentions in the comments, the vc-clearcase Emacs mode allows you to checkout a file right from an Emacs session (C-x v v).
It will handle hijacked file, asking whether to keep the changes in said hijacked file through the question "Claim lock retaining changes?"
It will ask for a comment
It allows for checkouting a directory
It handle file with a -nocheckout rule on their config spec