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 inside a nestable comment. See the docstring for parse-partial-sexp for more details.
Note that this doesn't work with Org-mode, you should use ...
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 heading
;;;; Another sub heading
;;; Next main heading
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
comment-region. This determines the default value of the numeric
argument of comment-region. The plain comment style doubles this
This should ...
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
In order to delete, instead of killing, just make sure the kill-ring isn't changed:
(comment-kill (count-lines (...
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> will match those with "comment end" syntax.
Another option is the variable comment-start, which is the string inserted by comment-dwim and friends. It ...
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, /* */, and so on.
I also tried testing both comment-region and comment-dwim with web-mode enabled. Both functions had the same result: <!-- --> was placed ...
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)
Comment or uncomment each line in the region. With just C-u prefix
arg, uncomment each line in region BEG .. END. Numeric prefix ARG
means use ARG comment ...
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 the semantics of the code is unaffected).
So, the support offered by Emacs's syntax tables should be sufficient in most cirsumstances. If you want to highlight ...
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)
But unfortunately, it relies on there being a space after the comment separator.
It's also very disappointing, because comment markers should never be part of ...
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-indent-comment which originally goes like this:
(defun octave-indent-comment ()
"A function for `smie-indent-functions' (which see)."
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 like // this is comment in c++-mode, if you place the cursor over the / character, the result of (nth 4 (syntax-ppss)) is nil.
not work at all in major-mode ...
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 variable (e.g. give it a prefix like DISABLED:) such that the value is simply assigned to a variable which nothing uses.
If you don't want to have to ...
This is what I ended up going with:
(defface special-comment '((t (:foreground "#2aa198"))) "Cyan")
'clojure-mode '((";-;.*" 0 'special-comment t)))
";-;.*" is regex. 0 matches the entire expression. t overrides existing highlights.
More info on font-lock-add-keywords can be found here: https://www.gnu.org/software/emacs/manual/...
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 the Elisp manual, node
You will have to change the wildcard match to a non-greedy version (+?,??,*?). Ref: Emacs Manual: Regexp
In this case:
That tells it to find the shortest full match, rather than the longest.
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 c-mode). If it is the first comment line the closing closing characters */ will be auto-inserted.
Hitting M-j more times with insert more comment lines with ...
@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 the kill ring. Here's the source code of
comment-kill with the single-line change to define comment-delete:
(defun comment-delete (arg)
"Delete the first ...
Customize option comment-empty-lines.
comment-empty-lines is a variable defined in newcomment.el.
If nil, comment-region does not comment out empty lines.
If t, it always comments out empty lines.
If eol it only comments out empty lines if comments are
terminated by the end of line (i.e. comment-end is empty).
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 file.
x <- rnorm(10)
y <- x<0
##* sec 2
z <- x + y
## Local Variables:
## outline-regexp: "##*\\*+\\|\\`"
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 the execution of "emacs" will not have any visible effect. If you want to use it on elements whose execution does have visible effects, you can use
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 'poporg-edit-hook 'markdown-mode)
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
(let ((bol (line-beginning-position 1))
(eol (line-end-position 1)))
(if (condition-case nil
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 patch effectively does:
(defun modi/ffap-string-at-point (&optional mode)
"Return a string of characters from around point.
MODE (defaults to value of `...
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 ()
(insert " "))
(global-set-key (kbd "SPC") #'fill-then-insert-space)
There are a couple of caveat's that I've stumbled across so far:
elisp-mode (possibly others) does some ...
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, comments, xml/html elements, symbols,…), using command isearchp-thing. This is equivalent to using command isearchp-thing-define-contexts, which marks such ...
It looks like the answer is no, you cannot.
The elisp manual node on
In Lisp, a semicolon (;) starts a comment if it is not within
a string or character constant. The comment continues to the end
It also, however, goes on to say that:
The #@count construct, which skips the next count characters,
is useful for ...
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 active.
This answer provides some background on the history of the common lisp commenting style https://stackoverflow.com/a/6365579
This question and answers ...
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 as a comment starter. The important detail is that the above setq needs to be executed before octave.el is loaded (so its values is correctly propagated to ...