Hot answers tagged

9

OS-X comes with emacs 22, which is several years out of date. One easy way to get a current emacs is by downloading from http://emacsformacosx.com/. This will give you package.


9

This is a bit disppointing, because ffap.el has some code that should do just that: ;; Immediate rejects (/ and // and /* are too common in C/C++): ((member name '("" "/" "//" "/*" ".")) nil) But unfortunately, it relies on there being a space after the comment separator. It's also very disappointing, because comment markers should never be part of ...


9

UPDATE: I created Semantic Refactor package that completely solves this problem and more. You can look at the demos to see how it works. The remaining text of this answer, after this sentence, is old and put it there just for historical reason. OLD ANSWER: You can use senator-copy-tag for accurately copy function signature, then paste back in your source ...


7

The below code works fine from my brief testing in a c-mode buffer: After typing /*, hit M-j, the default binding for indent-new-comment-line (and the default binding for c-indent-new-comment-line in c-mode). If it is the first comment line the closing closing characters */ will be auto-inserted. Hitting M-j more times with insert more comment lines with ...


7

The Emacs one is actually better. Here's why, The purpose of syntax highlighting in text editors is not being pretty, but to make important code structures stand out. If you look at the Emacs sample, you'll see 'MyClass' being colored in the 'type name' color and 'obj' in 'variable' color, which makes the important information that you have one variable '...


7

That's a lot of questions, but I will try to answer them in such a way that you can look up all the answers in detail. Emacs is primarily a text editor; you will use it to edit your C++ files. Converting those files into a program that your computer can run is the job of a compiler. There are many C++ compilers, but you will want to use one called gcc. ...


6

This can be done by changing comment-start & comment-end. (add-hook 'c-mode-hook (lambda () (setq comment-start "//" comment-end ""))) Found the answer after further searching here


5

this seems to answer the member function bit of your question (font-lock-add-keywords 'c++-mode `((,(concat "\\<[_a-zA-Z][_a-zA-Z0-9]*\\>" ; Object identifier "\\s *" ; Optional white space "\\(?:\\.\\|->\\)" ; Member access "\\s *" ; Optional white space ...


5

color-identifiers-mode does this for variables, if I understand your question correctly. rainbo-identifiers-mode too, I think. Screenshot is from the former one.


5

Yes. The functions in window-scroll-functions are called just before a redisplay that would cause scrolling. Each function returns two arguments, the window window and the new window start position new-start. You can call (window-start window) to get the current window start position, (window-end window) to get the current window end position, and (window-...


5

As mentioned in this answer on SO, you can do: (setq c-default-style "bsd") This will set the style for all C-based modes. If you want to set it only for one, do e.g.: (add-to-list 'c-default-style '(c-mode "bsd")) However, setting c-default-style will change various other style settings, which may not be what you want. To only change the post-for-loop-...


4

Thanks to the solution posted by @Sigma. I had that solution in my config for more than 2 years, and finally sent that as a patch to emacs upstream. Commit in emacs master: e472cfe8 Here is what the patch effectively does: (defun modi/ffap-string-at-point (&optional mode) "Return a string of characters from around point. MODE (defaults to value of `...


4

I had a similar idea once, but honestly? there are quite a few things that a proper build system needs, and which will require quite a lot of work. One thing you want is memorizing things you've built and building only the things you have to. This would typically call for interaction with database, version control system and writing code which builds a ...


4

Here is a start. Add to your .emacs file: (global-set-key [f4] 'compile) You can also enter the "f4" and "compile" interactively. Starting out with M-x global-set-key Compile is a generic for running any command in a separate buffer. The default command runs "make", which may or not be what you want. You have an opportunity to change that and compile ...


4

Based on @Tobias's excellent answer. this extends it to have both forward and backward transpose. correct cursor location. don't move the cursor if there is nothing to do. (defun c-forward-to-argsep () "Move to the end of the current c function argument. Returns point." (interactive) (while (progn (comment-forward most-positive-fixnum) (...


3

A vanilla company install wont quite get you where you want; you'll need to use use something like the company-c-headers package. Tuhdo has written an excellent document on using Emacs as a C/C++ IDE, which has instructions on setting up company-c-headers, along with a lot of other stuff. I don't know what Emacs version you're using, but in 24.5 with ...


3

Quoting deps.mk: ## This file is included in src/Makefile if AUTO_DEPEND=no.\ So it's kind of a fallback file only used to give dependencies to make sure compilation ordering is right. You want to look in src/Makefile.in instead where you should have no difficulty finding the variable that contains all the .o files we need.


3

You can check my C/C++ guide for all the needs above: You can use GNU Global with ggtags or helm-gtags, which can be installed through MELPA. GNU Global can use cscope backend, but you should use its native backend for generating tag datdabase for C/C++ code. You can jump to definitions or references instantly, even for project as large as Linux kernel. ...


3

You can install irony-mode and see full information of each completion candidates; it looks like this. Alternatively, you can also use company-clang that comes with company that gives you something like previous screenshot. Note that to have something similar to the screenshot and using Irony, you have to install Company to install company-irony. If you want ...


3

The following command should do it. It passed my tests, and has no external dependencies. (defun endless/copy-proto-to-header-file () (interactive) (save-excursion ;; c-mode's `beginning-of-defun' should be robust enough. (beginning-of-defun) (let ((l (point))) (search-forward-regexp " *{") (let ((proto (buffer-substring l (match-...


3

Emacs has keyboard macros with counter support. The gist of the solution would be (assuming default key bindings): F3 to start recording a macro Type printf("%d", " F3 to insert the macro counter Type the rest of the line, "); F4 to end recording the macro Use F4 with a prefix to run the macro n times, e.g. C-u 1 0 0 F4. If you want to play editor golf and ...


3

Posting own answer since I didn't find an existing method *. This is generic Doxygen highlighting, it doesn't try to be too strict since doxy supports so many different expressions. \[anything] and @anything are matched (until non whitespace). #symbol uses stricter matching ([a-zA-Z0-9_\.\:]+). Doxy comment styles /** … */, /*! … */, /// … are supported. ...


3

Since you are using Org-mode and all you want (according to your post), is to evaluate small C code examples, I'd use ob-C and just evaluate everything using org-babel. This is not an answer on how to compile and run C code directly, but a convenient alternative using Org. Fire up an org file and try the following (taken from this awesome blog post): #+...


3

The following transposes two arguments of c-functions. The first argument is the one with point in it. It is followed by the second arg and separated by a comma. It looks for arguments by skipping over sexps and whitespaces-comments until it finds an argument separator, i.e., a comma or a parenthesis. (defun c-forward-to-argsep () "Move to the end of the ...


2

Your code doesn't make much sense. You set the default style in the mode setup hook. The default style will be used when you subsequently open a file. The first file you open will be in what was the default style at the time (which is "gnu") with some parameters customized. The Linux style is built in, so you don't need to do anything other than select it. ...


2

I think hacking find-file-at-point is easy, you can use defadvice on find-file-at-point. The key point is detecting whether the cursor is in a comment. I had a similar issue when developing evil-nerd-commenter. Here is the function you can re-use. The trick is to detect the current font face. (defun evilnc--in-comment-p (pos) (interactive) (let ((...


2

I think the following should work (it works for me): (defun c-copy-function-signature-to-header () (interactive) (save-excursion (let ((last-point -1)) (while (/= (point) last-point) (setq last-point (point)) (sp-backward-up-sexp)) (kill-ring-save (point) (line-beginning-position)) (ff-find-other-file) (yank) ...


2

The problem was not in a build system but in Emacs itself. In order to have a function defined with DEFUN available for a user you must not only define it but also write in your file: void syms_of_filename (void) { defsubr (&Sfunction_name); ... } and call this function from emacs.c


2

In eshell aliases $* is replaced by the list of arguments passed after the aliased command. (You can also use $1 to get the first argument, $2 for the second, etc.) So, try alias gcc "gcc -Wall -pedantic -std=c99 \$*" As far as I know this behavior is not documented in the manual. See the EmacsWiki Eshell Alias page and the comment at the top of em-alias....


2

A .dir-locals.el file would certainly do the trick! I like to use the function (add-dir-local-variable MODE VARIABLE VALUE) rather editing .dir-locals.el manually. For those two values eval (let ((default-directory "~/your/project/path")) (add-dir-local-variable nil 'c-default-style "linux") (add-dir-local-variable nil 'c-basic-offset 4)) and ...


Only top voted, non community-wiki answers of a minimum length are eligible