all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Heime <heimeborgia@protonmail.com>
Cc: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Printing comment-start of various modes
Date: Tue, 13 Aug 2024 23:13:57 +0200	[thread overview]
Message-ID: <875xs486sq.fsf@gmx.net> (raw)
In-Reply-To: <LBSDc2yqSFbMJKahjiwB2Ny6csD_O9e3QvqqOyb5ScMMO-pT5mp314GtigLNK94M3gEAxZvoz46Yet5H957uTRRwp_ZU2DdsUUGT7_VjxRU=@protonmail.com> (Heime's message of "Tue, 13 Aug 2024 20:09:57 +0000")

On Tue, 13 Aug 2024 20:09:57 +0000 Heime <heimeborgia@protonmail.com> wrote:

> This function should print the value of comment-start for various modes,
> but I am not getting any comment-start outputs from it.
>
> (defun costart ()
>   "Loop through various major modes and print the value of `comment-start`."
>
>   (interactive)
>
>   (let ( (modes '(sh-mode perl-mode python-mode
> 		 emacs-lisp-mode lisp-interaction-mode
>                  org-mode tex-mode latex-mode texi-mode
>                  c-mode c++-mode f90-mode fortran-mode
>                  html-mode css-mode js-mode
>                  java-mode php-mode) )
>
>          (output-buffer (generate-new-buffer "Costart")) )
>
>     (with-current-buffer output-buffer
>       (insert "Mode \t\t Comment Start \n")
>       (insert "---- \t\t ------------- \n"))
>
>     (dolist (mode modes)
>       (with-temp-buffer
>         (funcall mode)
>         (let ((comment-start (or comment-start "None")))
>           (with-current-buffer output-buffer
>             (insert (format "%s \t\t %s \n" mode comment-start))))))
>
>     (switch-to-buffer output-buffer)))

You successively bind mode-specific value of comment-start in a
temporary buffer, and then switch to output-buffer to print the values,
but this buffer is in fundamental-mode, where comment-start has the
value nil by default.  Using the temporary buffer seems superfluous, you
could just use output-buffer:

(defun costart ()
  "Loop through various major modes and print the value of `comment-start`."
  (interactive)
  (let ((modes '(sh-mode perl-mode python-mode
			 emacs-lisp-mode lisp-interaction-mode
			 org-mode tex-mode latex-mode texi-mode
			 c-mode c++-mode f90-mode fortran-mode
			 html-mode css-mode js-mode
			 java-mode php-mode) )
        (output-buffer (generate-new-buffer "Costart")))
    (with-current-buffer output-buffer
      (insert "Mode \t\t Comment Start \n")
      (insert "---- \t\t ------------- \n"))
    (dolist (mode modes)
      (with-current-buffer output-buffer
        (funcall mode)
        (let ((comment-start (or comment-start "None")))
          (insert (format "%s \t\t %s \n" mode comment-start)))))
    (switch-to-buffer output-buffer)
    (fundamental-mode)))

Steve Berman



  reply	other threads:[~2024-08-13 21:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13 20:09 Printing comment-start of various modes Heime
2024-08-13 21:13 ` Stephen Berman [this message]
2024-08-13 21:32   ` Heime
2024-08-13 21:55     ` Stephen Berman
2024-08-13 22:10       ` Heime
2024-08-13 22:17         ` Stephen Berman
2024-08-14 15:59           ` Heime

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=875xs486sq.fsf@gmx.net \
    --to=stephen.berman@gmx.net \
    --cc=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.