Hot answers tagged

20 votes
Accepted

How to detect if the point is within a comment area?

Check the fourth* value in the list returned by syntax-ppss: (nth 4 (syntax-ppss)) It's nil if point is outside any comment, t if inside a non-nestable comment, or an integer (the nesting depth) if ...
user avatar
  • 5,834
16 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 ...
user avatar
  • 25.3k
12 votes

How to change comment string used by comment-region?

comment-add: comment-add is a variable defined in newcomment.el. Its value is 1 Local in buffer .emacs; global value is 0 Documentation: How many more comment chars should be inserted by ...
user avatar
  • 5,474
12 votes
Accepted

Function to delete all comments from a buffer, without moving them to kill ring

In general, there's nothing wrong with using commands as part of elisp code. Those functions which are only meant for interactive use will (or should) warn you about that. See next-line for instance. ...
user avatar
  • 22.4k
11 votes
Accepted

How can I detect if the current character is a comment character for that major mode?

You can check if the current character is a comment character by using the syntax table: (looking-at "\\s<"). The regexp \\s< will match any character with the "comment start" syntax; \\s> ...
user avatar
  • 12.1k
11 votes

How can I comment a block of CSS or HTML in web mode?

The web-mode shortcut M-; (which calls web-mode-comment-or-uncomment) works for me in HTML, CSS, and PHP files. For the first, this command puts <!-- --> around the region, for the second, /* */,...
user avatar
  • 2,605
11 votes
Accepted

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

Inside your hook put this: (setq comment-start "% "). Also, this will explain why: comment-region is an interactive compiled Lisp function. (comment-region BEG END &optional ARG) ...
user avatar
  • 10.9k
10 votes
Accepted

Three-characters comment syntax

AFAIK the example you give are actually 2-char comment delimiters, except that depending on the 3rd character, these comments are treated in different ways (but always as comments in the sense that ...
user avatar
  • 25.3k
9 votes
Accepted

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

This is a bit disppointing, because ffap.el has some code that should do just that: ;; Immediate rejects (/ and // and /* are too common in C/C++): ((member name '("" "/" "//" "/*" ".")) nil) ...
user avatar
  • 4,440
9 votes

How to detect if the point is within a comment area?

use the font-face, this is the trick I learned from flyspell. I tried syntax-ppss two years ago, it does not work for two reason: not work on edge of comment (comment limit), for example, for comment ...
user avatar
  • 4,611
9 votes
Accepted

Hide comment in current buffer

The package hide-comnt available from Melpa (now marmalade) can do it: M-x hide/show-comments-toggle
user avatar
  • 7,344
9 votes
Accepted

Commented lines shoot off to column 32 in octave-mode

I achieved what I wanted by overriding some definitions from the original major mode. In /lisp/progmodes/octave.el (the file was zipped, I had to unzip it to view the source), I redefined octave-...
user avatar
  • 425
8 votes
Accepted

How to automatically create neat C comment blocks while typing?

The below code works fine from my brief testing in a c-mode buffer: After typing /*, hit M-j, the default binding for indent-new-comment-line (and the default binding for c-indent-new-comment-line in ...
user avatar
  • 24.3k
8 votes
Accepted

How comment out a variable line in a local variable list

Based on a quick check of C-hig (emacs) Specifying File Variables, I'm reasonably sure that you can't. I think your options are: Move the comment outside of the local variables block. Change the ...
user avatar
  • 43.5k
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 ...
user avatar
  • 797
8 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 ...
user avatar
  • 2,185
7 votes

Commented lines shoot off to column 32 in octave-mode

Try using more than one % or # in a row: %% or %%% etc. By default, the number of consecutive comment chars determines the kind of comment and its behavior (e.g., with respect to indentation). See ...
user avatar
  • 69.7k
7 votes
Accepted

Matching multiline comments in regex

You will have to change the wildcard match to a non-greedy version (+?,??,*?). Ref: Emacs Manual: Regexp In this case: (\\*[\0-\377[:nonascii:]]*?\\*) That tells it to find the shortest full match,...
user avatar
7 votes

Function to delete all comments from a buffer, without moving them to kill ring

@Malabarba's answer looks like the simplest and most elegant solution. However, if you do this enough that it warrants its own function, you can also adapt comment-kill to delete without modifying ...
user avatar
  • 31.1k
6 votes
Accepted

How to implement comments outline in ESS similar to that of Rstudio?

I like orgstruct-mode. In the following file you can collapse headings with Tab or S-Tab, much like in org-mode. Note that the eval part below collapsed the file to out-most level when opening the ...
user avatar
  • 2,622
6 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 ...
user avatar
  • 25.3k
5 votes

Using a different major mode in comments

You can use poporg for this. People mostly use it to edit comments in Org mode, but you can use whatever mode you want by setting poporg-edit-hook. (remove-hook 'poporg-edit-hook 'org-mode) (add-hook ...
user avatar
  • 6,434
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 (...
user avatar
  • 31.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 ...
user avatar
  • 19.9k
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 ...
user avatar
  • 24.3k
4 votes
Accepted

Is there fully-automatic fill-paragraph-mode for code comments?

I came up with a minimal way of implementing this functionality: just bind space bar to also call (fill-paragraph)! (defun fill-then-insert-space () (interactive) (fill-paragraph) (insert " ")) ...
user avatar
  • 1,261
4 votes

key to toggle line comment in python

I don't know which version of Emacs you're using, but there is (will be) C-x C-; in Emacs 25, it runs comment-line that seem to have the behavior you want.
user avatar
  • 4,773
4 votes
Accepted

How to search/isearch just comments?

Yes. Use library Isearch+, specifically file isearch-prop.el. As it says here: You can search the text of THINGS of various kind (sexps, lists, defuns, lines, pages, sentences, filenames, strings, ...
user avatar
  • 69.7k
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 ...
user avatar
  • 31.1k
4 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 ...
user avatar

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