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:55:05 +0200	[thread overview]
Message-ID: <871q2s84w6.fsf@gmx.net> (raw)
In-Reply-To: <SIEuEAOTBkJv17d4XtiMtIscmSb31XWaFjtvZrcUOJHKnczk6jJAiUdyhWoBSgdirmD-A7wgGLAu8PGpoXvPQBhAYtzn5FxFaS45xmgzmp0=@protonmail.com> (Heime's message of "Tue, 13 Aug 2024 21:32:50 +0000")

On Tue, 13 Aug 2024 21:32:50 +0000 Heime <heimeborgia@protonmail.com> wrote:

> Sent with Proton Mail secure email.
>
> On Wednesday, August 14th, 2024 at 9:13 AM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>> 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
>
> What does it matter if the buffer is in fundamental-mode, when I am changing
> the major mode ?  I still do not get the dolist insert for each mode.

With the code I posted, I get this output (I evaluated and executed the
code after commenting out texi-mode and php-mode, because they were not
loaded in my running Emacs):

Mode 		 Comment Start
---- 		 -------------
sh-mode 		 #
perl-mode 		 #
python-mode 		 #
emacs-lisp-mode 		 ;
lisp-interaction-mode 		 ;
org-mode 		 #
tex-mode 		 %
latex-mode 		 %
c-mode 		 /*
c++-mode 		 //
f90-mode 		 !
fortran-mode 		 C
html-mode 		 <!--
css-mode 		 /*
js-mode 		 //
java-mode 		 //

If you don't get this output, I guess you didn't use the code I posted,
or something in your running Emacs changed how it works.  As for
changing output-buffer to fundamental-mode at the end, that's just to
restore its initial major-mode, otherwise it would have the major-mode
of the last major mode function evaluated (here, java-mode).

Instead of using comment-start as the let-bound variable, which in your
original code gets overriden by the value of the dynamically scoped
variable comment-start in output-buffer, you could use a variable name
that doesn't get shadowed, e.g. `cmnt-strt', for the let-bound variable.
Then you can keep the use of both the temporary buffer and
output-buffer.

Steve Berman



  reply	other threads:[~2024-08-13 21:55 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
2024-08-13 21:32   ` Heime
2024-08-13 21:55     ` Stephen Berman [this message]
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=871q2s84w6.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.