unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Phil Sainty <psainty@orcon.net.nz>
To: Yuan Fu <casouri@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Calling another major mode in a major mode body
Date: Tue, 22 Nov 2022 13:44:07 +1300	[thread overview]
Message-ID: <efdadbce7a9d343974e2dbe0e0c53286@webmail.orcon.net.nz> (raw)
In-Reply-To: <1263D369-330F-4624-A376-ECC1E1A26A52@gmail.com>

On 2022-11-22 11:07, Yuan Fu wrote:
> So I wonder if it’s ok to fall back to another major mode by simply
> calling that mode.

I think the following describes what that would do.


Quoting myself from https://stackoverflow.com/a/19295380 (and as a
tangent I'd be happy for some adaptation of that to live somewhere
in the elisp manual, as I think it was a decent explanation of the
processes), when we call `child-mode', the full sequence is:

(run-hooks 'change-major-mode-hook) ;; actually the first thing done by
(kill-all-local-variables)          ;; <-- this function
,@grandparent-body
,@parent-body
,@child-body
(run-hooks 'change-major-mode-after-body-hook)
(run-hooks 'grandparent-mode-hook)
(run-hooks 'parent-mode-hook)
(run-hooks 'child-mode-hook)
(run-hooks 'after-change-major-mode-hook)
;; plus the following final step, since:
;; commit 2eb6817ba971184cc109f8530f4b3b38f65650ea
;; Add :after-hook facility to define-derived-mode.
(run-hooks delayed-after-hook-functions)


`delay-mode-hooks' is still in effect until child-body has returned,
so I believe calling (fallback-mode) within child-body would result
in this sequence:


(run-hooks 'change-major-mode-hook) ;; actually the first thing done by
(kill-all-local-variables)          ;; <-- this function
,@grandparent-body
,@parent-body
,@child-body
+    (run-hooks 'change-major-mode-hook) ;; actually the first thing 
done by
+    (kill-all-local-variables)          ;; <-- this function
+    ,@fallback-parent-mode-body
+    ,@fallback-mode-body
;; The child-mode binding for `delay-mode-hooks' is now out of scope,
;; so `run-mode-hooks' finally acts...
(run-hooks 'change-major-mode-after-body-hook)
(run-hooks 'grandparent-mode-hook)
(run-hooks 'parent-mode-hook)
(run-hooks 'child-mode-hook)
+    (run-hooks 'fallback-parent-mode-hook)
+    (run-hooks 'fallback-mode-hook)
(run-hooks 'after-change-major-mode-hook)
(run-hooks delayed-after-hook-functions)


It looks like things pushed onto `delayed-after-hook-functions'
would happen in this sequence, though:

- grandparent-mode
- parent-mode
- fallback-parent-mode
- fallback-mode
- child-mode

Although `delayed-after-hook-functions' does not seem to be
permanent-local, so in fact it might be this?

- fallback-parent-mode
- fallback-mode
- child-mode




There's also this, which doesn't seem entirely appropriate, but...

** New functions 'major-mode-suspend' and 'major-mode-restore'
Used when switching temporarily to another major mode, e.g. for 
hexl-mode,
or to switch between c-mode and image-mode in XPM.




  reply	other threads:[~2022-11-22  0:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21 22:07 Calling another major mode in a major mode body Yuan Fu
2022-11-22  0:44 ` Phil Sainty [this message]
2022-11-23  2:03   ` Yuan Fu
2022-11-23  2:15     ` Yuan Fu
2022-11-23  2:46     ` Stefan Monnier
2022-11-23 18:36       ` Yuan Fu
2022-11-23 19:21         ` Stefan Monnier
2022-12-04  7:54           ` Yuan Fu
2022-12-05 22:37             ` Richard Stallman
2022-12-05 22:50               ` Stefan Monnier
2022-12-08 23:07                 ` Richard Stallman
2022-12-09 12:56                   ` Stefan Monnier
2022-12-10 22:05                     ` Richard Stallman

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=efdadbce7a9d343974e2dbe0e0c53286@webmail.orcon.net.nz \
    --to=psainty@orcon.net.nz \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).