I want to detect if selection made was activated and bind appropriate code for indent-region or ifselection mode was not activate - other code.

  • 1
    The question isn't clear. The title asks to just indent the region with TAB. The body asks how to indent the region if active and invoke some "other code" if it's inactive. Two different questions.
    – Drew
    Commented Sep 3, 2023 at 22:23

2 Answers 2


indent-for-tab-command - is default command that choose between indent-according-to-mode and indent-region automatically.

  • indent-according-to-mode - indentation for one line
  • indent-region - it indent region with indent-according-to-mode.

full code:

(defun indent-or-complete ()
    (if (looking-at "\\_>")
      ;; (indent-according-to-mode)


You don't have to do anything to get this behavior. This is how emacs behaves out of the box.

  • 1
    FWIW, I don't think this answers the question, which is how to invoke some "other code" if the region isn't active. But it does answer the question as expressed in the title. IOW, the question isn't clear.
    – Drew
    Commented Sep 3, 2023 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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