From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: martin-kemp@brusseler.com Newsgroups: gmane.emacs.help Subject: Using comment characters for specific major modes Date: Sun, 6 Jun 2021 11:05:50 +0200 (CEST) Message-ID: References: <87im2rcry3.fsf@omarpolo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24136"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: "Omar Polo" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 06 11:06:37 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpojs-00064x-Ln for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 11:06:36 +0200 Original-Received: from localhost ([::1]:42276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpojr-0005tP-9g for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 05:06:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpojJ-0005sx-Bn for help-gnu-emacs@gnu.org; Sun, 06 Jun 2021 05:06:01 -0400 Original-Received: from ip-15.mailobj.net ([213.182.54.15]:52222 helo=msg-4.mailo.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpojD-0003ht-AR for help-gnu-emacs@gnu.org; Sun, 06 Jun 2021 05:06:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=brusseler.com; s=mailo; t=1622970350; bh=5tm9h0dQmOwURciGGlyT2BbxaQYZE/NoCcl7RHBpig4=; h=X-EA-Auth:From:To:Cc:Date:Subject:MIME-Version:X-Mailer: Message-ID:In-Reply-To:Content-Type; b=c0zN3uZmR9D1J4Pf42z2MEvumjc3FwRHfsVBCf6Dv+LlCKyjzgQbxC7mGpTNUDF4V pEHsLkJ86sqD8zvZBuRXTnp6pJP6f6Le62lDSVczEeSIjqIWlmYw3fRnrz/B944plG EwTGcMs1PZVVWVXXGXr1YCGRadNIRFdJCawSL0t0= Original-Received: by www-8.mailo.com with http webmail; Sun, 6 Jun 2021 11:05:50 +0200 (CEST) X-EA-Auth: M5uQqgcuw+xgxuK2nIBp4f5OSie2LnIE+hkQ7e+9ld76vbvWt11IkdH+jozgX6Acn7//TpIzKcST4OLQIEo3QpgPkjsm0p+q X-Priority: 3 X-Mailer: COMS/EA21.01/r20210415 In-Reply-To: <87im2rcry3.fsf@omarpolo.com> Received-SPF: pass client-ip=213.182.54.15; envelope-from=martin-kemp@brusseler.com; helo=msg-4.mailo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:130575 Archived-At: I would find it useful if there was a function that returns a list with the= comment delimiter=20 for the specific mode.=C2=A0 Then one can select which one to get. From: Omar Polo To: martin-kemp@brusseler.com Subject: Re: Using comment characters for specific major modes Date: 06/06/2021 10:34:12 Europe/Paris Cc: help-gnu-emacs@gnu.org I've seen only now the reply from Stefan Monnier, which is (of course :P) better than mine, apologies. His explanation is indeed better. Sorry for the noise. Omar Polo writes: > martin-kemp@brusseler.com writes: > >> Am using the following expression to make a line composed of ";" of len= gth lena. >> >> >> >> The first two semicolons ";;" are for when I use elisp code. >> >> >> >> (setq-local s (concat ";; " (make-string lena ?\;))) >> >> >> >> But I want to change the starting ";;" to be the comment character of t= he major mode I am working with. >> >> >> >> For texinfo I want "@c", and for fortran-mode I want "c", and "!!" for = f90-mode. > > taking a look at how things like `comment-dwim' is quite educational. > The comment handling is easy but there are a few gotchas, like not all > major-modes have a single "comment string" (like ";" in Lisp), some have > starting and ending comment string (like C with /* and */) > > I've come up with the following > > --------8<-------- > (defun insert-lena () > (interactive) > (let* ((lena 8) > (s (make-string lena ?\;))) > ;; this bit is stolen from comment-dwim > (if comment-insert-comment-function > (funcall comment-insert-comment-function) > (let ((add (comment-add nil))) > (indent-according-to-mode) > (insert (comment-padright comment-start add)) > (save-excursion > (unless (string=3D "" comment-end) > (insert (comment-padleft comment-end add))) > (indent-according-to-mode)))) > ;; insert the string > (insert s))) > -------->8-------- > > that seems to works. > > It uses comment-insert-comment-function or comment-start/end. I stolen > a bit from comment-dwim. > > In lisps buffer it inserts > > ;; ;;;;;;;; > > while in a C buffer it adds > > /* ;;;;;;;; */ > > Probably it doesn't do exactly what you want, and there are probably > edge cases when there is a region active or things like that, but it's a > good start (I think). > > HTH