I had to solve a very similar problem in nadvice.el, so here is a solution (which uses some of the code from nadvice.el):
(defun wrapper (&rest args)
(cadr (interactive-form #'wrappee))))
(apply #'wrappee args))
Compared to the other solutions posted so far, this one has the advantage of ...
Of course it is possible inclusive the interactive specification. We are dealing here with elisp! (Lisp is the language where the most important constructs are lists. Callable forms are just lists. So you can construct them after your liking.)
Application: You want to add some functionality to some functions automagically. The extended functions should be ...
As @hatschipuh pointed out in the comments, an flet-type construction is more straightforward and doesn't rely on my idiosyncratic advice macro. At least on my Emacs (24.5.1), cl-flet uses lexical scoping, so you'll need the noflet package for the following snippet to work. Scroll down for the original, idiosyncratic answer.
The error is (add-to-list return nil). The first argument of add-to-list must be the symbol of the variable holding the list and not the list itself.
That means you have to write (add-to-list 'return nil) instead.
You can find such errors easily yourself if you use edebug.
I think you have lisp-interaction-mode or emacs-lisp-mode as major mode of the buffer ...
Emacs Lisp doesn't have any support for automatic type checking, whether in the byte compiler or at runtime.
The idiomatic way to report an error at runtime is to check the argument against a predicate function, and signal the error `wrong-type-argument if it doesn't match.
Furthermore, to express a choice between a small, fixed number of items, the ...
This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form
On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.
I read you question from top to bottom. When I ...
I generally recommend against doing that (better change the functions to take &optional or &rest arguments that are simply ignored), but if you must, the solution I recommend is:
(funcall f arg1 arg2 arg3)
(funcall f arg1 arg2)
No, there is no reason not to pass a non-nil value that has some other meaning (to a human reader, if not to the executing code).
It is common to do this, especially when there are multiple parameters, and especially if some are used in some call which are not used very often. That can help a (human) reader understand without needing to use C-h f to consult ...
The function sunrise-sunset is an interactive function takes a numeric prefix argument as a parameter. It does not take the latitude and longitude as parameters, which is what you're trying to pass into it. I suggest reading this emacs wiki article as well as of course the manual itself to learn more about prefix arguments. Also checking out the interactive ...
Standard elisp does not allow you to put restrictions on the arguments in the header in the way you're specifying, but you may wish to check out cl-defun in the Common Lisp extension library to get more options in your defuns.
In the meantime, a fairly simple way to handle your use case is to do a preliminary check before you get into the body of the ...
You've misunderstood the error. Emacs is complaining about the call to your function eshell-go-to-number-down; not the call to evil-numbers/inc-at-pt.
Your problem is that you have defined a function with an empty arglist (), and then given it an interactive spec of "p*" -- which supplies an argument when the function is called interactively.
See C-h f ...
Something like this, the new function to learn is apply:
(defun get-quotes (x &rest y)
(cons x y))
"Smith, \"Neural Pathways in Cat Brains\""
(dolist (thisarticle articles)
(if (stringp thisarticle)
org-agenda-todo calls the org-todo function interactively and in doing so, the it passes its own argument as it is to org-todo1.
From C-h f org-todo, you will get a complete understanding of what the values of ARG mean to org-todo (and org-agenda-todo):
org-todo is an interactive compiled Lisp function in `org.el'.
(org-todo &optional ARG)
Change the ...
As documented in the Info for Elisp:
The argument SYMBOL is not implicitly quoted; add-to-list is an
ordinary function, like set and unlike setq. Quote the
argument yourself if that is what you want.
Here's a scenario showing how to use add-to-list:
(setq foo '(a b))
=> (a b)
(add-to-list 'foo 'c) ;; Add `c'.
=> (c a ...
Another possible solution:
(defun neotree-go-to-upper-directory ()
(evil-define-key 'normal neotree-mode-map (kbd "h")'neotree-go-to-upper-directory)
call-interactively invokes the function exactly as it would have been with a keybinding, so it should work, in theory ...
It looks like you can call it like this:
(let ((calendar-latitude 40.1)
(calendar-location-name "Urbana, IL"))
This does not prompt you for the latitude and longitude, and puts a message in the minibuffer for those variable values.
set-mark-command (as the name suggests) is meant to be used as a command and not called as a function. For that reason, the docstring talks about the interactive uses rather than the case where you call it from Elisp code.
Once you're familiar with the "universal prefix argument" in Elisp, you can mostly decode the above docstring and guess that ARG will ...
There is the general rule that any widely used programming language such as R has an Emacs language mode and those modes also have functions that parse function arguments. For R there is the huge package Emacs Speaks Statistics.
There is a parser ess-r-syntax. The comment marks it as "not yet stable". But, there are 4 people working on it including senior ...
Under the theory that some answer is better than none, I've posted my hacky solution to this, however I would welcome a better answer than this one.
(defun find-next-fcn-arg-separator ()
"Find the next argument separator in a function call.
Move point to the next function argument separator. Point is
expected to be at the opening parenthesis of the ...
You can use split-string to split a string into a list of strings. Here's a simple example of a function that uses it for a minibuffer prompt:
(defun test-function (&rest args)
(interactive (split-string (read-from-minibuffer "Space separated list: ") " "))
(mapc #'message args))
Here's the code I have in my dot files. This code evolved over the years while maintaining backward compatibility; it should work with any Emacs or XEmacs version since the late 19.x series. If you only care about recent versions, the code can undoubtedly be simplified.
Stable Emacs releases offer subr-arity which returns a cons describing the argument length. This function has been extended to work in a more general fashion on the master branch, check out func-arity and the thread leading to it.
I'd generally advise against using this for more than tools helping you with elisp development (such as better error messages ...
I can't say I like the idea... but maybe I only need to get used to it. Anyway, I think you can come very close to your goal :
The function help-function-arglist tries hard to find the signature of any given function/subr ; this can be a starting point for rewriting your easy-going-funcall to handle more cases.
Another starting point is the source code of ...
From the package Neotree, I want to bind a key, that moves to the upper directory.
Here's what I came up with after a bit of exploration.
(defun neotree-go-to-upper-directory ()
"Go to the parent directory in the NeoTree buffer."
Please edit the question to make it clear if this is what you were looking for (see @...
edit: Tobias' answer is nicer than this, as it obtains the precise interactive form and docstring of the wrapped function.
Combining the answers of Aaron Harris and kjo, you might use something like:
(defmacro my-make-wrapper (fn &optional name)
"Return a wrapper function for FN defined as symbol NAME."
`(defalias ',(or (eval name)