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
0 answers
12 views

How to add spacemacs/evil functions to pulsar-pulse-functions?

I'm using emacs 28.1 with Spacemacs and after installing pulsar I'm wondering how to add the pulse functionality on certain events, such as, when going through search matches, scrolling up, down, etc. ...
user avatar
  • 101
0 votes
3 answers
29 views

Problems using a function reference from a plist

I'm trying to (funcall) a function reference I have in a plist. (defun helper-get-filename () "Argument Helper to get a filename." (read-file-name "-l <filename>: " "...
user avatar
  • 987
1 vote
1 answer
26 views

How can I create an alias for a function name?

Does Elisp allow the equivalent of an alias for a function name?
user avatar
  • 107
1 vote
1 answer
25 views

Is there some way to have a local defalias?

I have some very long function names I want to use short forms for in particular files, eg (defalias-local avlfn a-very-long-function-name) Is that possible, or is that something I may have to write ...
user avatar
  • 1,157
1 vote
1 answer
34 views

What makes an elisp function available with M-x [duplicate]

Why some functions in simple.el are invokable with M-x and some others aren't? For example I can do M-x what-line but I can't do M-x line-number-at-pos.
user avatar
  • 27
1 vote
1 answer
48 views

Extract org heading title without task count e. g. [0/0]

I would like to extract just the plain name of an org heading: I tried with (nth 4 (org-heading-components)) Example: * Some Heading Title [0/1] ;; cursor in this line when executing ** ...
user avatar
0 votes
1 answer
25 views

Function to clone and rename buffer and narrow to subtree

This is a continuation of another question of mine which stated: I would like to go to an org heading * [A] HeadingTitle :sometag:, then clone a buffer, rename it to "HeadingTitle" and ...
user avatar
0 votes
1 answer
31 views

Function to clone buffer, narrow it and rename it to the name of the current heading

I would like to go to an org heading * [A] HeadingTitle :sometag:, then clone a buffer, rename it to "HeadingTitle" and narrow it to this heading - all in one function. I know how to add the ...
user avatar
3 votes
1 answer
428 views

Why do people add their initials to the names of tailor-made functions added to their config file?

Is it a namespace trick to prevent future problems? I noticed a pattern in the Emacs community. When people create some tailor made function and insert it on their init files, they use a convention on ...
user avatar
1 vote
1 answer
49 views

Lisp function to parse shebang line?

Before I probably re-invent the wheel, has anyone written a function (or perhaps there's one somewhere in Emacs already) to parse the shebang line of the current buffer (or some specified buffer). For ...
user avatar
  • 141
1 vote
1 answer
66 views

How do I call a function within a lambda?

I would like to define a function that generates lambdas, as such: (defun my-func (FUNCTION) (lambda () (FUNCTION))) But when I evaluate the following (defun my-func1 () (message &...
user avatar
  • 288
3 votes
2 answers
51 views

Create a function that returns a new function definition

I'm creating a modular system for my use of Emacs, so I can call modules on the fly, as I need them. Just like a lazy call, but I must explicitly call them. Anyways, I found this riddle, I want a ...
user avatar
  • 257
0 votes
1 answer
55 views

How can a function be used as an alist value but be evaluated before its value is used?

I am using Chemacs2 and I want to set an environment variable in the .emacs-profiles.el, eg To clarify the problem .emacs-profiles.el is not executed it is read and I have updated the post with a ...
user avatar
  • 1,157
1 vote
1 answer
74 views

Validating Arguments to a Function

I would like to validate the argument to a function before its action is executed. The main concern is the passing of a void variable. How can I trap this? (defun is-it-bound(item) (if (boundp 'item)...
user avatar
1 vote
1 answer
74 views

redefine a function as wrapper for the old definition

I am trying to modify a package by redefining a function in it. However, I would like to call the original definition in the new definition. (kind of like extending a constructor in a subclass now ...
user avatar
3 votes
1 answer
31 views

command print no results with (interactive "r")

Consider this test function (tested in emacs -q): (defun foo (start end) "for testing purposes" (interactive "r") (when (region-active-p) (cons start end))) ...
user avatar
  • 1,710
1 vote
1 answer
426 views

Call an interactive function and pass argument to it in elisp without user input

I am new to elisp and am trying to write an Elisp function that calls org-pandoc-export-to-html5-pdf-and-open. org-pandoc-export-to-html5-pdf-and-open is an interactive function that will write to a ...
user avatar
1 vote
1 answer
49 views

Create a new named buffer with a function

I want to create a keyboard shortcut that will prompt me for a string and then open a new ansi-term buffer with that string as the buffer name. How would I do this?
user avatar
  • 481
0 votes
1 answer
59 views

How to temporarily change the definition of a function?

In the following code the function foo calls the outer f2 function. How to make it call the anonymous function bound within the let? (defun f2 () (message "outer f2")) (defun foo () (f2)...
user avatar
-1 votes
1 answer
32 views

Need to make a function that uses &rest and sums the rest of parameters together

I am learning ELISP and this function should gather any number of parameters plus N and return the sum. This what I've got so far and I cannot figure out where my error is. Also if a char is in the ...
user avatar
0 votes
1 answer
33 views

How to prompt for function use be used within a function?

Consider the following example function (defun simple-function () (dotimes (counter 10) (input-function))) This requires input-function to be hard coded within the definition of simple-...
user avatar
  • 288
0 votes
1 answer
100 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: (...
user avatar
1 vote
1 answer
59 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 ...
user avatar
  • 529
2 votes
2 answers
166 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 ...
user avatar
  • 1,439
0 votes
0 answers
259 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. ...
user avatar
  • 273
1 vote
1 answer
84 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 ...
user avatar
  • 314
0 votes
1 answer
44 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) ...
user avatar
  • 7,179
0 votes
1 answer
36 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 ...
user avatar
  • 1,041
7 votes
1 answer
535 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 ...
user avatar
1 vote
3 answers
236 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 ...
user avatar
0 votes
1 answer
145 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 ...
user avatar
  • 227
4 votes
1 answer
125 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 ...
user avatar
  • 227
0 votes
1 answer
52 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 ...
user avatar
  • 487
6 votes
1 answer
6k 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 ...
user avatar
1 vote
1 answer
202 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)))) ...
user avatar
  • 1,439
8 votes
3 answers
2k 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?
user avatar
3 votes
1 answer
138 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)) ;;...
user avatar
0 votes
3 answers
128 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).
user avatar
  • 1
2 votes
1 answer
79 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 ...
user avatar
  • 237
0 votes
1 answer
35 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"))
user avatar
  • 620
1 vote
1 answer
48 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 ...
user avatar
  • 147
1 vote
1 answer
105 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 "...
user avatar
3 votes
1 answer
250 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 ...
user avatar
  • 1,283
1 vote
3 answers
379 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-...
user avatar
  • 3,885
1 vote
2 answers
54 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-...
user avatar
  • 645
-1 votes
2 answers
65 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.
user avatar
  • 645
1 vote
1 answer
86 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 (...
user avatar
  • 113
0 votes
1 answer
75 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 ...
user avatar
  • 1,089
0 votes
2 answers
160 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?
user avatar
1 vote
1 answer
42 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 ...
user avatar
  • 1,089

1
2 3 4 5