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
5
votes
2answers
179 views

How to repeat a command immediately after calling it?

I've just called an interactive function (i.e., a command). I want to call it again, with the same arguments. I know that I can call a keyboard macro again by using e right after running it the ...
0
votes
1answer
92 views

a function to clear out particular words/characters via regex

I have a specific request to all you regex wizards :) I want to create a simple function that deletes or cleans out several parts of a text file based on predefined keywords (such as single capital ...
0
votes
2answers
51 views

windmove: write a function to move two times (e.g. down and right)?

I'm using the windmove package to move my cursor between windows. In addition, I want to define a function to move twice, e.g. down first and right second. The following function only do the "down" ...
1
vote
0answers
129 views

Sublime Text like Ctrl-Delete/Backspace

Is there any easy way (or maybe a package) which provides Ctrl-Del/Backspace behavior like in Sublime? The default rule of sublime is delete-to-next-word-boundary. I did not find similar options. ...
1
vote
1answer
52 views

Expression as var

Is it possible for a variable to be set to an expression that will be evaluated each time that variable is accessed? The idea would be that a user could then set the variable to be either a string or ...
1
vote
1answer
275 views

How to break out of function indirection loop

I have a problem that I suspect is a general Emacs problem. If I run a certain package, simple-rtm, and then try and use M-x to run any command, I get the error in the bottom line of the screen: ...
4
votes
1answer
34 views

Change the behavior of a function when the point is in a table

How can I change the behavior of a function when the point is in an org-table? Is there a function like "table-p" that returns true when the point is in a table (like region-active-p returns true when ...
2
votes
1answer
104 views

Command for inserting for-statement skeleton

How would one write a function that one could bind to, say, SUPER-f, which inserts the code: for () { } in the buffer with my cursor being moved into the () parens for filling out the loop guard?
3
votes
1answer
73 views

FORM vs BODY in documentation?

Recently I was trapped by void-variable error on eval-after-load. That is not first time I forget to quote args like: (eval-after-load 'sql '(progn ...)) because eval-after-load docs say: ...
1
vote
3answers
149 views

Is calling elisp functions expensive (time-wise)? [closed]

Reading code in the wild, I seem to see less of the "many small functions doing one thing each" pattern in emacs lisp. Might this be due to calling functions being expensive (like in Python), so that ...
2
votes
2answers
227 views

How to pass an argument from command to another command?

From the package Neotree, I want to bind a key, that moves to the upper directory. The upper directory is always on the top with .. (up a dir). So I go to the first line of the neotree buffer, and ...
1
vote
1answer
73 views

How to create named functions for dynamic key bindings?

I am creating a keymap based on a configuration file. The resulting keys all call the same function but with different arguments. Here is the code I am using for a single key: (defun add-do-my-stuff-...
2
votes
0answers
186 views

Is it worthwhile to write a wrapper for calling Julia or Python functions from emacs? [closed]

For writing efficient emacs functions, would it be worthwhile/not too difficult to write a C wrapper for calling Julia functions or for calling Python functions via Numba/pycc? For reference: Julia ...
5
votes
1answer
603 views

What is identity doing? [closed]

I've seen this sort of thing a few times: (mapconcat 'identity '("" "home" "alex " "elisp" "erc") "/") => "/home/alex /elisp/erc" which means mapconcatwants a function in the second position, ...
2
votes
1answer
82 views

Get a list of functions evaluated

I am trying to track down a weird bug in my emacs configuration - the cursor, occasionally, jumps to a random location when I am scrolling using the arrow keys, in cc-mode. I don't see any accidental ...
3
votes
1answer
143 views

Simple fill-sentence function

I am new to emacs and would like to make a simple function to automate a series of commands I use repeatedly. In auto-fill-mode after I edit the text I often need to re-wrap the lines. (I am writing ...
4
votes
2answers
1k views

How to pass a parameter together with function

This code opens 1-st & 2-nd bookmarks when 1 & 2 keys are pressed on bookmarks page: (defun jump-to-n-th-bookmark (n) (let ((bookmarks (sort (bookmark-all-names) 'string<))) (...
1
vote
2answers
247 views

Are keybindings mode-dependent? How can I customize this?

I have bound the eval-region function to H-x I would like to use this to simply highlight selected code and evaluate - simple. Working in a Python script I have the following code: def test(this, ...
1
vote
1answer
32 views

Defining a function that takes as an input the current buffer's path

I am hoping to define an interactive function that I can invoke with M-x <function-name> and that will: Automatically grab the path to the file Run the following code on it: (require 'tramp) ...
7
votes
1answer
1k views

Override a function locally, but allow calls to the original function

The advice feature allows modifying the behavior of a function globally. An advice definition can make calls to the original function. (defadvice foo (around foo-bar activate compile) "Always set ...
4
votes
1answer
94 views

Recover a built-in function that I accidentally unbound

I accidentally unbound a built-in function (a subr) from its usual symbol. Is there a generic way to recover it? Of course I could save my buffers and my session, exit Emacs and start another ...
7
votes
3answers
362 views

#'and is an invalid function?

I'm trying to see if all the values in a list are truthy. For some reason, (apply #'and lst) errors with: Invalid function: and This also happens when I try (cl-reduce #'and lst). However, (apply ...
0
votes
1answer
80 views

How call a function, when the user confirms the question?

I'm trying to write some Emacs Lisp. But I stumble on one thing. The code is structured as following: (defun foo () (interactive) (if (yes-or-no-p "Do you want to call the function bar?") ...
3
votes
3answers
148 views

Sort of autoreply for specific messages in minibuffer

Every time when I call M-x projectile-regenate-tags I get bothered with the message Tags file a:/foobar/TAGS has changed, read new contents? (y or n) which is quite cumbersome. Especially when I ...
1
vote
2answers
135 views

Getting latest command from function, but function exceeds “max-lisp-eval-depth”

This defines the Helm-source for Emacs commands history. (defvar helm-source-emacs-commands-history (helm-build-sync-source "Emacs commands history" :candidates (lambda () ...
1
vote
1answer
497 views

How call the eval-sexp function with the right argument?

When I change something in a function, I need to move to the last parenthese of a function, and do C-x C-e. I thought it would be nice if I can devise a keybinding to evaluate the function, while I'...
4
votes
3answers
190 views

What are the situations where defining a function as non-interactive is better than interactive?

Assume that we have a function which can be defined either interactive or non-interactive. When we define it as interactive, we can use it as a command by invoking M-x so we have more freedom. I am ...
7
votes
4answers
975 views

How to obtain a list of all functions exclusively provided by a certain major mode

This question in inspired by https://stackoverflow.com/q/605785/. By M-x describe-function <TAB> I can get a list of all interactive or nonintractive functions available in the current state of ...
4
votes
1answer
49 views

Priority of the executation of two functions with the same name from two different packages

General question: two packages have the same name for a certain function. When both packages are installed, which one has the priority to execute that particular function. Particular situation: I am ...
2
votes
1answer
983 views

Zip/Map functions ending when shortest list runs out

I wanted a function in the style of zip, but rather than stopping when one of the supplied lists runs out, I wanted it to continue using zip on the rest of the lists. Looking around at a few Emacs ...
6
votes
3answers
533 views

How to find out which function is bound to C-u C-SPC?

C-u C-SPC is used to Move point to where the mark was, and restore the mark from the ring of former marks. When trying to get the function bound to C-u C-SPC with describe-key it just stops ...
2
votes
2answers
123 views

How do I format dates without padding the values?

I was not very statisfied with the leading zero that I got in my insert-date function. It looks now as 09 jun 2015, instead 9 jun 2015. To solve this, I looked into the source code of s.el and ...
3
votes
2answers
363 views

How interpret the Lisp way to include arguments in functions?

I have some difficulties to understand how Lisp wanted to receive the arguments. When I look into the documentation about arguments in functions, I need to name the arguments exactly as in the source ...
3
votes
3answers
192 views

How to call another function, if one function gives an error message

Suppose I call a function which is named as foo. Sometimes that function foo will give a message such as "Example of error message". If that is the case, then something else should be executed. ...
4
votes
2answers
103 views

Understanding “It is bound to …” message in describe-function

If you ask for a function description, there is a line that starts: It is bound to <...> <...> <...> For example, for isearch it says: It is bound to <menu-bar> <search&...
2
votes
1answer
70 views

Where is this `make-magit-section` function defined?

I'm looking at the magit source code, and there's this make-magit-section function that doesn't seem to found anywhere in the project (grep doesn't return any results). describe-function says that ...
1
vote
0answers
133 views

My function seems to not know a variable has changed and gives the wrong output

I want to change the shebang string every time I create a new Python file, some projects use Python 2 and other use Python 3, so the shebang should change according to the value of a variable in the ....
5
votes
1answer
564 views

How kill all hidden (non-visible) buffers?

I looked around to be sure, that none had this issue earlier. Okay, sometimes I'm having too many buffers to manage. So I would like to kill all these buffers, except the buffers that are currently ...
10
votes
1answer
811 views

How to find out where a function is called from (backtrace/stacktrace)?

I've hit a problem that region is deactivated (in transient-mark-mode). The function deactivate-mark is called and I would like to find out where (and why) it is called from. I tried M-x debug-on-...
1
vote
1answer
240 views

Text is shown as bounding boxes when I switch to Arabic input method and use a certain font

I use this function in init.el file so that I can switch to Arabic language when writing code in Arabic and select an Arabic font for that: (defun arabic-input-font () "changes the set-input-method ...
22
votes
1answer
977 views

What is the difference between ' and #' in front of a symbol?

I'm a little new to Emacs. When looking at some of the configurations, I found there are two types command in "add-hook". (add-hook 'LaTeX-mode-hook #'LaTeX-math-mode) and (add-hook 'LaTeX-mode-...
2
votes
1answer
170 views

buffer-file-name is a function, so why doesn't M-x buffer-file-name work? [duplicate]

When trying to run it I get M-x buffer-file-name [No match] But it has a function help entry via C-h f and I can evaluate it with M-: buffer-file-name. So why isn't it accessible via M-x?
2
votes
3answers
118 views

How to convert this add-to-list call into a function

I have a bunch of add-to-list calls that I'd like to shorten in my .emacs file. They all look like this: (add-to-list 'align-rules-list '(haskell-comment (regexp . "\\(\...
5
votes
1answer
355 views

Does Emacs Lisp functions return objects by reference or by value?

I tried to determine if Emacs returned object by reference or value, but could not find a clear answer (searching google and Emacs Lisp manual). I guess it must be "by reference", and I just ...
12
votes
2answers
4k views

How do you return from a function at an arbitrary point?

How do you return early from a function before it's ended? For example: (defun my-func () "for example." (unless something (return nil)) ; continue as usual... (+ 42 1))
5
votes
1answer
234 views

How to map a function over several values?

I have a function foo-function that takes the variable x and performs a specific action. The variable x comes before the definition of foo-function: (defvar x "value1") (defun foo-function () (...
5
votes
2answers
1k views

Partial function application

apply-partially lets you create a new function by fixing the first n arguments of an existing function. Is there any way to achieve unrestricted partial function application, i.e., the ability to fix ...
21
votes
1answer
3k views

Curiosity: What does progn stands for?

According to Emacs documentation: progn is a special form in `C source code'. (progn BODY...) Eval BODY forms sequentially and return value of last one. What does progn stands for (or its origin)? ...
30
votes
4answers
3k views

When to sharp-quote a lambda expression?

Q: When, if ever, is it useful to sharp-quote a lambda, and when, if ever, must we not sharp-quote a lambda? People use lambdas in three ways: plain: (lambda (x) x) quoted: '(lambda (x) x) sharp-...
36
votes
1answer
2k views

What is the difference between a function and a command?

When posting questions and answers here, people sometimes use the terms "function" and "command" interchangeably. In other cases, people only use one of the two terms to discuss specific pieces of ...