 <p>The right way to do it might be:</p> <pre><code>(defun my-grep-select(&amp;optional beg end) (interactive (if (use-region-p) (list (region-beginning) (region-end)) (list &lt;wordbegin&gt; &lt;wordend&gt;))) ...) </code></pre>