0

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

A mix of:

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

And

(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? – Gilles 'SO- stop being evil' Jul 12 '16 at 12:29
  • Please try to clarify the question, or it risks being closed as unclear. – Drew Jul 12 '16 at 14:51
  • I would like to write the function (defun my-function (beg end style) ....with completion for style – djangoliv Jul 13 '16 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 Jul 25 '16 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 Jul 26 '16 at 5:55
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)
  (interactive
   (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.

| improve this answer | |

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.