1

I try to write a function to abstract which helm-imenu variant to use:

(defun my/helm-menu ()
  "For Org mode buffers, show Org headlines.
For programming mode buffers, show functions, variables, etc."
  (interactive)
  (cond ((derived-mode-p 'org-mode)
           (helm-org-in-buffer-headings))
        (t
           (helm-semantic-or-imenu))))

Though, when using it in a non-Org mode buffer, it fails, saying it needs one argument.

Indeed, helm-semantic-or-imenu requires arg.

How should I pass that?

Why is that working with a M-x helm-semantic-or-imenu: where is the argument?

Community
  • 1
  • 1
user3341592
  • 1,419
  • 1
  • 17
  • 36
  • You should try to ask that on http://emacs.stackexchange.com – rsenna Jun 24 '16 at 21:52
  • You don't need to ask it on emacs.stackexchange.com. You can ask it here. – Drew Jun 25 '16 at 03:01
  • Use `C-h f helm-semantic-or-imenu` to find out what the argument is. Click the link there to go to the source definition and see what the argument is and how it is received. If that function is a command then check the `interactive` spec to see where the arg comes from. Then pass the same kind of arg to your invocation of that function. – Drew Jun 25 '16 at 03:03
  • @Drew, could you have a look at my answer to check that it's the right way to do it? Thx! As well, if you post an answer, I can give you the credit for that. – user3341592 Jun 25 '16 at 09:07
  • Looks OK to me (but I don't use Helm). If it works, it works. Apparently you found out that the `ARG` in this case is from the prefix argument. If so, you correctly provided that using `interactive`. No need to credit me. You can accept your own answer - nothing wrong with that. – Drew Jun 25 '16 at 13:56
  • OK, thanks for reviewing! – user3341592 Jun 25 '16 at 15:07

1 Answers1

0

Following Drew's piece of advice, this should do it:

(defun my/helm-menu (arg)
  "For Org mode buffers, show Org headlines.
For programming mode buffers, show functions, variables, etc."
  (interactive "P")
  (cond ((derived-mode-p 'org-mode)
           (helm-org-in-buffer-headings))
        (t
            (helm-semantic-or-imenu arg))))

At least, it works!

user3341592
  • 1,419
  • 1
  • 17
  • 36