People who code: we want your input. Take the Survey
13

Not everything is a function, no. For starters, Elisp (the language) has many other kinds of object besides functions. However, I think you're specifically asking whether every interactive action from the user is invoking a function behind the scenes; and the answer is still no. The majority of commands will be functions; but not all of them. Quoting from C-...


4

[I believe you meant sort-lines, not sort - that's the only way the question makes sense, so I am going to assume it.] Both sort-lines and delete-duplicate-lines operate on the selected region. You must select a region before calling them, otherwise they will complain that there is no region. So you are going to have to do the same thing in your function: ...


3

How to temporarily change the definition of a function? Calling a function by its (symbol) name means calling that symbol's function slot. So, to temporarily change the definition of a function that is called by its name, you need to temporarily modify its symbol-function value. The shortest way to do that is with cl-letf; see (info "(cl) Modify ...


3

One way is to use an interactive code to prompt you for the function. (defun simple-function (input-function) (interactive "aInput function: ") (dotimes (counter 10) (funcall input-function))) then you can write your own input like this perhaps, even using the counter variable from your loop. (defun myfunc () (message "%s: %s" ...


3

Well, you could define it this way: (defun my-shrink () (interactive) (dotimes (_ 43) (shrink-window-horizontally 1))) But that's not quite as elegant as this: (defun my-shrink () (interactive) (shrink-window-horizontally 43)) And since that's so short, maybe you don't even need to define anything at all. Just call (shrink-window-horizontally ...


3

No. As (elisp) Calling Functions tells us, for funcall (and it lets us know that apply is the same): Special forms and macros are not allowed, because they make sense only when given the unevaluated argument expressions. funcall cannot provide these because, as we saw above, it never knows them in the first place. I suggest that you think about what you ...


3

You could try using something like: (add-function :after after-focus-change-function #'your-function-here) So, in your case, something like this should do what you are after: (add-function :after after-focus-change-function (lambda () (save-some-buffers t))) If you look at the documentation of after-focus-change-function with C-h v after-focus-change-...


3

You define a local variable, then later call a non-existent function with the same name in the if: (if (helm-in-frame-p) Drop the surrounding parentheses and it should work again.


2

Emacs is a “Lisp-2”: functions and values have separate namespaces. A function definition (defun foo …) and a function call (foo …) use the function slot of the symbol foo. A variable assignment (setq foo …), a variable binding (let ((foo …)) …), and a variable reference x use the value slot of the symbol foo. To call a function which is stored in the value ...


2

In the emacs lisp sense, not everything is a function. functionp is a predicate to determine wether a symbol is bound to a function or not. (functionp 'set) t (functionp 'setq) nil set is a built-in function writen in C, setq a special form which don't evaluate all its argument like functions does.


2

Yes, I think so. Every key is bound to a function. Actually, a command, which is an interactive function (meaning a function the user can call during editing, not just by running elisp code). Adding a letter to a file is accomplished via the command self-insert, which is bound to most unmodified keys by default. I'm not sure how useful that is, but nearly ...


2

`funcall' is not supposed to be called with a macro as the FUNCTION argument. The Elisp manual says: The argument FUNCTION must be either a Lisp function or a primitive function. Special forms and macros are not allowed, because they make sense only when given the unevaluated argument expressions. ‘funcall’ cannot provide these because, as we saw above, ...


2

2nd Edit: Turns out there is a builtin, func-arity. It works exactly like the lambda-arity included below. Might be worth checking if it's defined in your emacs 25 though. 1st Edit: having re-read your use-case, maybe just do (if (< (string-to-number emacs-version) ... instead. Not built-in, no. There's help-function-arglist which returns the signature, ...


2

One common way to detect recursion without using a global variable is the use of an optional argument: (defun foo (x &optional recursed) "Frobnicate X." (unless recursed (foo x t))) You could even hide the optional argument from the function's API: (defun foo (x &optional recursed) "Frobnicate X." (declare (advertised-...


1

You can use symbol-function to obtain the current function slot value for a given symbol, which is typically what you'd be after here. You can store that value anywhere you want, and restore it later (perhaps with fset). I tried fset but that creates rather something like an alias from a new name to the old name, but it does not save the old definition... ...


1

The binding for variable example-settings is to a quoted list. The lambda form (lambda...) in that list isn't defined as a function there it's just a list. You can't expect the lexical binding of variable function-to-mock-call-cnt to be captured within that lambda - nothing indicates to Emacs that the list (lambda...) is a function. You can instead use a ...


1

In addition to function func-arity (which @Tommy mentioned), there is function subr-arity, for functions defined in C source code, not Lisp. C-h f subr-arity says: subr-arity is a built-in function in ‘C source code’. (subr-arity SUBR) Return minimum and maximum number of args allowed for SUBR. SUBR must be a built-in function. The returned value is a pair ...


1

(org-babel-result-hide-all) Fold all results in the current buffer.


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