I'm using expand-region and experimenting with it trying to find the right key binding

As per expand-region README it binded to

(global-set-key (kbd "C-=") 'er/expand-region)

But I'm not satisfied, I thing it better keybind would be

(global-set-key (kbd "C-S-SPC") 'er/expand-region)
(global-set-key (kbd "C-SPC") 'er/contract-region)

Since we nomally use C-SPC to set-mark, which would be ovrrided by this config, but C-SPC when region selected will reset the region the reset to the current-cursor-position, so binding er/contract-region to C-SPC make sense so I did.

(defun my-contract-region()
    (if (use-region-p)

(global-set-key (kbd "C-SPC") 'my-contract-region)

but when using in I couldn't figure out the argument error

enter image description here

Edited 1:

Yes I turned on debugging but, still could'nt figure out why, :(

enter image description here

  • The message gives a good hint. Check that the functions get the right number of arguments. Also consider to use `call-interactively' for the calls. – Marco Wahl Mar 23 '18 at 11:17
  • @MarcoWahl samel problem when using call-interactively – rho Mar 23 '18 at 13:29
  • I recommend M-u as keybinding for expand-region. – Stefan Mar 23 '18 at 13:35
  • @Stefan M-u is binded to upcase-word which i use regulary. – rho Mar 23 '18 at 14:55
  • To make easier sense of the error message, load the source code (.el, not .elc) first. (And set variable debug-on-error to t.) And use C-h f to check the expected (i.e., mandatory minimal) number of args for each of the functions you are using. – Drew Mar 23 '18 at 15:07

After adding argument, er/contract-region is working perfectly, thanks @Drew @MarcoWahl I made the mistake using call-interactively Sorry, I don't really understand elisp. my final snippet looks like:

(defun my-contract-region()
      (if (use-region-p)
          (er/contract-region 1)
          (call-interactively 'set-mark-command)))

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.