Questions tagged [functions]

use this tag for Elisp `functions` for their usage, definitions, re-definitions, defining aliases, and other standard features of function execution fundamental to Lisp programming languages. Add additional Elisp tags when the functions are about specific Emacs features.

Filter by
Sorted by
Tagged with
0
votes
1answer
28 views

How to run shrink-window-horizontally multiple times, or how to repeat a function multiple times in general?

I wanted to define a function to execute a command multiple times and ended up using fset: (fset 'my-shrink (kbd "C-u 43 C-x {")) Now, I want to include this in a function, like this: (...
1
vote
1answer
44 views

Referencing Lexically Bound Variable in Mocked Function

I'd like to mock a function for a unit test that I'm writing. I want the mocked function to count how many times it was called but I'm having issues related to the scope of the count variable. Here ...
2
votes
2answers
48 views

Call apply with a macro

Is there a way to expand a macro using a list of arguments? I tried using apply but then I get an error that the "function" my/x-becomes-nil is invalid. (defmacro my/x-becomes-nil (variable ...
0
votes
0answers
68 views

How do I run an Emacs function from the terminal with an argument?

I want to install icon font for that I need to run all-the-icons-install-fonts function. According to the documentation I have to type: emacs --batch -f all-the-icons-install-fonts in the terminal. ...
1
vote
1answer
20 views

How to use face-remap-set-base to substitute a face for another?

I'd like to locally remap a face to other custom face. The docstring reads: (face-remap-set-base FACE &rest SPECS) Set the base remapping of FACE in the current buffer to SPECS. This causes the ...
0
votes
1answer
32 views

Idiomatic way to prevent a function calling itself in elisp?

If I have a function which needs to know if it's calling itself, what is an idiomatic way to check for this situation? While I can always bind a symbol (with a name that's highly likely to be unique) ...
0
votes
1answer
33 views

How can I save a function defintion

I want to extend a standard Emacs function (package--save-selected-packages), but to cover my tracks I want to save the old defintion under a new name and then redintion teh standard function. I tried ...
3
votes
1answer
139 views

How to replace focus-out-hook with after-focus-change-function in emacs 27?

In my old emacs, I have defined the following code. (add-hook 'focus-out-hook (lambda () (save-some-buffers t))) After upgrade to emacs 27, it said focus-out-hook is obsoleted, and the new one is ...
1
vote
3answers
84 views

how to find number of arguments expected by an elisp function in emacs

I have some code that I use in my .emacs file that works with version 25.5 where the definition of windows--sanitize-window-sizes looks something like this: (defun window--sanitize-window-sizes (frame ...
0
votes
1answer
67 views

funcall/apply lambda

Please look at the following elisp expressions. (funcall 'lambda '() 1) ;; or (apply 'lambda '() 1 ()) The interpreter says that lambda is not a valid function for both the above expressions. Why? Is ...
3
votes
1answer
63 views

Combine two interactive functions

For example, I want to sort a file, then remove the duplicate lines. I run M-x sort followed by M-x delete-duplicate-lines. I wanted to combine them into a single interactive function. Here is an ...
0
votes
1answer
24 views

Collapse all #+RESULTS block present in the current buffer

The problem Because the output of some commands is pretty big, I need to collapse their corresponding #+RESULTS: block in order to read the important parts (the commands). The question Is there any ...
3
votes
1answer
1k views

Symbol’s function definition is void

I am trying to make an interactive toggle in emacs 27.0.90 When I eval-region no warnings or errors are shown. However, when I do (helm/toggle-frame) in ielm it throws Symbol’s function definition is ...
1
vote
1answer
76 views

How to call a function that is the value of a variable?

Can someone explain to me why the code below throws an error (void-function fn)? (let ((lexical-binding t) (fn (lambda (y) (+ y 4))) (x 4)) (pcase x (10 (- x 2)) (4 (fn x)))) ...
7
votes
3answers
1k views

Is everything in Emacs made of functions?

Being more used to Vim, I know that it was correct to think "everything in Vim is a macro" but what about Emacs? Is it fine/correct to think that everything is a function in Emacs?
3
votes
1answer
64 views

Inconsistent behavior when calling #'funcall with a macro

I would have thought that both of the funcall's the follow would have yielded the same result, but they don't and I'm trying to understand why. (defmacro test/z () "z") (funcall (function test/z)) ;;...
0
votes
3answers
47 views

How to find information about a function?

To be able to learn about functions on my own I would like to know where I can find information about them (within emacs or otherwise).
2
votes
1answer
47 views

Why can't I directly invoke the result of apply-partially?

I'm confused about return value of apply-partially. Documentation states that it returns a function, and source of the function shows that it actually retruns a lambda. But I can't invoke the return ...
0
votes
1answer
33 views

Convert function-quoted form #'… to string

I have tried (symbol-name x), but it doesn't work if the argument is a lambda: ok: #'execute-extended-command not ok: #'(lambda (&optional frame) (interactive) (message "hi 8"))
1
vote
1answer
39 views

general function to concat token at point with function and send to *R*

I'm moving my R setup over to emacs and ess -- and am struggling with the emacs / LISP customisation process. In an answer to another question, I learnt how to create a function that concats a ...
1
vote
1answer
45 views

Wrong type argument: symbolp, 10

I would like create function that ask me how length I want the Pomodoro but it say wrong type argument. (defun changePomoLength () (interactive) (set-variable org-pomodoro-length (read-string "...
2
votes
1answer
200 views

Why is function defined by defun not bound

intro Sometimes I want to generate a function programmatically as opposed to defining one with defun. You may wondering why I'd want to do this. Well, it's complicated but just bear with me for a ...
0
votes
3answers
130 views

Default argument when nil is provided

I'm writing a function which wraps org-export-as for use in html conversion of a file. In this function, I define the options for org-export-with-toc, org-export-with-section-numbers, and org-html-...
1
vote
2answers
44 views

Why does `narrow-to-region` complain that its args are not `integer-or-marker-p`?

I have some functions that depend on smart-parens code. (defun outer-paren () "Move point to the outermost parenthesis." (interactive) (ignore-errors (while t (up-list))) (sp-...
-1
votes
2answers
51 views

Add a number to every item in list

How do I add a number, say 2, to every item in a list? (setq x '(1 2)) (+ 2 x) (mapcar '2+ x) (loop for i in x do (+ 2 i)) (dolist (i x) (+ 2 i)) None of the above work.
1
vote
1answer
75 views

built-in function to return the argument itself

The line below shows the first element which is not nil. (message "%s" (cl-some #'(lambda (x) x) '(nil nil "hello" nil))) ;; Output: hello Is there a built-in function which is equivalent to (...
0
votes
1answer
41 views

Source C code of function 'apply'

I referenced C-h f apply for the source code of "apply", it prompts References C code is not yet loaded. but does not hint the destination file. Execute grep-find within Emacs repo thus return no ...
0
votes
2answers
50 views

How do I define a function to execute as a command with M-x? [duplicate]

I wish to M-x my-func and let my code run. This seems basic but where can I get more documentation about this, if possible inside emacs itself?
1
vote
1answer
33 views

Evaluate allows for combinations whose operators are compound expressions

I find the amazing power of scheme in sicp Exercise 1.4. Observe that our model of evaluation allows for combinations whose operators are compound expressions. Use this observation to describe ...
2
votes
1answer
96 views

How to introspect function & macro arguments in elisp?

Is there a programmatic way to access function/macro arguments, Something like this, which returns the the arg count and true if it accepts any number of additional arguments. eg: (number-of-...
0
votes
1answer
19 views

Usage of vhdl-mode's vhdl-compose-place-component function

The command vhdl-compose-place-component is supposed to create the text to place a component. I can't figure out how to specify which component it places, though. Right now, when I use it, it places a ...
1
vote
1answer
42 views

Use Elisp macro instead of two function arguments?

Is the following sort of shortcut macro possible to implement? (defmacro region-end-beg () "Replacement for '(region-end) (region-begin)' in source code" (...)) So that (buffer-substring (region-...
1
vote
2answers
54 views

I want to simplify repeated calls in my init.el file

I've got a lot of: (desktop-save-mode 1) (show-paren-mode 1) which I'd like to collapse into: (mapcar (lambda (fn) (fn 1)) '(desktop-save-mode show-paren-mode)) but I get an error: Symbol’s ...
0
votes
1answer
185 views

how to bind custom commands to keys in existing mode map?

I wrote some extra commands for Python mode: python-insert-quote and python-insert-double-quote. I want to have these commands be available in the minibuffer when python-mode is active. How can I add ...
0
votes
1answer
117 views

What is a better way to write this function?

(cl-defun filename-from-buffer (&key get-ext get-path) (let ((filename (buffer-name)) (pathname (buffer-file-name))) (setq ret (car (split-string filename "\\."))) (when get-path ...
0
votes
1answer
44 views

Force function evaluation when setting variable value? [duplicate]

I have these functions defined in my early-init.el. I'm trying to change the location of where my backups are saved and keep getting a Wrong type argument stringp (djm/emacs-cache "backups/"). early-...
0
votes
2answers
97 views

How to know whether a function is implemented in C or Elisp?

I want to switch some behavior in my .emacs based on whether I have the new native fast json-serialize which is implemented in C rather than Elisp. Is there a simple way to detect whether a function ...
1
vote
1answer
224 views

How to execute one line in the .emacs file?

To test a function definition, for example : (defun count-words-buffer () (let ((count 0)) (goto-char (point-min)) (while (< (point) (point-max)) (forward-word 1) (setq count ...
0
votes
1answer
42 views

How to set value vc-git-grep-template within function

I have a working sexp for configuration vc-git-grep: (setq vc-git-grep-template "git --no-pager grep -n -i -e <R> -- <F>") Then in dired-mode I evaluate M-x vc-git-grep and everething ...
3
votes
1answer
78 views

Octal character representation in keyboard macros

I generated a macro as a help for generating indices for words I have marked before. Now this macro looks as follows (fset 'index "\367\\index{\C-y") What does \367stand for and where can I look ...
0
votes
1answer
55 views

Is it possible to make a function local to the buffer?

I want to override the function helm-swoop-pre-input-optimize in man mode using its hook, but not anywhere else. Is there something similar to make-local-variable for functions?
1
vote
0answers
58 views

execute-kbd-macro apparently not working according to its doc?

The doc of execute-kbd-macro says: (execute-kbd-macro MACRO &optional COUNT LOOPFUNC) ... If MACRO is a symbol, its function definition is used. I tried M-: (execute-kbd-macro 'ignore). ...
5
votes
3answers
1k views

Are local nested functions possible in elisp?

It it possible to declare functions whose names are only available in the scope of another function, similar to let? e.g.: (defun my-fn (x y) (let ((my-local-fn (lambda (a b) (message "%S" (- a b)...
1
vote
2answers
59 views

' versus #' what are the differences and when should I choose one over the other? [duplicate]

Both seem to work equally well when mapping a function over a list, for example. (mapcar #'1+ (list 1 2 3)) ;; => (2 3 4) (mapcar '1+ (list 1 2 3)) ;; => (2 3 4)
4
votes
3answers
439 views

How to bind keys to a function which can be defined per-mode?

Currently I have variables defined with setq-local, this is useful for modes, so I can define variables only for a particular mode. How can this be done for functions? I'd like to have a function, ...
1
vote
1answer
314 views

Disable minor modes like flycheck-mode and flymake-mode by default

I disable the following the modes in init.el ;;flycheck-mode ;;flymake-mode ...
1
vote
2answers
248 views

How to save all modified buffers and kill emacs

I use the well known key-binding C-x C-c to quit emacs. However this command asks y/n confirmation to save modified buffers and if there are process buffers (eg. Shell) it also asks for yes/no ...
2
votes
1answer
70 views

trying to make a self-modifying function [duplicate]

I'm trying to make a function that returns a list of perfect numbers: A perfect number is a positive integer that is equal to the sum of its proper positive divisors For instance, 28 is perfect ...
5
votes
1answer
63 views

Can a symbol have a function, variable, and class?

Q: can one symbol refer to a function, a variable, and a class? Elisp is a Lisp-2 in which a symbol can have separate function and variable values. So, for example, I can define the following ...
1
vote
1answer
55 views

How to create a function with a computed name?

Let's suppose I have a string "foo" and want to create a function that would be an equivalent of (defun foo (...) ...). Is there a nice way to do it? I played with make-symbol and fset, but could ...