2

I'm reading (info "(elisp) Command Overview"):

Variable: post-command-hook
: ... ...
: This hook is also run when Emacs first enters the command loop (at which point this-command and last-command are both nil).

Users may need to know the exact time point referred to here to determine how to utilize this feature. But after searching in (info "(elisp) Startup Summary"), no relevant information was found.

shynur
  • 4,065
  • 1
  • 3
  • 23

1 Answers1

3

The sequence to entering the command loop for the first time is:

main()                  /* defined in src/emacs.c */
Frecursive_edit()       /* defined in src/keyboard.c */
recursive_edit_1()      /* ditto */
command_loop()          /* ditto */
NickD
  • 27,023
  • 3
  • 23
  • 42
phils
  • 48,657
  • 3
  • 76
  • 115
  • The manual ([Summary: Sequence of Actions at Startup](https://www.gnu.org/software/emacs/manual/html_node/elisp/Startup-Summary.html)) currently says that Emacs starts mainly through 31 steps. I just want to figure out at which step the time mentioned in the question falls, or between which two steps. – shynur Aug 10 '23 at 06:11
  • 1
    Calling `normal-top-level` (and hence all of those listed steps) is (essentially) the very first thing that `command_loop` does. – phils Aug 10 '23 at 06:42
  • I suspect the call to `post-command-hook` in question will be the one near the top of `command_loop_1`. There are things about that code which I do not understand, though, so I can't say much more about it. – phils Aug 10 '23 at 06:58
  • It seems that whether to mention "*`post-command-hook` is also run when Emacs first enters the command loop*" in the manual is not important, because its value cannot be changed at the beginning of startup unless you modify Emacs C source code. – shynur Aug 10 '23 at 07:01
  • Perhaps the note is for users who are dumping their own Emacs executable. That might be a way to give it an initial non-nil value before the command loop is entered. – phils Aug 10 '23 at 07:04