all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin-kemp@brusseler.com
To: monnier@iro.umontreal.ca, help-gnu-emacs@gnu.org
Subject: Using comment characters for specific major modes
Date: Wed,  9 Jun 2021 17:42:18 +0200 (CEST)	[thread overview]
Message-ID: <ea-mime-60c0e15a-660c-68996ec2@www-8.mailo.com> (raw)
In-Reply-To: <jwvv96ru1fr.fsf-monnier+emacs@gnu.org>

I have found it easier to use a condition depending on the major mode of the buffer to set the comment

prefix directly.






From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 05:24:13 Europe/Paris

> That uses the command (comment-dwim ARG), but I got to get the comment characters
> to append to the string "s".
>
>   (setq-local s (concat ";; " (make-string lena ?\;)))
>
> At least that was my plan.  You may know the proper way to do it though.

Here's how you could go about finding the answer:

Seeing that `comment-dwim` manages to find the ";;" you're looking for,
you could look into it code: `C-h o comment-dwim RET` then click on the
link to jump to the definition. There you'll see:

[...]
(comment-normalize-vars)
(if (use-region-p)
(comment-or-uncomment-region (region-beginning) (region-end) arg)
(if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
;; FIXME: If there's no comment to kill on this line and ARG is
;; specified, calling comment-kill is not very clever.
(if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
;; Inserting a comment on a blank line. comment-indent calls
;; c-i-c-f if needed in the non-blank case.
(if comment-insert-comment-function
(funcall comment-insert-comment-function)
(let ((add (comment-add arg)))
;; Some modes insist on keeping column 0 comment in column 0
;; so we need to move away from it before inserting the comment.
(indent-according-to-mode)
(insert (comment-padright comment-start add))
(save-excursion
(unless (string= "" comment-end)
(insert (comment-padleft comment-end add)))
(indent-according-to-mode)))))))

And here you already see some functions and variable which might give
you some answers, such as `comment-add`,
`comment-insert-comment-function`, `comment-start`, ...
Using `C-h o` on those should fairly quickly lead you to:

comment-start is a variable defined in ‘newcomment.el’.
Its value is ";"
Local in buffer newcomment.el.gz; global value is nil

This variable is safe as a file local variable if its value
satisfies the predicate ‘string-or-null-p’.
Probably introduced at or before Emacs version 21.1.

Documentation:
String to insert to start a new comment, or nil if no comment syntax.

[back]


-- Stefan





  reply	other threads:[~2021-06-09 15:42 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-05 20:52 Using comment characters for specific major modes martin-kemp
2021-06-05 21:50 ` Jean Louis
2021-06-05 22:05   ` martin-kemp
2021-06-05 22:40     ` Jean Louis
2021-06-05 22:53       ` martin-kemp
2021-06-05 23:05         ` Jean Louis
2021-06-05 23:20           ` martin-kemp
2021-06-05 23:32             ` Jean Louis
2021-06-05 23:47               ` martin-kemp
2021-06-05 23:56                 ` Jean Louis
2021-06-06  0:17                   ` martin-kemp
2021-06-06  0:23                     ` Jean Louis
2021-06-06  0:39                       ` martin-kemp
2021-06-06  0:43                         ` Jean Louis
2021-06-06  9:14                           ` martin-kemp
2021-06-06  9:46                             ` Jean Louis
2021-06-06 16:02                             ` Stefan Möding
2021-06-06 16:23                               ` martin-kemp
2021-06-06 16:40                                 ` Jean Louis
2021-06-06 16:53                                   ` martin-kemp
2021-06-06 16:56                                 ` Jean Louis
2021-06-06 17:36                                   ` martin-kemp
2021-06-06 20:50                                     ` Jean Louis
2021-06-08  9:14                                       ` martin-kemp
2021-06-06  3:24             ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-09 15:42               ` martin-kemp [this message]
2021-06-06  8:32 ` Omar Polo
2021-06-06  8:34   ` Omar Polo
2021-06-06  9:05     ` martin-kemp
2021-06-06 11:43       ` Omar Polo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ea-mime-60c0e15a-660c-68996ec2@www-8.mailo.com \
    --to=martin-kemp@brusseler.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.