From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.emacs.help Subject: Re: Using comment characters for specific major modes Date: Sun, 06 Jun 2021 10:34:12 +0200 Message-ID: <87im2rcry3.fsf@omarpolo.com> References: <87lf7ncs1f.fsf@omarpolo.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34267"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.0.50 Cc: help-gnu-emacs@gnu.org To: martin-kemp@brusseler.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 06 10:34:53 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 1lpoFA-0008UG-Vq for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 10:34:52 +0200 Original-Received: from localhost ([::1]:34474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpoFA-0006YB-0S for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 04:34:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpoEh-0006Y1-CI for help-gnu-emacs@gnu.org; Sun, 06 Jun 2021 04:34:23 -0400 Original-Received: from mail.omarpolo.com ([144.91.116.244]:60585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpoEe-0001CS-3c for help-gnu-emacs@gnu.org; Sun, 06 Jun 2021 04:34:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1622968458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0DD2fJUHbUM9cz6xc/cX35EVsMeucrL3MYhKAFTbJ4s=; b=WplgF6CDVGzQ4aH4pg14xhOvX8ExHdK8z4icNOEBc+/nOat1U3b+3N6wLDKVOasr8yUiUP tRyaNbXgpYcUoUSYqtgCCQ0rUXG8MgEbgUL8oK0xVmJ+EPMdQ0or7Ql9nJEhfeD5GrFxEf aifmH1//fO5xuMddQkhQthXVOh4D5ZQ= Original-Received: from localhost (host-79-44-237-248.retail.telecomitalia.it [79.44.237.248]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id 66d8eebb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 6 Jun 2021 10:34:17 +0200 (CEST) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id b5b1f0b3; Sun, 6 Jun 2021 10:34:12 +0200 (CEST) In-reply-to: <87lf7ncs1f.fsf@omarpolo.com> Received-SPF: pass client-ip=144.91.116.244; envelope-from=op@omarpolo.com; helo=mail.omarpolo.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:130574 Archived-At: 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 length 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 the 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= "" 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