Is it possible to write a function with completion that act on region?

A mix of:

(defun function-style (style)
    (completing-read "Style: " styles-list)))


(defun function-style (beg end)
      (interactive "r")
  • I don't understand the question. The two functions take different arguments. What data are you going to work with in the function? What does “completion that act on region” mean: do you want to complete the content of the region, to use the region as default argument when called interactively, something else? Commented Jul 12, 2016 at 12:29
  • Please try to clarify the question, or it risks being closed as unclear.
    – Drew
    Commented Jul 12, 2016 at 14:51
  • I would like to write the function (defun my-function (beg end style) ....with completion for style
    – djangoliv
    Commented Jul 13, 2016 at 9:58
  • @djangoliv: I don't know what you mean by "completion for style". This said, my crystal ball tells me you probably don't want to create a new command but just write a new function to add to completion-at-point-functions.
    – Stefan
    Commented Jul 25, 2016 at 20:00
  • @stephan: As Tyler has understood, I wanted a solution for write the function my-function(beg end style) with list completion for style argument.
    – djangoliv
    Commented Jul 26, 2016 at 5:55

1 Answer 1


You can use any elisp functions to generate the arguments for an interactive call. The code you use should return a list that matches the function arguments:

(defun my-function (beg end style)
   (let ((string (completing-read "Style: " styles-list)))
     (list (region-beginning) (region-end) string)))
  <function body> )

See the the manual node (elisp) Using Interactive for details.

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.