Skip to main content
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 <...
ABu's user avatar
  • 290
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 ...
ideasman42's user avatar
  • 8,935
6 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))) ...
Mohammed Sadiq's user avatar
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) ...
theldoria's user avatar
  • 1,845
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 ...
Lindydancer's user avatar
  • 6,180
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, ...
YoungFrog's user avatar
  • 3,526
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 ...
Lindydancer's user avatar
  • 6,180
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 ...
pajato0's user avatar
  • 399
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 (...
npostavs's user avatar
  • 9,223
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 ",")...
Vladimir Panteleev's user avatar
2 votes
Accepted

How to use C++ comments "//" in c-mode?

Support for toggling between block-style and line-style comments was added a few months ago, and should be included in the next release. If you have a snapshot of the development version of emacs (...
Toon Claes's user avatar
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 ...
Xaldew's user avatar
  • 1,261
2 votes

prevent auto indent temporarily for multi line conditional, loops, etc

The Section "Customizing Indentation" of the cc-mode manual describes how to configure the indentation of c-mode. If cc-mode is properly installed on your system you can also reach the info version of ...
Tobias's user avatar
  • 33.4k
2 votes
Accepted

How to indent c++ "special" source lines that don't end with semicolons

I had the same problem with GENERATED_BODY() from UnrealEngine and so found your question. What works for me is to add to the buffer-local variable c-macro-names-with-semicolon and then call the ...
Seth Bruder's user avatar
2 votes
Accepted

Indenting within block comments in C-mode Emacs

The usual way to check if you are in a comment is to use syntax-ppss. A simple way to do what you want would be something like: (defun my/c-indent-or-tab-in-comment () (interactive) (if (nth 4 (...
dshepherd's user avatar
  • 1,281
2 votes

Indentation of multi-line arrays within braces?

The following setting makes brace lists use a single indent: (c-set-offset 'brace-list-intro '+)
ideasman42's user avatar
  • 8,935
2 votes
Accepted

converting c-mode hooks to use-package fails in non-obvious ways

The code after :config runs as soon as the package is loaded, which is when you config file is loaded unless you delay loading the package somehow. So the c-set-style function is getting called ...
erikstokes's user avatar
  • 12.9k
2 votes

Altering syntax highlighting for a particular expression

The following will do something similar to what you asked for. (let ((re "^[ ]*\\(exec sql\\)\\(.*\\)$")) (font-lock-add-keywords 'c-mode `((,re 1 font-lock-preprocessor-face t))) (...
Toothrot's user avatar
  • 3,284
2 votes

C/C++ mode aggresive auto indent

For listing all active modes press [C-h m]. Ensure, that these modes are disabled: Aggressive-Indent (local and global); Electric-Indent (local and global). Turn off this modes and check Emacs ...
Dunaevsky Maxim's user avatar
1 vote
Accepted

objc-mode: Comment-end face is not same face as comment-start

Emacs provides two variables, comment-start-skip and comment-end which font-lock use to determine which part of a comment should be in font-lock-comment-face and which should be in font-lock-comment-...
Lindydancer's user avatar
  • 6,180
1 vote
Accepted

Workaround for "Invalid search bound (wrong side of point)" in CC Mode

A big-hammer approach is to add cc-mode to your config, as it is maintained externally and tends to be very backwards-compatible. The latest version says "CC Mode 5.34 should work out of the box with ...
phils's user avatar
  • 51.8k
1 vote
Accepted

How to set tabulator size in the awk mode?

Try using c-basic-offset instead of awk-indent-offset. It is automatically buffer-local so should not affect c-mode or others. Complete answer, incl. avoiding tab characters: (add-hook 'awk-mode-...
wef's user avatar
  • 452
1 vote
Accepted

Customizing indentation style for continuation lines?

You'll want to modify c-offsets-alist for the "K&R" style by creating a new style and using that. Something like the following should work. (c-add-style "my/k&r" '("k&r" (c-...
nega's user avatar
  • 3,276
1 vote

How to re-enable syntax highlighting of code that have been disabled by #if preprocessor statements

It was emacs-cquery that shadowed code inside #if false regions. Setting cquery-enable-inactive-region to nil solved it.
Mikael Springer's user avatar
1 vote
Accepted

enlarge font of functions only in C code

(defun my-c-mode-faces () (face-remap-add-relative 'font-lock-comment-face '(:foreground "dark gray")) (face-remap-add-relative 'font-lock-function-name-face ...
lawlist's user avatar
  • 19.2k
1 vote
Accepted

Make wide string literal for C/C++

The following function transforms unicode strings into literal c-strings. Note however that the transformation is encoding dependent. For interactive use just write your c-string with multibyte ...
Tobias's user avatar
  • 33.4k
1 vote
Accepted

Update cc-style to use a mix of tabs and spaces, depending on context?

Smart Tabs is a mode that will do what you want -- indent with tabs, align with spaces. From the documentation, once you install it, you can disable it normally, but enable it in c-mode this way: (...
zck's user avatar
  • 9,112
1 vote

emacs cc-mode installation issue

cc-mode comes bundled with Emacs[0]. No manual installation needed. To make sure that cc-mode is available, just go to the scratch buffer and type (require 'cc-mode) place the cursor at the end of the ...
Hariharan's user avatar
  • 473
1 vote

How do I find the variable or lisp code controlling a face at a particular column?

In addition to what @YoungFrog offered, you can often find what a given face is at places where you cannot put the cursor, by using M-x list-faces-display. That will show you all faces currently ...
Drew's user avatar
  • 78.1k

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