Pages

Sunday, June 28, 2026

Emacs disabled Commands

It's possible to configure Emacs to prompt the user before calling a function, thereby "disabling" a function. The function isn't totally inaccessible -- Emacs will let you run it if you want it to. I chose to do this with scroll-left, scroll-right, scroll-up-command and scroll-down-command as explained in the previous post.

Most keypresses call self-insert-command, which is itself a function. So what would happen if self-insert-command were disabled?

It turns out to be not as debilitating as you'd think -- only the alpha-numeric and punctuation keys are affected. When a modifier is used with a key (M-x, for example), there is no interruption. Likewise, the TAB key is allowed to pass, which makes completion easier.

When Emacs inhibits self-insert-command, it prevents the keypress from having its intended effect. It will say that the command is disabled because many users find it confusing. Then you'll have the options of:

  • (n) Not running the command
  • (y) Run the command and don't ask again
  • SPC Run the command just one time to try it
  • (!) Enable the command and all other disabled commands

The n, y, SPC and ! keys are not inhibited at this point, so the user doesn't get trapped in a set of recursive prompts.

So to invoke org-agenda, I'd press M-x o. Then I'd press SPC to enable the self-insert-command for "o." Then I'd press r followed by SPC, and so on. My keypresses are M-x o r g - a g TAB ENTER.

Thus, adding (put 'self-insert-command 'disabled t) to a cube-mate's init file is a harmless prank, something to try on April Fool's Day.

No comments:

Post a Comment

Thank you for taking time to comment. Please note that comments may be deleted if they:

* Contain link(s) to a domain outside USA or Canada or to a commercial enterprise.
* Include non-English words or characters.
* Are irrelevant to the subject matter of the post.

For posts older than 14 days, comments are moderated and require approval.