6

Upon reading (emacs) Program Modes:

Entering a programming language mode runs the custom Lisp functions specified in the hook variable prog-mode-hook, followed by those specified in the mode's own mode hook (see Major Modes). For instance, entering C mode runs the hooks prog-mode-hook and c-mode-hook. See Hooks, for information about hooks.

Does it mean that C programming is running under prog-mode and c-mode?

Is prog-mode a universal mode for all the programs?

It additionally implies that prog-mode is a major mode like c-mode.

Nevertheless:

Major modes are mutually exclusive; each buffer has one and only one major mode at any time.

(from (emacs) Modes)

What does prog-mode do here, is it a minor mode but stated vastly in the major mode part?

9

Does it mean that C programming is running under prog-mode and c-mode?

No, because, as you later quote:

Major modes are mutually exclusive; each buffer has one and only one major mode at any time.

So your buffer can only be in one or the other.

Is prog-mode a universal mode for all the programs?

No, it is a universal parent mode for all programming modes.

It additionally implies that prog-mode is a major mode like c-mode.

Yes, prog-mode is a normal major mode derived from fundamental-mode. Similarly c-mode is a normal major mode derived from prog-mode. The difference is that prog-mode alone is quite bare, and is not intended to be enabled directly.

What does prog-mode do here, is it a minor mode but stated vastly in the major mode part?

No, it is a normal major mode. It is provided as a convention for major mode authors to derive their modes from, and as a convenience for users to more easily customise all their programming modes.

For example, if a user wants to enable show-trailing-whitespace in all their programming modes, they may first define a hook like the following:

(defun my-show-trailing-space ()
  "Enable `show-trailing-whitespace' in the current buffer."
  (setq show-trailing-whitespace t))

Instead of adding this function to the mode hook of every programming mode they use, like so:

(mapc (lambda (hook)
        (add-hook hook #'my-show-trailing-space))
      '(c-mode-common-hook
        emacs-lisp-mode-hook
        perl-mode-hook
        prolog-mode-hook
        ...))

They can instead simply add it to the mode hook of the parent mode, i.e. prog-mode-hook:

(add-hook 'prog-mode-hook #'my-show-trailing-space)

As such, prog-mode provides common settings for all programming modes derived from it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.