3

I want to be able to perform helm-swoop on an input error: on a compiler output buffer using C-x C-r, here is how I tried to achieve it.

(global-set-key (kbd "C-x C-r") (lambda () (interactive) (helm-swoop "error:")))

When I try to use it I get:

Keyword argument error: not one of (:$query :$source :$multiline)

I'm in a process of learning Emacs Lisp. Having this short cut would help speed up a workflow looking up compiler errors.

4

The (lambda () (interactive) ...) syntax is just fine. The problem you are encountering is with your invocation of helm-swoop. The arguments for that function must be keyed (preceded by their argument :keyword). C-h f shows that the signature is:

(helm-swoop &key $QUERY $SOURCE ($MULTILINE current-prefix-arg))

Try this:

(lambda (query)
  (interactive "sQuery: ")
  (helm-swoop :$query "error:"))

As @Tobias mentions, helm-swoop employs keyword arguments because it is defined by cl-defun. The cl-defun help page has a link to the cl info page "Argument Lists" which describes &key in more detail.

  • Thanks, you just made my day! Plain and simple answer. On the follow up: Is :$query a part of a language? I assume it is, but not sure. – A_P Sep 25 '18 at 12:46
  • 1
    Keywords are are self- quoting symbols that start with a ":" (so you don't need to use a "'" at the beginning). They are used for various things like denoting named/labeled arguments like that function. It occurred to me that you wanted to read user input. Try (lambda (query) (interactive "sQuery: ") ... ) – ebpa Sep 25 '18 at 12:56
  • 1
    Maybe mention that helm-swoop is defined by cl-defun. The help for cl-defun has a link to the cl info page for "keyword" arguments. – Tobias Sep 25 '18 at 14:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.