Questions tagged [comment]
is for distinguishing comment lines from code. Emacs uses the same key bindings for manipulating comments in different modes. Emacs handles all the different ways of inserting comments for each of the major modes. Use additional tags to indicate language-specific modes for questions about comments.
149 questions
23
votes
1
answer
4k
views
Emacs Lisp comment conventions
The Emacs Lisp Reference Manual's Appendix D.7 mentions some comment tips:
Single semicolons (;) should be used for inline comments.
Double semicolons (;;) should be used for line comments.
Triple ...
21
votes
1
answer
4k
views
How to automatically create neat C comment blocks while typing?
Some code editors such as eclipse automatically form neat blocks when you start typing a multi-line comment:
Is there some package or another way to do this in emacs too?
Edit: To clarify: I do not ...
19
votes
2
answers
2k
views
How to detect if the point is within a comment area?
How to detect if the point is within a comment area?
19
votes
2
answers
1k
views
Is there fully-automatic fill-paragraph-mode for code comments?
I'm looking for a minor mode to keep paragraphs filled at all times while typing (similar to what aggressive-indent-mode does for indentation). It also needs to be smart enough to only fill comments (...
13
votes
2
answers
2k
views
Function to delete all comments from a buffer, without moving them to kill ring
I need to be able to remove all comments from a buffer from elisp code. For now, I am using:
(goto-char (point-min))
(comment-kill (count-lines (point-min) (point-max)))
However, comment-kill is an ...
13
votes
1
answer
1k
views
How to change comment string used by comment-region?
Emacs generally comments regions well, but sometimes I wish I could change the string it prepends to lines. For example, in LaTeX, I would like to have a commented region only use a single % per line ...
12
votes
3
answers
1k
views
How can I detect if the current character is a comment character for that major mode?
I am working on this little function that pulls up the next line to the current line. I want to add a functionality so that if the current line is a line comment and the next line is also a line ...
10
votes
2
answers
2k
views
Commented lines shoot off to column 32 in octave-mode
I am using the octave major mode for editing my MATLAB code, since it is more convenient than the unsupported MATLAB packages for emacs on the internet.
One downside is whenever I try to auto-indent ...
9
votes
2
answers
4k
views
How to change comment character from # (hash) to % (percent sign) for Octave major mode
By default, comment-region inserts # for comments in Octave major mode:
# foo
I want to modify the behavior so that it inserts the percent sign
% foo
I used the following
(setq octave-mode-hook
...
9
votes
4
answers
1k
views
Syntax highlighting for comments starting with specific sequence of characters
In clojure, the comment character is ;. clojure-mode syntax highlighting + color scheme greys comment text out.
I want emacs to color lines that begin with ;-; with a different color.
For example:
...
9
votes
1
answer
729
views
Hide comment in current buffer
Is their a way to hide comment whatever the language used?
Like if I'm in cpp mode all /* ... */ should be hide and if I'm on LaTeX mode, all % ... will be hide.
9
votes
1
answer
497
views
How comment out a variable line in a local variable list
In a python file I have
# Local Variables:
# python-shell-interpreter: "python3"
# python-shell-virtualenv-path: "~/.virtualenvs/datascience"
# leo-python-args-to-send: "-f fqanalysis.txt"
# End:
...
7
votes
4
answers
779
views
How do I disable ffap (find file at point) when the first two non-space characters in a line are '//'?
In Verilog/C/C++, comments can begin with //.
Here's an example comment,
//This is a comment
I like to use the find-file-at-point feature. If my cursor is on the file name in `include "some_file.v"....
7
votes
1
answer
742
views
How to implement comments outline in ESS similar to that of Rstudio?
Shifting from Rstudio to ESS took some time with me because of the steep learning curve of a versatile Emacs editor, but is was a worthwhile experience. What I am still missing in ESS is that outline ...
7
votes
1
answer
186
views
Modify org-mode's definition of comment lines?
Q: how do I change org-mode's definition of a commented line?
According to the manual, org-mode comments work as follows:
Lines starting with zero or more whitespace characters followed by one '#' ...
6
votes
2
answers
742
views
Three-characters comment syntax
Emacs supports syntax flags for 1- and 2-characters comment delimiters. Can it be made to recognize and properly highlight 3-characters delimiters?
For example:
In Emacs Lisp:
;;; Headings
In C#...
6
votes
2
answers
787
views
Is there an emacs command to go to end of code line (before line comment and whitespaces start)
say you have that:
stuff
indented stuff # commented stuff
We already got move-beginning-of-line and back-to-indentation for the left side. Now, for the right side...
I'd love to know if you ...
6
votes
2
answers
473
views
How to search/isearch just comments?
Is it possible to perform a search/isearch just in comment regions of the text?
6
votes
1
answer
237
views
How to prevent emacs from fontifying empty part of the line?
As an example, if I start a one line comment:
;; Comment⏎
Emacs will fontify the the whole line, from the beginning of line, occupying the entire width of the window, as comment. This can be made ...
6
votes
2
answers
586
views
C++ mode: smartly use /*...*/ for comment-dwim
I want to adjust the behavior of comment-dwim when editing c++ files:
When a region is selected that either starts or ends in the middle of a line I would prefer /* ... */ comments. For the other ...
6
votes
0
answers
115
views
Code blocks in font-lock comments
I'm developing a major mode for a language that has doc comments. They look like this:
(** Foos three bars.
Better call this as [foo 1 b c].
Though of course [foo a b 1] works as well. **)
...
5
votes
2
answers
5k
views
Matching multiline comments in regex
I'm writing a major mode for a language that uses (* ... *) as comments.
I'm trying to match multi-line comments. e.g.
(*
foo
bar
*)
I was initially doing "(\\*.*\\*)", however, . doesn't match ...
5
votes
1
answer
585
views
Emacs auto-indenting comments in an unhelpful manner
New Emacs user here. Hitting enter after a semicolon commented line in any file type (.el and .lisp at the very least) indents the comment in a very unhelpful way that I have to assume is not intended ...
5
votes
1
answer
195
views
Using a different major mode in comments
A programming language that I use lets me format comments and docstrings using markdown, and then export my code and documentation to PDF.
When I edit the file, though, Emacs doesn't see comments as ...
5
votes
2
answers
375
views
Commenting out some JSX code section with Emacs 27 js-mode
When I comment out (M-x comment-dwim) some section of JSX code with the new js-mode in Emacs 27, it gives:
// <Grid rows={rows} columns={columns}>
// <Table />
// <TableHeaderRow /&...
5
votes
0
answers
460
views
How to setup comment-start and comment-start-skip?
Haskell has line comments starting with -- and multiline comments of the form {- ... -}. I'd like to make auto-fill-mode work for both of those.
Currently line comments are auto-filled correctly:
-- ...
4
votes
1
answer
2k
views
How can I comment a block of CSS or HTML in web mode?
I am using web-mode.el to edit my CSS and HTML files. I am 90% sure that I haven't touched it but, just in case I modified it in the past, you can find the actual web-mode.el file I'm using here.
I ...
4
votes
4
answers
5k
views
How can I create block (multiline) comments in Lisp code?
How can I do multiline / block comments in Lisp code - e.g. in the init.el.
In Python I would do it like this
"""Block
comment
"""
In C/C++ like this
/*
Block
comment
*/
...
4
votes
1
answer
395
views
Can I make "comment-region" comment empty lines?
In LaTeX code I can have:
Lorem ipsum dolor sit amet, consectetur
\begin{comment}
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis ...
4
votes
6
answers
538
views
Search for "foo bar" ignoring comments and newlines
How do I search for "foo bar" ignoring comments and newlines in emacs? For example, given the tex file fragment
blah blah foo % comment 1
% comment 2
bar blah blah
I'd like to be able to type "foo ...
4
votes
2
answers
633
views
White space being inserted before a semicolon in asm-mode
When I try to insert a semicolon in my code (in asm-mode) it seems to indent a certain number of tabs like this (usually 4 it seems):
D ;
And if I put another semicolon on the next ...
4
votes
1
answer
558
views
add a space after the comment delimiter
When I'm writing a comment and press M-j to continue the comment on the next line (using single-line comments), if I press it multiple times say because I want to leave the next comment line "empty" ...
4
votes
1
answer
236
views
How to convert single line comments to multiline comments?
I have a bunch of single line comment blocks in C-code that I want to change to multiline. Example:
// foo
// bar
should become:
/* foo
* bar
*/
How can I do this easily in Emacs?
4
votes
1
answer
510
views
How do I teach Emacs to re-wrap /* */ comments?
Is there an existing function, and if not how would I write one, that turns this:
/* asdasdasd asdasdasd asdasdasd */
/* asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd */
/* asdasdasd asdasdasd ...
3
votes
1
answer
35
views
Is it possible for hideshow to display both the start and trailing comment characters?
Running hs-toggle-hiding converts a C-style multi-line comment from.
/*
* This is a comment.
*/
To:
/* ...
Is there a way to collepse the comment to:
/* ... */
Instead?
3
votes
2
answers
337
views
Change behaviour of "comment-region" in org-mode tangled source blocks?
I am experimenting with using org-mode for some of my startup config, and adding (org-babel-load-file (concat user-emacs-directory "config.org")) to my .emacs.
Then I use a structure like the ...
3
votes
1
answer
329
views
How to prettify symbols inside comments?
I'm using prettify-symbol mode together with Pragmata Pro.el.
Ligatures work perfectly fine in the source code but for some reason with comments they don't. I think I'm missing something since it's ...
3
votes
1
answer
847
views
how to define color for part of a comment?
How to make colored some part of comment? Let comment be ;; This is James Bond diary. And I want to make "James Bond" in green.
There will be only a few such strings and no places where it will be ...
3
votes
2
answers
365
views
Is there a package for supporting two types of comments?
So, you would be able to setup it like this
(setq
one-line-comment "//"
multi-line-comment-start "/*"
multi-line-comment-end "*/")
And use one command to comment anything. If nothing is ...
3
votes
1
answer
248
views
Continue comment while editing lisp and when hitting enter
If I'm writing a comment
;; this is a comment
;; this is its second line
And I hit enter, I get a new line like this:
;; this is a comment
;; this is its second line
Instead of getting a new line ...
3
votes
2
answers
817
views
How to align both of comments and macro of multiple lines with space instead tabs for C/C++ code?
This is my configuration in init.el for C/C++ code which is default value in linux kernel:
(setq indent-tabs-mode t)
I'm using this style and won't change it to nil.
And indentation and alignment ...
3
votes
1
answer
130
views
disable strange comment behavior in AUCTeX
When I have a commented line in my TeX file, eg
some text that is not commented
|%% here is a comment
followed by more uncommented text
(the | represents point), and I hit RET, point is moved past ...
3
votes
2
answers
2k
views
How to get emacs to automatically insert block comment prefixes?
I would like to type source code comments of the form:
{- ...
3
votes
1
answer
153
views
Move point to just before end of a comment
Given that the point is right in front of a comment, how do I move it to the end of the comment, but before the comment end markers?
For example:
for a C++ // xxx comment, I would like to move the ...
3
votes
1
answer
65
views
How to treat region between conflict markers as comment?
While resolving complex conflicts manually, I usually want emacs to treat conflict markers and region between them as comment, since it breaks major-mode's syntactic analysis (fontification, electric-...
3
votes
1
answer
68
views
Can you mark the end of 'compilation' in an eLisp source file?
In all of my source files, in whatever language, I use some trick or other to end compilation and then add a documentation trailer in perldoc format from which I can generate a man page. I always keep ...
3
votes
0
answers
288
views
Can I use "comment-column" for comments in other modes than emacs-lisp-mode?
Emacs-lisp-mode distinguishes multiple kinds of comments.
; is an "end of line" comment when following code, or a "right-margin" comment obeying comment-column when indented with indent-for-tab-...
3
votes
0
answers
141
views
org-fill-paragraph leaves a comma at end of C style comment
In a src block when there is a C style comment /* ... */ doing an org-fill-paragraph would always put a comma just before the last star, like this:
/*
Some comment
,*/
Is there a way to stop it from ...
3
votes
1
answer
365
views
How to set web-mode to use single-line comment style instead of multi-line for JavaScript
When commenting C-style code like C++, JavaScript etc., I use single-line comments to be able to uncomment a previously commented region selectively, i.e
// This
// is
// a single-line style
// ...
2
votes
2
answers
363
views
Is there a way to comment within a line in elisp?
Is it possible to comment the string "emacs" below while keeping this code one line? If so, how?
(message "hi") "emacs" (message "hi!")