Skip to main content
Share Your Experience: Take the 2024 Developer Survey
17 votes
Accepted

Emacs Lisp comment conventions

Actually, 3-and-more semi-colons stand for headings, where the more semi-colons you put the deeper the nesting of the heading. So it should look like ;;; Main heading ;;;; Sub heading ;;;;; Sub sub ...
Stefan's user avatar
  • 26.5k
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,310
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
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.5k
7 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
7 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

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.1k
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
  • 30.4k
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.1k
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.7k
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,486
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,855
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.5k
3 votes
Accepted

how to define color for part of a comment?

This answer is just a slight modification of Lindydancer's answer in the following link: https://emacs.stackexchange.com/a/20228/2287 It has been modified to highlight a double-quoted name -- e.g., ;...
lawlist's user avatar
  • 19.2k
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.5k
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.5k
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.2k
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.2k
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,124
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
  • 8,826
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,080
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.4k
2 votes
Accepted

add a space after the comment delimiter

I also ran into this issue. It is caused because in emacs-lisp-mode, comment-start is ";" whereas in c++-mode, it is "// " (note the space). The obvious fix would be to add a space to comment-start ...
Qudit's user avatar
  • 837
2 votes
Accepted

If I am in a comment (including empty lines), how do I get to the beginning of the comment?

You can use syntax-ppss to find out if the point is in a comment or not. When it is, it also provides information about where the comment started. The following code wraps this into a loop, skipping ...
Lindydancer's user avatar
  • 6,170
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.5k
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
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,657

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