[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Printing comment-start of various modes
From: |
Stephen Berman |
Subject: |
Re: Printing comment-start of various modes |
Date: |
Tue, 13 Aug 2024 23:55:05 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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