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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
76 views

How can a region matched by "string-match" be commented out with "comment-region"?

I have this code: (when (string-match "^[ ]*\\\\usepackage{url}" (buffer-string)) (comment-region (match-beginning 0) (match-end 0))) I tested it on these lines: %% LaTeX file test The ...
Onner Irotsab's user avatar
0 votes
0 answers
23 views

Need an emacs function that reformats a comment, left and right padded

Context When writing a long text file that has some structure (program, TeX/LaTeX document, whatever programming or markup language), it can be handy to make structure visually salient into visible ...
Stéphane Gourichon's user avatar
2 votes
0 answers
31 views

What is (setq comment-style 'aligned) supposed to do?

First let me show a few things that work correctly. I am doing everything shown below using emacs -q foo.txt in a text buffer. I make these settings first: (setq comment-start "<<") (...
Lone Learner's user avatar
2 votes
1 answer
44 views

Why the number of spaces inserted by M-; is less than the number of spaces in comment-start and comment-padding?

I am using emacs -q and editing a text buffer foo.txt. I have added the following settings: (setq comment-start ">::") (setq comment-padding ":::<") Now if I select a region ...
Lone Learner's user avatar
0 votes
2 answers
91 views

How can I disable some code without commenting it out or removing it?

When I need to disable code without removing it, I comment it out. I find this clumsy, especially when the code is a function definition or some other kind of cohesive whole, such as: (global-set-key &...
Philippe-André Lorin's user avatar
1 vote
2 answers
56 views

How to Organize Comments into a Grid on Emacs?

I see this done a lot. Don't know what it's called. Don't know how to do it. See how the comments are all lined up? int myNum = 5; // Integer (whole number) float myFloatNum = 5.99f; /...
Matthaeus Gaius Caesar's user avatar
0 votes
1 answer
55 views

How to make comment-dwim comment from cursor position if its middle of the line?

I am using comment-dwim-line to comment out multiple lines. For this, I automatically move cursor always to the beginning of a line. I just want to use this behavior if the cursor is at beginning of a ...
alper's user avatar
  • 1,238
0 votes
1 answer
29 views

Colouring different parts of a comment

I want to change the colour of substrings inside comments in a buffer. So that text enclosed by braces are coloured differently. For the following bash comment, I want the text enclosed bf {} to be ...
Dilna's user avatar
  • 1,183
3 votes
1 answer
44 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 ...
Dale Amon's user avatar
0 votes
1 answer
47 views

Using general comment character used in programming languages

I am using highlight-regexp with a regexp pattern that includes the elisp comment characters ;;. How can I extend the pattern so that it adequately handle the general comment character for each ...
Dilna's user avatar
  • 1,183
1 vote
1 answer
71 views

Using a sub-expression for `highlight-regexp`

I have made a face to highlight elisp comments starting with ;; [ using hi-lock. My intention is to only colour the expression [text] using SUBEXP. (highlight-regexp "^;; \\[.+\\].+$" 'face-...
Dilna's user avatar
  • 1,183
0 votes
0 answers
32 views

Keeping specific comments with bold weight

I am using a bold typeface, but for comments I am using normal weight. But I would like that some specific comments to remain displayed with bold weight. The specific comments are those that start ...
Dilna's user avatar
  • 1,183
0 votes
0 answers
31 views

Setting file-local comment character

I am trying to set the comments character to * in conf-mode with this file-local line: * -*- mode: conf; comment-start: "*" ; comment-start-skip: "\\* [ ]*" -*- normal line * ...
quazgar's user avatar
  • 341
2 votes
1 answer
79 views

How to make comment-dwim comment out the current line when there is no active region?

This question is about changing the behavior of comment-dwim when no active region is defined. The current behavior is defined below (from C-h k), which is kind of complicated and not what doing what ...
tinlyx's user avatar
  • 1,280
0 votes
1 answer
47 views

How can I make this lisp function more general? [closed]

I've recently made this little function: (defun luctins/rust-continue-comment () (interactive) (if (nth 4 (syntax-ppss)) (let ((co (concat "\n" (...
Luctins's user avatar
  • 120
1 vote
1 answer
77 views

how to break apart text into lines of a specified max width

I am writing long, descriptive text above a line of code and would like to format it into comment lines of a specified max width, while not splitting text mid-word. How can I do this? For example, I ...
mark's user avatar
  • 263
0 votes
1 answer
80 views

How to comment out multiple or all files in a directory?

I frequently use commands like paredit-comment-dwim, comment-dwim, and comment-region. I am also aware these commands can have a compound effect with the mark command. But, I would like to comment ...
Pedro Delfino's user avatar
0 votes
0 answers
49 views

ess font-lock-add-keywords not working

For several years I have been using this bit of code in my init.el file to organize comments. Here is the code ` (defgroup ess-jb-faces nil "Faces used by cutomized ess-mode" :group '...
Jacob's user avatar
  • 21
0 votes
2 answers
135 views

keep org-mode comments on export

I am drafting a document in org. Because I will have some coauthors, I will have to switch to LaTeX at some point. I am usually putting a very short description of the paragraph on top: # why do we ...
gdkrmr's user avatar
  • 175
0 votes
1 answer
119 views

Comment continuation in block comments

It used to work in c-mode, but I cannot get it back, and now I miss it in rustic, too: If in a block comment, I want Emacs to insert "\n * " after I hit return: /** *<-- [if I hit return ...
Markus's user avatar
  • 101
1 vote
2 answers
92 views

How to execute Elisp code embedded in c++ comment?

While I found lots of sources, how to use Elisp in an org-mode document, what I try to do is not related to org-mode at all. My idea is to embed Elisp functions and calls of Elisp functions within ...
BitTickler's user avatar
0 votes
1 answer
172 views

To remove characters in the beginnings of lines

To add // in the beginnings of multiple lines I can use either string-insert-rectangle or string-rectangle (C-x r t). But how is it possible to remove these characters instead? This question is not ...
john c. j.'s user avatar
0 votes
1 answer
94 views

Adjust how comments work in markdown-mode

How can I adjust how M-; (comment-dwim) works in markdown-mode? Specifically, I'd like for it to not use delimiters for each line. As an example, in Markdown mode, if I commend a line like This is a ...
asmeurer's user avatar
  • 1,562
0 votes
1 answer
76 views

Comments in org capture templates

I have a lot of org capture templates defined in my .emacs file. I'd like to be able to add a "comment" into some of them - how would I do that? For example when I'm capturing a new GTD ...
Johan's user avatar
  • 315
1 vote
1 answer
38 views

How do I match comments where the start and the end character are the same?

I have a programming language I want to make a major mode for where both the start and the end characters of a comment are the same. Specifically #. # This is a comment # As you can see it can match ...
irishgreencitrus's user avatar
1 vote
1 answer
124 views

No comment syntax defined when tangling lua or vimrc code blocks

Resolution With help from commenters, I have things kind of working. I removed :comments link from Properties. I manually added comments to the top of every code block to replicate what :comments ...
Jason's user avatar
  • 111
0 votes
0 answers
123 views

Inheritance of font-lock-comment-delimiter-face

How does inheritance of font-lock-comment-delimiter-face work with font-lock-comment-face? The following uses a different colour for the comment delimiter by setting the foreground colour to font-lock-...
Dilna's user avatar
  • 1,183
1 vote
0 answers
74 views

How to properly use modify-syntax-entry flags to syntax highlight comments in Lua?

I made my own Lua major mode about a month back. There is one thing that is still not working: highlighting comments. At first, I simply added ("--.*" . font-lock-comment-face) to lua-font-...
Alan's user avatar
  • 37
2 votes
1 answer
54 views

How to hide comments and move them to a separate window?

I'm interested in hiding comments in code or structured text, but displaying them in another window; i.e. same buffer, two windows side-by-side, one showing the main text (code, or content), but ...
Jacob Lee's user avatar
  • 227
3 votes
1 answer
31 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?
ideasman42's user avatar
  • 8,395
0 votes
1 answer
131 views

Docstring - quotes or semicolons?

In the documentation I only see mention of using semicolons for comments and docstrings, but in elisp-documents I regularly see functions documented in double-quotes, such as in org.el: (defun org-...
xeruf's user avatar
  • 324
0 votes
1 answer
22 views

IntelliJ style comment block cannot be recognized

In java-mode, I find the IntelliJ style comment block /** ... */ cannot be recognized correctly. And I have checked that the value of comment-start-skip variable (inherit from c-mode) is set as "\...
angeldsWang's user avatar
1 vote
1 answer
50 views

How to update beg end with comment-region

Scenario: I have Emacs open with split window. Top window contains an R script. Bottom windows has the interactive R session. I want to be able to copy a region from the interactive window to the ...
Kevin Wright's user avatar
1 vote
1 answer
84 views

After setting syntax-propertize-function, comment is not being fontified with comment face

I'm trying to build a major mode for xwiki, where I'm defining {{{ verbatim }}} as a comment. So far, I've done (eval-when-compile (defconst xwiki-syntax-propertize-rules (syntax-...
ackerleytng's user avatar
3 votes
4 answers
3k 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 */ ...
buhtz's user avatar
  • 689
0 votes
1 answer
130 views

How to uncomment multiple expressions in Lisp code?

I am using Emacs, Slime, Paredit, and other packages to work on Common Lisp (SBCL). It is really useful to comment out multiple expressions while debugging. For instance, suppose I have these ...
Pedro Delfino's user avatar
0 votes
1 answer
57 views

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

I am using Emacs, Paredit, Slime to work on Common Lisp (SBCL). When I create a comment such as: ; test It is placed as expected. But if I press return in order to create a new line below ;test this ...
Pedro Delfino's user avatar
0 votes
1 answer
39 views

Auctex change default comment style for latex-mode

I want a double %% to start my comments in latex documents. I'have found two solutions suggested ;; solution 1 (add-hook 'latex-mode-hook '(lambda() (setq comment-start "%% "))) ;; ...
PinkCollins's user avatar
0 votes
2 answers
115 views

Commenting moves point unexpectedly

The usual behavior of comment-line is to move point to the next line. When commenting code within an Org source block, however, the point will jump to some previous line. For example, say that point ...
Lorem Ipsum's user avatar
  • 4,337
0 votes
1 answer
46 views

How add specifc string(ex: TODO) along with a comment character for a specifc mode?

Based on specific mode, by using a keybinding I want to add a TODO string that is preceded by an unique comment character. For example, (org-mode is exception since ** does not stands for comment and ...
alper's user avatar
  • 1,238
4 votes
1 answer
176 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?
Arne's user avatar
  • 409
0 votes
0 answers
99 views

Uncommenting not working on Javascript file

I am trying to use the block un-comment command C-x C-; but I am getting the error message "Can't find the comment end". I am writing Javascript code in an .html file. The block comment ...
Lucas Myers's user avatar
0 votes
0 answers
68 views

in Fundamental mode, give certain marked text a different face

I am trying to add a new comment character in fundamental mode, but I can't get it to work. Let me rephrase that, because I think it's an xy-problem. What I really would like to have is the ...
Roadowl's user avatar
  • 131
5 votes
1 answer
250 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 /&...
cjauvin's user avatar
  • 594
4 votes
1 answer
386 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 ...
Evan's user avatar
  • 143
3 votes
1 answer
171 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 ...
Peeyush Kushwaha's user avatar
0 votes
1 answer
62 views

Comment code using elisp

Input and desired output Original code Commented out code: C %% MODULE %% module_name C~ CPR C ## MODULE ## module_name lines of code ...
Prasanna's user avatar
  • 1,470
0 votes
0 answers
145 views

Custom comment with comment-line and comment-dwim

Basically, what I want to do is to customize comment-start and comment-end when invoking different commands to then call comment-dwim or comment-line with them. What I managed to do so far is the ...
Lhooq's user avatar
  • 230
0 votes
0 answers
31 views

AUCTeX highlight contents of comment environment as a comment

I sometimes use comment environment in my LaTeX documents. Is there a way to make AUCTeX display contents of this environment as a comment?
Sergey's user avatar
  • 249
0 votes
1 answer
145 views

Comment out / uncomment source blocks on state change in org-mode config file

I started to move my config file to an org-file just recently. I wondered if it was possible to use the TODO state to activate or deactivate source blocks in the entry under the heading. This way it ...
breathe_in_breathe_out's user avatar