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 13:43:35 +0200 Message-ID: <878s3ndxqw.fsf@omarpolo.com> References: <87im2rcry3.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="6553"; 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 13:44:17 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 1lprCT-0001SU-Fw for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 13:44:17 +0200 Original-Received: from localhost ([::1]:53268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lprCS-0000LR-CH for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 07:44:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lprC1-0000Jj-7p for help-gnu-emacs@gnu.org; Sun, 06 Jun 2021 07:43:52 -0400 Original-Received: from mail.omarpolo.com ([144.91.116.244]:60850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lprBy-0000Gy-At for help-gnu-emacs@gnu.org; Sun, 06 Jun 2021 07:43:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1622979823; 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=bm+/1P61xcrboK+Mv0Rx3Y7ZIt2ELdVMcVhQqp69qgw=; b=dnIX2QRaJ51CRXl6iQTTee0eh3mdSYLg7gKGvdCR3kcjBlqxG3ZgJ7YgiYZIJfmgKs/1U3 PV7KvirmKao5b9ZJ5I6HvqULGWdooIW/XDoGTFf4dgBDXwTfxvN8quK5TWIPEY0dwXu7uC uqMklKUGBdJyZCsHzrE+1gq4rYRWQj0= Original-Received: from localhost (host-79-44-237-248.retail.telecomitalia.it [79.44.237.248]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id 073803b7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 6 Jun 2021 13:43:43 +0200 (CEST) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id c64471fe; Sun, 6 Jun 2021 13:43:35 +0200 (CEST) In-reply-to: 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:130578 Archived-At: martin-kemp@brusseler.com writes: > I would find it useful if there was a function that returns a list with the comment delimiter > > for the specific mode. Then one can select which one to get. I don't have a deep knowledge (or any knowledge at all really). Studiyng newcomment.el is probably the way to go, but as you can see from comment-dwim there are two variables `comment-start' and `comment-end' that holds the string for the start and end string of comments. They are respectively ";" and "" in elisp-mode, or "/*" and "*/" in c-mode, and so on. > 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 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