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

  • 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
    Sep 3 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.

  • 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
    Sep 3 at 22:21

Your Answer

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

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