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
2
votes
1answer
37 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
6 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 ...
0
votes
1answer
35 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-...
1
vote
1answer
24 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-...
2
votes
7answers
690 views

How to get the function help without typing?

I'm already used to press C-h f and type a function name to ask for help on that function. But if the function name is already under the cursor (e.g. while visiting the .emacs configuration file), is ...
1
vote
2answers
40 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
27 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
51 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
2answers
37 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 ...
2
votes
3answers
484 views

Org-mode link to function definition

Is it possible to link to a function definition in a source code file, rather than a fixed line number?
0
votes
0answers
12 views

Choose to use a function between emacs packages or libs

Suposse that I want to use the function dolist from package cl (I know that is obsolete and als have cl-lib package). but when I'm looking for documentation (C-h f dolist) I get the following: ...
3
votes
3answers
278 views

Trace calls to a function with the parameters

I need to track the calls to org-tags-view to discover the params passed to it. I tried an advice: (defun his-tracing-function (orig-fun &rest args) (message "org-tags-view called with args %S" ...
1
vote
1answer
64 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
12 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
46 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
140 views

Custom search function for dictionary lookup

I have a plain text dictionary in which each headword is matched by ^# \(† \)?headword, How can I make a custom search function that relieves me of typing the whole regex every time I want to look ...
0
votes
1answer
44 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
29 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). ...
2
votes
3answers
292 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
40 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)
9
votes
2answers
471 views

When should sharp quotes be used?

I see sharp quotes being used in other people's eLisp code, and I use them myself, but I'm not completely clear on when they are appropriate and when not. Could anyone clarify on exactly when it's ...
4
votes
3answers
286 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
2answers
101 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 ...
0
votes
1answer
122 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 ...
2
votes
1answer
56 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
51 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
43 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 ...
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-...
5
votes
1answer
601 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
2answers
145 views

Why use `defsubst` in `man.el`?

I recently noticed an issue in man.el, in which sections in Man--sections are listed backwards. That is, the value is is something like: (#("SEE ALSO" 0 8 (face Man-overstrike)) #("COPYRIGHT" 0 9 ...
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&...
7
votes
2answers
764 views

How to delete a function?

For what I do I tend to define a lot of functions that I use temporarily. Life span is usually about 1-2 weeks - and then I define a new set of functions. I was not able to find where these ...
4
votes
2answers
363 views

defun in defun is not local?

I am reading SICP to learn Lisp, the book uses Scheme dialect. I want accommodate it to emacs lisp, I find something weird in 3.1.1 and cannot figure it out, say I have a test.el file: (defun make-...
1
vote
1answer
67 views

Problem with file-exists-p function on Linux running as VirtualBox guest

Until this morning, my emacs setup (running on Arch Linux as a VirtualBox guest) was working absolutely fine. Then for no obvious reason I started experiencing the following issue: If I opened an ...
0
votes
1answer
43 views

How can I get git-gutter:next-hunk to NOT loop around at buffer bottom?

As per the title, I would like to stop processing at the end of a buffer and not loop around to the top. I find it easier to keep track of what I am doing that way. TIA.
12
votes
1answer
1k views

Why can't I bind my function to a key or call it with M-x?

I wrote a function, and I want to call it via M-x, and bind it to a key. This is my function: (defun my-function () (message "This is a great function")) If I try to call it with M-x my-function,...
0
votes
1answer
41 views

Apply of a logic function over a list

I'm trying to apply a logic function over a list, but: e.g.(apply 'and some_list) give me Invalid function: and. There is a way to apply a logical function to a list?
2
votes
2answers
104 views

Does `car` on an non-lazy function generated list evals the whole list?

I want to get in a huge directory the first file which satisfies some condition, something like (require 'seq) (require 'f) (defun lazy-filter-file (pred path) (car (seq-filter pred (f--files path ...
2
votes
2answers
122 views

Elisp - Activate and Deactivate Linum-Mode when Goto-Line is Triggered

I switched to Emacs from Vim and because of Vims functionality of giving keys a prefix, (for example to jump up several lines etc.) i installed relative-linum-mode right away. Now i found out about ...
3
votes
1answer
506 views

Define a function alias within a let binding?

How can I define an alias within a script with let-binding? I tried (let (b-s) (defalias 'b-s 'buffer-string)) But it doesn't work. I figured out to let-bind the variable where aliases as stored ...
0
votes
2answers
381 views

how to correctly pass around function as parameters?

I have a working snippet that advices both kill-buffer and kill-this-buffer to not kill the scratch buffer: (defun ninrod/scratch-bodyguard (buffer-assassin &rest arguments) (let ((buffer-...
1
vote
1answer
30 views

Calling locally defined function via function parameter

Interface, by example: (my-run-command '(my-append (3 6 8) (4 5))) Desired output: (3 6 8 4 5) Implementation, with bits missing: (defun my-run-command (command) (let ((my-append 'append)) [...
0
votes
1answer
65 views

use a function to get file in compilation-error-regexp-alist

I have used compilation-error-regexp-alist a lot so I am familiar with the syntax. However for this particular error I need to use a function to get the file because I need wildcards. Here is the ...
3
votes
1answer
71 views

How to get Emacs to know that a symbol has a function definition

While reading the source file prelude-ivy.el in the Prelude modules directory, I saw that there was a warning associated with "here" in the last line, specifically that prelude-required-packages was ...
3
votes
1answer
246 views

Hook with quoted lambda as an argument

I been reading a blog post from Chris Wanstrath from 2010 where he write about coffee-mode. He proposed there this functions hook: (defun coffee-custom () "coffee-mode-hook" ;; Emacs key binding ...
1
vote
1answer
116 views

Call emacs function from terminal and obtain the same behaviour

I have this simple function that opens an external shell (st) in the same directory of the current buffer: (defun external-shell-in-dir () (interactive) (start-process "st" nil "st")) However, ...
1
vote
2answers
64 views

`ibuffer-switch-to-saved-filter-groups' is not known to be defined

I have this line in my .emacs file. (add-hook 'ibuffer-mode-hook #'(lambda () (ibuffer-switch-to-saved-filter-groups "default"))) The settings work fine for me. But flycheck ...
1
vote
1answer
265 views

How to run an executable from within emacs on windows

I have a program, say myprogram.exe, and I want to run it from within Emacs by using a key binding. I can run the program in the shell, but don't know how to write a function that calls this function ...
2
votes
1answer
81 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 ...
1
vote
0answers
63 views

What is confusing about upcase-region?

Using upcase-region gives the message about it being disabled because new users find it confusing; but it seems very straightforward—replace every character with its upper-case version, if there is ...