Emacs support for VS2012 builds - c++

I'm trying to get my .emacs set up so I can do builds of VS2012 projects from inside Emacs.
I followed the instructions on Emacswiki for doing this. It worked in the past for me with VS2005.
The problem is that this new version of VS appends a CPU designation on the front of every error/warning line, and emacs' C++ compiler parsing is getting confused and thinking that's part of the file name. For example, the error:
5>c:\dev\proj\my_class.h(35): warning C4100: 'command' : unreferenced formal parameter (my_class.cpp)
When visited with "next error", instead of bringing up the file and line, gives me the prompt:
Find this error in (default 5>my_class.h): ~/dev/proj/
Is there a tweak I can make in my .emacs (or perhaps the C and C++ modes) to fix this? Alternatively, is there a newer version of Emacs (or the mode .el files) that deals with VS2012 better? I'm currently using GNU Emacs 24.2.1

I think I've tracked this down.
The issue was not that GNU Emacs didn't try to support VS2012 compiler messages, the issue was that it had a couple of bugs in its support (in 24.2.1).
A bit of background: All the regexps Emacs uses to recognize errors and warnings are in a variable with the enchantingly redundant name of compilation-error-regexp-alist-alist. This is declared inside of the compile.el elisp file.
The main issue is that the first match found in the list is used, not the largest. There's a regexp on that list for edg-1 (Edison Design Group's front end for LLVM) that happens to match VS2012 errors and warnings. It was earlier in the list than the msft, so it was being used instead. Presto: bad directory match.
The issue was discussed in this thread on the emacs dev list, and fixed with a patch on 10/14/2012.
There are two fairly easy solutions.
Upgrade to Emacs 24.3 or later. This should have the patch.
(for the handy) Edit your lisp/progmodes/compile.el file. Find the "msft" entry in compilation-error-regexp-alist-alist, and move it somewhere in front of the offending "edg-1" entry. While you are at it, you may want to add a ? at the end of the first regexp line before the backslash (see the diff link). Then byte-compile the file and restart emacs.

Related

getting include paths to work with Neovim and LSP-zero/Clangd

I'm currently Studying Computer enginering and taking embeded systems class, My isuse is that we use a custom library then compile it in a old version of Codewarrior.
how I would go about creating an include path for my lsp with nvim
I was woundering how I would go about creating an include path for my lsp with nvim, when I am not compiling the code localy but later compiling it with an old IDE
any wisdom would be apreciated.
note: in class we are required to use an exterior editor and the older version of code warrior is verry bad it is used for compiling for our micro controler but is unusable for writting code.
things I have done
I have atempted using compile_commands.json by coppying my vscode config for path location
I have tryed using a .clangd file with -I ...
I have tried other method but had no sucess so far
over all I was hopping to find a solution and have poured over the getting started page and stack overflow for several hours trying diffrent method to no avail.
The easiest approach is probably to use a .clangd file. Based on the path in your comment, the .clangd file should look like this:
CompileFlags:
Add: -I/home/bjc1269/Documents/github/libraries/lib/hc12c/include
A few things that I'm seeing in the .clangd file in your comment that don't work are:
Variable substitutions like ${workspaceFolder}. This is a VSCode feature that works in some VSCode settings like "clangd.arguments", but is not supported in a .clangd file, which is editor-agnostic (for example, it works with editors that don't have a concept of a "workspace").
Referring to your home directory as ~. Expanding ~ to /home/<username> is a feature of your shell. Command-line arguments specified in .clangd are passed directly to the compiler without being processed by the shell, so ~ will not work.
Globs like **. To be honest, I'm not even sure what the intended semantics for this could be in the context of specifying include directories.
Square brackets inside the argument to -I. Square brackets may appear in a .clangd file as YAML syntax for specifying multiple values in a list, for example you might have:
CompileFlags:
Add: [-I/path/to/directory1, -I/path/to/directory2]
But if you write -I=[/path/to/directory], the brackets just get passed on verbatim to the compiler, which does not understand this syntax.
First of all: Welcome to stackoverflow! :D
I'd recommend to use bear for this. You just simply invoke it with your build-command and the clangd LSP will read the includes automatically.

Emacs recursive search/replace on Windows without Cygwin

To answer "where did I also use this identifier?" -questions, I run on macOS and the linuxes
dired-maybe-insert-subdir
dired-mark-files-regexp
followed by either of:
dired-do-find-regexp
dired-do-find-regexp-and-replace
On Windows I can get by using Emacs as my IDE without Cygwin, except for dired recursive search/replace.
Does Projectile
offer commands that will search/replace an identifier recursively without requiring Cygwin?
Does any other package make recursive search/replace possible on Windows without Cygwin?
I'm not concerned about the speed, because even after installing Cygwin, the recursive invocation of Cygwin's grep from within Emacs is painfully slow.
Update:
Recursive search/replace seems to be available in both
Helm
and
Projectile.
If true, then my question is:
Is the feature available on Windows without Cygwin?
The list of requires in my .emacs is already excessive. What is a light package that will do recursive search/replace (without Cygwin on Windows)?
Clarification:
OK. Success. [Thanks to Drew] With a .emacs containing nothing but (require 'dired+), I can search-and-replace in marked files using M-+ Q on Windows without having Cygwin installed. I'm guessing that this will also work on linux/macOS, although perhaps not quite as quickly as delegating to grep. (The "Act on ALL files [] in and UNDER this dir?" confirmation message will start to get tedious, but that's a separate question.)
For the present question one issue needs clarification. dired+ augments the built-in dired family of commands. Is there a way for it to take over ordinary dired-do-find-regexp-and-replace? That's because with the one-liner .emacs, and with a few marked files in a directory listing, I get
File not found - GREP
File not found - -I
...
File not found - NUL
File not found - ;
indicating that grep is still being invoked. How can tell dired+ "I'm on Windows and I won't install Cygwin; please take over A and Q?" (mapped by default dired-do-find-regexp and the aforementioned command).
Editorial: dired+ seems a bit overwhelming, but if it solves this one problem (eliminate the need for Cygwin on Windows), it will be well-worth figuring out how to move from the usual dired commands to dired+.
I think you're looking for a way to search files and get a list of those that match a regexp. If tags-query-replace works for you on MS Windows (without Cygwin), and I think it should, then you can use command diredp-do-query-replace-regexp-recursive, bound to M-+ Q by default, available from Dired+.
That acts on all marked files in the current Dired buffer, and on all marked files in all of the buffer's marked subdirs, and so on, recursively.
With a non-negative prefix arg it acts on all files in the current buffer and all files in all subdirs, and so on, recursively. (That is, any marks are ignored, and the effect is as if everything were marked.)
If, instead of finding files that match a regexp, you want to search through files then you can use command diredp-do-isearch-regexp-recursive, bound to M-+ M-s a C-M- by default, also available from Dired+. The files to access are defined similarly (all Dired+ dired[p]-do...-recursive commands act similarly wrt which files are identified to act on). That definitely does not require any Cygwin etc. commands - it's just Isearch.

vs10 C++ $(MyLibrary) vs %(MyLibrary)

We are using an environment variable to specify a path to a library we use. Most of the time it points to the released version but sometimes to a development version.
Anyway, it works ok when I use $(MyLib)/path;%(AdditionalIncludeDirectories) for building the C++ application but I can not open the project resources. However, when I use %(MyLib)/path;%(AdditionalIncludeDirectories) it works.
Now, what is the difference?
I thought the correct way is to use $(EnvVar) but for the resource editor it doesn't seems to work. And if $(EnvVar) is the correct way then why does Visual Studio use %(AdditionalIncludeDirectories) and not $(AdditionalIncludeDirectories)
The error I get is: fatal error RC1015: cannot open include file 'afxres.h'.
You use %(item) to refer to an MSBuild metadata item. Using $(AdditionalIncludeDirectories) would not work well if you also had an environment variable by that name. So %(MyLib)/path ought to resolve to just /path.
You can put echo %(MyLib)/path in a prebuild event to verify this.
Which is probably enough to stop confusing rc.exe, the resource compiler. Which is a stone-cold-old SDK utility, going back all the way to Windows version 1.0. It is pretty temperamental, very picky about command line options and .rc script file text encoding. Do keep in mind that it dates from an era long before Windows started to support a forward slash as a path separator, everybody had to use a backslash back in 1986.
So use "$(MyLib)\path" instead, including the double quotes so you don't confuzzle it when MyLib contains embedded spaces. And do favor using a project property sheet instead so there are some odds that somebody can still figure out how to get the project built correctly 2+ years from now.

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

how to install cc-mode-5.32.3? (hightling in C++ mode of emacs)

I am editting my C++ program on a unix cluster by using emacs. I wanna emacs to highlight key words in C++. After searching online, I decide to install cc-mode-5.3.3. But I stuck here:
follow the readme instruction at http://cc-mode.sourceforge.net/src/README
After byte compiling, I don't understand
Put the compiled files somewhere (X)Emacs will find them, i.e. in
some path that's in the load-path variable. You must make sure
they are found before any CC Mode files which are distributed with
(X)Emacs. A directory has higher precendence than all directories
after it in the load-path list.
GNU Emacs comes together with cc-mode installed by default, so you don't need to install it manually. To enable symbols hightlighting, you need to set variable global-font-lock-mode to true value, for example, by using M-x customize-variable global-font-lock-mode, switching it to t, and pressing Apply and Save.
P.S. Are you running Emacs in console, or in graphical mode? If in console, then you could be need to setup corresponding font-lock faces. Use the M-x customize-face command to set faces whose names are starting with font-lock-