14
votes
Accepted
before-save-hook for cc-mode
One fairly common way of restricting the action of a hook to a particular major mode is to check the value of major-mode.
For example, this hook prints a message before saving buffers using c++-mode:
...
9
votes
Accepted
formatting constexpr if in c++-mode
UPDATE: That pretest version that I put down there in the original question (emacs-26.0.90.tar.gz) had a bug that cause certain infinity loops while parsing the buffer, specifically when using the <...
8
votes
Accepted
Indentation after braces in C
Your question appears to be dealing with two independent issues:
you want the RET character to automatically indent; and
you want an indentation style that is different from the Emacs default.
...
7
votes
Indentation after braces in C
smartparens, a solution for advanced handling of pairs (such as (), [], {}, <>, ...) supports pre- and post-action hooks. With these it's possible to make Emacs indent the content of a {} pair ...
7
votes
How to use C++ comments "//" in c-mode?
This can be done by changing comment-start & comment-end.
(add-hook 'c-mode-hook (lambda () (setq comment-start "//"
comment-end "")))
Found the answer ...
6
votes
Accepted
Change the way CC-mode font-lock the C++11 `auto` syntax
One option is to add "auto" to extra types recognized by c++-mode:
(require 'cc-mode)
(add-to-list 'c++-font-lock-extra-types "auto")
The downside is that now it is not highlighted as a keyword any ...
5
votes
rgrep default files pattern
M-xcustomize-variableRETgrep-files-aliases and then use the interface to change the value of this variable.
Alternatively, you could put:
(setf (cdr (assoc "cc" grep-files-aliases))
(assoc "...
4
votes
Customizing c-mode indentation behavior in Emacs 24.4
You want to do:
(add-hook 'c-mode-hook
(lambda ()
(setq-local electric-indent-chars
(remq ?\n electric-indent-chars))))
4
votes
Accepted
Customizing c-mode indentation behavior in Emacs 24.4
You could rebind RET to electric-indent-just-newline like this:
(add-hook 'c-mode-hook
(lambda() (local-set-key (kbd "<RET>") 'electric-indent-just-newline)))
4
votes
Accepted
Setup c-mode indentation, braces and tabs
This is not necessarily a direct answers to what you should put in your .emacs file but rather a more generic way to quickly figure out the parameters for the style you've chosen.
cc-mode provide ...
4
votes
Accepted
cc-styles c-offsets-alist setting for C++11 lambda brace indentation
You can add a function for that to arglist-cont-nonempty. In the following example my-c-lineup-arglist-lambda should do what you want:
(c-add-style "work"
'((indent-tabs-mode . nil) ...
4
votes
Customized c-offsets-alist override c-file-style in dir-locals
Instead of modifying c-offsets-alist, you can modify c-file-offsets whose purpose is to set offsets via file local variables.
A small example for a .dir-locals.el file:
((nil . ((fill-column . 80)))
...
3
votes
Accepted
How to highlight “constexpr” in cc-mode?
The incantation you want is:
(font-lock-add-keywords 'c++-mode
'(("constexpr" . 'font-lock-keyword-face)))
3
votes
Accepted
CC-Mode - Javadoc Comment Colors in C/C++
After fiddling a bit longer with this, I think I figured it out. Adding the following snippet to my CC-mode init-configuration fixed this:
(defun my-cc-init-hook ()
"Initialization hook for CC-mode ...
3
votes
Accepted
How do I find the variable or lisp code controlling a face at a particular column?
You can use describe-char or C-u C-x = (= what-cursor-position with a prefix arg) to obtain a buffer giving as much information as possible about the character at point : font, syntax, properties and, ...
3
votes
Create new major mode from cc-mode that allows comments with two dashes
I asked this question in Xah Lee emacs blog entry, and he gave me these suggestions:
i think it can be done, without much trouble. Read the elisp chapter
on syntax table. basically, add the -- to ...
3
votes
Accepted
Changing or adding compiling options in cc-mode
Thanks to the University of Wyoming I have been able to achieve the result with:
;; Make M-x compile smarter in order to guess language
(require 'compile)
(defvar compile-guess-command-table
'((c-...
3
votes
Accepted
Override c++-mode font lock
Font-lock use two phases:
The syntactic phase. In this phase, Emacs determines things like strings and comments.
The keyword phase, i.e. the normal font-lock rules.
If you want to make Emacs ignore ...
2
votes
Accepted
GNU Emacs - Space in compile command
This looks like a variant of Emacs bug #18745 (really a bug of Windows' CreateProcess() function and/or cmd.exe), apparently it applies to .exes when called via the shell. It works if you don't quote ...
2
votes
How to configure linum-mode in spacemacs?
You could put this in dotspacemacs/config:
(global-linum-mode)
(with-eval-after-load 'linum
(linum-relative-toggle))
The relative number line will be by default.
2
votes
How do I find the variable or lisp code controlling a face at a particular column?
I saw that you already solved this, but I thought that I could share the following anyway:
You can use Font-lock studio (an interactive debugger for font-lock keywords) to single step each font-lock ...
2
votes
How do I find the variable or lisp code controlling a face at a particular column?
How embarrassing. A few minutes after asking the question, the solution came to me. I might make the case that the asking of the question led to the solution, though.
In any case, the answer that ...
2
votes
Accepted
Minor modes not working with derived mode from c++-mode
company-mode is just a framework. If you want completions from company-clang, try adding your major mode to company-clang-modes.
But if you only created a new major mode for minor reasons like new ...
2
votes
Accepted
C++ Incorrect Enum Indentation
If it happens with emacs -Q, file a bug report with M-x bug-report.
If you verify that this doesn't happen on Emacs 24.4, you can even:
Send an email to the dev list. It's likely that the person who ...
2
votes
Emacs indent with tabs to 2 columns
The Ruby editing mode defines ruby-indent-tabs-mode and sets indent-tabs-mode to that value when the mode is invoked. The default for this is nil. To fix your problem, set this variable instead.
...
2
votes
cc-styles c-offsets-alist setting for C++11 lambda brace indentation
In some recent versions of Emacs, there's actually a new syntactic element available to handle lambdas: inlambda. This might be a bit clearner to use rather than a custom specifier function. As an ...
2
votes
Stop reindenting `if` after `else`
I guess one way is to simply unmap the undesired keys from the mode's keymap:
(eval-when-compile
(require 'cc-mode))
(defun my-c-mode-hook ()
"My `c-mode' hook."
(define-key c-mode-map (kbd ",")...
2
votes
Stop reindenting `if` after `else`
You could make c-mode follow your style like this:
(defun lineup-if-with-else (context)
(pcase context
(`(substatement . ,anchor)
(save-excursion
(back-to-indentation)
(when (...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cc-mode × 68indentation × 23
c++ × 10
font-lock × 5
syntax-highlighting × 4
c × 4
comment × 3
c-mode × 3
spacemacs × 2
debugging × 2
faces × 2
flycheck × 2
region × 2
tabs × 2
syntax-table × 2
directory-local-variables × 2
balanced-parentheses × 2
java × 2
derived-mode × 2
helm × 1
osx × 1
hooks × 1
search × 1
major-mode × 1
company-mode × 1