Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now
11

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) (interactive (advice-eval-interactive-spec (cadr (interactive-form #'wrappee)))) (apply #'wrappee args)) Compared to the other solutions posted so far, this one has the advantage of ...


11

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 ...


7

EDIT: 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. (defun my/bypass-...


6

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 ...


5

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 ...


5

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 ...


4

You are looking for the function apply. Use it as follows: (setq some-var '("-l" "-a" "-t" "-r")) (apply #'start-process "ls" "*temp*" "ls" some-var)


4

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: (condition-case nil (funcall f arg1 arg2 arg3) (wrong-number-of-arguments (condition-case nil (funcall f arg1 arg2) (wrong-number-of-arguments ......


4

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 ...


4

You have access from Emacs Lisp to information about the command line, such as its arguments (variable command-line-args). See the Elisp manual, node Command Line Arguments.


3

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 ...


3

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 ...


3

Here's how I'd do it: (defun my-ansi-term-prompt-for-name (orig-fun program &optional buffer-name &rest args) (apply orig-fun program (or buffer-name (let ((name (read-string "Tag: "))) (and (> (length name) 0) (concat "Term: " name)))) args)) ...


2

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 ...


2

Something like this, the new function to learn is apply: (defun get-quotes (x &rest y) (cons x y)) (let ((articles '("/home/matt/art/mice.pdf" ("/home/matt/art/cats.pdf" "Smith, \"Neural Pathways in Cat Brains\"" 3)))) (dolist (thisarticle articles) (if (stringp thisarticle) (get-quotes thisarticle) ...


2

Yes you can. You can use any value which isn't nil (noting that an empty list is the same thing as nil). That's precisely why the docs invariably use that awkward "non-nil" wording.


2

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 ...


2

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 ...


2

Another possible solution: (defun neotree-go-to-upper-directory () (interactive) (evil-goto-first-line) (call-interactively #'neotree-enter)) (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 ...


2

It looks like you can call it like this: (let ((calendar-latitude 40.1) (calendar-longitude -88.2) (calendar-location-name "Urbana, IL")) (sunrise-sunset)) This does not prompt you for the latitude and longitude, and puts a message in the minibuffer for those variable values.


2

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 ...


2

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 ...


1

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 ...


1

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))


1

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. (cond ;; XEmacs ((fboundp 'compiled-function-arglist) (defalias 'emacsen-compiled-...


1

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 ...


1

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 ...


1

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." (interactive) (neotree-dir "..")) Please edit the question to make it clear if this is what you were looking for (see @...


1

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) ...


Only top voted, non community-wiki answers of a minimum length are eligible