1

I do the following to activate the region and evaluate it

M-x spc  to begin mark
C-n 
C-n
C-n
M-x eval-region

The region is still active (highlighted) after the eval-region is performed.

I would prefer if eval-region evaluated the region and then deactivated the region, leaving the cursor after the code that was just evaluated.

I have this to start:

(defun e-eval-region (START END)
  "Execute region from START to END using `eval-region and unhighlight result."
  (interactive)
  (eval-region START END)
  (keyboard-quit))

How do I properly pass START and END of region to interactive?

1

Try this (drop the optional arguments, if you want):

(defun e-eval-region (start end &optional printflag read-function)
  (interactive "r")
  (eval-region start end printflag read-function)
  (deactivate-mark))
  1. Use C-h f interactive to see how to pass the region as two interactive arguments. For more information, see the Elisp manual, node Using Interactive. You can find that node in Emacs using C-h i, choosing the Elisp manual, and using i interactive RET.

  2. The command loop automatically deactivates the region after each command, unless the command takes special measures to prevent that - as does eval-region. You need only deactivate the mark explicitly to counteract that.

  • This is great, thank you Drew! I kept the optional arguments for completeness. – eflanigan00 Jul 23 '17 at 12:39

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.