How to pass arg in Emacs abstract function

111 views Asked by At

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?

1

There are 1 answers

0
user3341592 On

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!