Re: Manipulating keymaps

[email protected] Thu, 18 Jun 2026 14:15:02 -0400
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
Dr Rainer Woitok <[email protected]> writes:

>
> Here goes:
>
>    $ emacs -Q lorem-ipsum
>
>    ; Emacs will open a window in "Fundamental" mode.   Enter the follow-
>    ; ing text:
>
>    #! /usr/bin/bash
>    #
>    # lorem ipsum, dolor sit amet consectetur adipisci velit, sed eius modi tempora incidunt, ut labore et dolore magnam aliquam.
>
>    ; Position the cursor on the "#" character preceding "lorem", and en-
>    ; ter "C-<blank> <down> C-u M-q", which results in
>
>    #! /usr/bin/bash
>    #
>    # lorem ipsum, dolor sit amet  consectetur adipisci velit, sed eius modi
>      tempora incidunt, ut labore et dolore magnam aliquam.
>
>    ; (because this is still "Fundamental" mode).  Manually add the miss-
>    ; ing comment symbol in the last line:
>
>    #! /usr/bin/bash
>    #
>    # lorem ipsum, dolor sit amet  consectetur adipisci velit, sed eius modi
>    # tempora incidunt, ut labore et dolore magnam aliquam.
>
>    ; Now enter "C-s C-c" to terminate Emacs, and open this file in Emacs
>      again:

Assuming that you meant "C-x C-c" instead.  This is bound to
the command ‘save-buffers-kill-terminal’ by default, in
Emacs 30.2.

>    $ emacs -Q lorem-ipsum
>
>    ; This time the  file is opened  using mode  "Shell-script[bash]" and
>    ; key "M-q" is bound to  "prog-fill-reindent-defun".   Now change the
>    ; file's contents to
>
>    #! /usr/bin/bash
>    #
>    # lorem ipsum, dolor sit amet  consectetur adipisci velit, ONE, TWO, THREE, sed eius modi
>    # tempora incidunt, ut labore et dolore magnam aliquam.
>
>    ; Again place the cursor on the "#" character preceding "lorem",  en-
>    ; ter "C-<blank> <down> <down> C-u M-q"  to again re-format these two
>    ; lines, BUT NOTHING HAPPENS,  the two lines don't change.

Using Emacs 30.2 (started from ‘emacs -Q’), with M-q bound
to the command ‘prog-fill-reindent-defun’, the text was
"filled", as expected.  Here is a copy of the resulting
text:

>  #! /usr/bin/bash
>  #
>  # lorem ipsum,  dolor sit amet  consectetur adipisci velit,  ONE, TWO,
>  # THREE, sed  eius modi tempora  incidunt, ut labore et  dolore magnam
>  # aliquam.

If I undo the most recent change (C-/), the text is:

>  #! /usr/bin/bash
>  #
>  # lorem ipsum,  dolor sit  amet consectetur  adipisci velit, ONE, TWO, THREE, sed eius
>  # modi tempora incidunt, ut labore et dolore magnam aliquam.

I can toggle back and forth between the two layouts by
typing M-q and C-/.  The cursor can be placed anywhere on
the text, from the ‘#’ before ‘lorem’ to the ‘.’ after
‘aliquam’.  It is not necessary to mark the text to get M-q
to reformat ("fill") the text, but I have used M-q with the
text marked and without, and get the same result.

Note also, that if, instead of typing M-q, I type M-x
prog-fill-reindent-defun, I get the same behavior.

Stepping through the source for ‘prog-fill-reindent-defun’,
each time it evaluated the expression:

   (fill-paragraph argument (region-active-p))

and after this expression was evaluated, the text was
reformatted.

Here is the ‘if’ expression in ‘prog-fill-reindent-defun’
that decides whether the ‘fill-paragraph’ expression is
evaluated.  Possibly someone can say why your Emacs is
choosing the ‘else’ path:

      (if (or treesit-text-node
              (nth 8 (syntax-ppss))
              (re-search-forward "\\s-*\\s<" (line-end-position) t))
          (fill-paragraph argument (region-active-p))
        (beginning-of-defun)
        (let ((start (point)))
          (end-of-defun)
          (indent-region start (point) nil)))

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.