Skip to main content
9 votes
Accepted

Can I make "comment-region" comment empty lines?

Customize option comment-empty-lines. comment-empty-lines is a variable defined in newcomment.el. Documentation: If nil, comment-region does not comment out empty lines. If t, it always ...
muffinmad's user avatar
  • 2,340
8 votes

Syntax highlighting for comments starting with specific sequence of characters

This is what I ended up going with: (defface special-comment '((t (:foreground "#2aa198"))) "Cyan") (font-lock-add-keywords 'clojure-mode '((";-;.*" 0 'special-comment t))) ";-;.*" is regex. 0 ...
deadghost's user avatar
  • 827
8 votes
Accepted

Emacs auto-indenting comments in an unhelpful manner

Unable to post this as a comment, but the indentation is likely part of one of the active modes (probably lisp-mode based on your description). You can do M+x describe-modes to see which modes are ...
einfeyn496's user avatar
8 votes
Accepted

How can I create block (multiline) comments in Lisp code?

Emacs Lisp doesn't have multiline comments. Neither does Python, for that matter. """…""" in Python delimit a multiline string. Emacs has multiline string literals, but ...
Gilles 'SO- stop being evil''s user avatar
7 votes

Is there a way to comment within a line in elisp?

For the usual meaning of "comment", the answer is mostly no (see Dan answer for details), but if you just want to prevent code from being executed, then you can simply do nothing in your case, since ...
Stefan's user avatar
  • 26.6k
7 votes

How to Organize Comments into a Grid on Emacs?

align-regexp is the interactive function that you can use. Here's how you do it Select the region that you want to apply the indent M-x align-regexp which will prompt you for a regexp Enter // and ...
shyam's user avatar
  • 170
5 votes

Is there an emacs command to go to end of code line (before line comment and whitespaces start)

Here's a quick command, lightly tested, that does what you're looking for. (defun eol-dwim () "Go to the end of the line, ignoring comments and trailing whitespace." (interactive) (let ((bol (...
Dan's user avatar
  • 33.3k
5 votes
Accepted

Docstring - quotes or semicolons?

That is NOT a comment: that's the doc string of the function. The doc string of the function is what you get when you ask for help on the function: C-h f org-before-change-function will show some ...
NickD's user avatar
  • 32.5k
4 votes

Is there a way to comment within a line in elisp?

It looks like the answer is no, you cannot. The elisp manual node on Comments states that: In Lisp, a semicolon (;) starts a comment if it is not within a string or character constant. The ...
Dan's user avatar
  • 33.3k
4 votes

How do I disable ffap (find file at point) when the first two non-space characters in a line are '//'?

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 ...
Kaushal Modi's user avatar
  • 25.9k
4 votes
Accepted

Is there an emacs command to go to end of code line (before line comment and whitespaces start)

The package mwim offers this functionality. By setting (global-set-key (kbd "C-e") 'mwim-end) you get behavior similar to what you described. The package also offers the corresponding mwim-...
clemera's user avatar
  • 3,476
4 votes
Accepted

How to comment from the start of the line in makefile-mode?

The 'cause' of this behavior is mentioned in the docstring of e.g. comment-region. You can simply adjust the behavior by configuring the comment-style, e.g. using: (add-hook 'makefile-gmake-mode-hook ...
dalanicolai's user avatar
  • 7,940
3 votes
Accepted

Elisp: Inserting Comments

I'd suggest the variables comment-start and comment-end as well as the function comment-region.
Stefan's user avatar
  • 26.6k
3 votes

How to change comment character from # (hash) to % (percent sign) for Octave major mode

The octave-comment-char was added specifically for your kind of use case, so all you should need is: (setq octave-comment-char ?%) No need to change the syntax table, since % is already recognized ...
Stefan's user avatar
  • 26.6k
3 votes

How to prevent emacs from fontifying empty part of the line?

(Thanks to @Lindydance) Here is what I am currently doing to get the effect I want: (define-minor-mode fontify-line-limit-mode "Make sure the highlighting doesn't extend beyond the end of line." ...
nialv7's user avatar
  • 203
3 votes

Emacs custom major mode with multiple comment types

Here are some tips to get you started: The (setq comment-start/end ..) needs to be within the define-derived-mode, not within that defvar of my-mode-syntax-table (otherwise it just sets the comment ...
Stefan's user avatar
  • 26.6k
3 votes
Accepted

How to prettify symbols inside comments?

When symbols are composed with prettify-symbols-mode is controlled by prettify-symbols-compose-predicate. By default this will only compose symbols if they are at a word boundary and not inside a ...
Prgrm.celeritas's user avatar
3 votes
Accepted

How to align "end of line comments" in sh-mode?

Your question How to indent all "end of line comments" at column 60? actually has two parts. How to indent at column 60. How to indent all end of line comments 1. How to indent at column 60 The ...
Tobias's user avatar
  • 33.5k
3 votes
Accepted

Why Emacs creates multiples whitespaces after I create a comment and jump to a new line?

Lisp has a more complex convention for comments than most languages, and automatic formatting respects this convention. It is documented in appendix D.7 Tips on Writing Comments of the Elisp manual (...
db48x's user avatar
  • 18.8k
3 votes
Accepted

How to uncomment multiple expressions in Lisp code?

In emacs, comment-dwim (bound to M-;) is its own inverse (AKA, involution): Insert or realign comment on current line; if the region is active, comment or uncomment the region instead I.e., to ...
sds's user avatar
  • 6,174
3 votes

Is it possible for hideshow to display both the start and trailing comment characters?

This can be done using advice on hs-make-overlay: (defun my-c-comment-end-skip-backward (pos) (cond ((and (eq (char-before pos) ?/) (eq (char-before (- pos 1)) ?*)) (- pos 2)) (t ...
ideasman42's user avatar
  • 9,027
3 votes

Using a sub-expression for `highlight-regexp`

By SUBEXP a match group is meant. Match groups are defined by \\( ... \\) and they are numbered 0 (for the whole match), 1 (for whatever is within the first \\( ... \\), etc. So the following would ...
orgtre's user avatar
  • 1,110
2 votes

How to get emacs to automatically insert block comment prefixes?

Emacs has supported various styles of multi-line comments since at least as far back as version 23. :) The variables of interest are listed below (see their documentation with C-h v). It is up to the ...
Basil's user avatar
  • 12.5k
2 votes

Syntax highlighting for comments starting with specific sequence of characters

You want to customize font-lock-syntactic-face-function. The function stored in that variable is called for every string and comment to decide which face to use for it. Of course, you'll want to set ...
Stefan's user avatar
  • 26.6k
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,301
2 votes
Accepted

disable strange comment behavior in AUCTeX

Add (setq LaTeX-syntactic-comments nil) to your init.el to disable the option LaTeX-syntactic-comments. According to the manual: User Option: LaTeX-syntactic-comments If non-nil comments will be ...
Arch Stanton's user avatar
  • 1,727
2 votes

Search for "foo bar" ignoring comments and newlines

I can fake this via C-hv search-whitespace-regexp It wouldn't be a full solution unless your comment marker character could never occur in any other context (e.g. the string "100%"). For testing ...
phils's user avatar
  • 52.4k
2 votes

White space being inserted before a semicolon in asm-mode

A quick hack to disable this confusing functionality entirely is: (advice-add #'asm-comment :override #'self-insert-command) Then pressing your comment character will just insert it like you were ...
Resigned June 2023's user avatar
2 votes
Accepted

C++ mode: smartly use /*...*/ for comment-dwim

The reason that c++-mode does not use the /* ... */ syntax is because the variables comment-start and comment-end are set to "// " and "" by default in C++-mode. Changing them to "/* " and " */" ...
Qudit's user avatar
  • 835
2 votes
Accepted

align doesn't indent multiple lines of C code correctly

align is aligning those // comments to the value of comment-column in that buffer, which will be column 32 by default. Your for statement extends beyond that column, so it is out of alignment. See C-...
phils's user avatar
  • 52.4k

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