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
0answers
10 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: ...
1
vote
1answer
58 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
10 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
41 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
39 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
20 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
201 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
37 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
274 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, ...
0
votes
1answer
76 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
83 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
54 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
49 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
36 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 ...
7
votes
2answers
719 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
185 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-...
0
votes
1answer
38 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.
1
vote
1answer
56 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 ...
12
votes
1answer
877 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
38 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
101 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
107 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 ...
1
vote
1answer
29 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
57 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
69 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
211 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
105 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
54 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 ...
0
votes
1answer
185 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 ...
1
vote
0answers
58 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 ...
1
vote
1answer
108 views

Deleting duplicates in an org-table column

I wanted to preserve the first row value while deleting all subsequent repeated values in the sequence column ($5) as in the MWE below: | ID | M | D | P | sequence | item | |----+---+---+--...
0
votes
1answer
214 views

evil quit-window and evil-record-macro integration

I am trying to replicate emacs standard behavior when it comes to 'q', i.e. when in a buffer where insert mode does not make sense 'q' closes it. So I defined the following function (defun evil-new-...
4
votes
2answers
105 views

How to sort bash functions alphabetically?

My boss is a bit of a neat freak. He wants the functions in my functions.sh be ordered alphabetically. foo() { echo foo } baa() { echo baa } So baa should appear first in the file. Can emacs ...
1
vote
1answer
102 views

is there a function that can partially apply arguments on a function with order?

apply-partially cannot specify the order. Is there one from the default emacs installation that can specify order?
3
votes
2answers
52 views

How to define a bundle of variable-and-function pairs?

I want to define a bundle of variable-and-function pairs, e.g.: vl/path-doc points to my often used path, and vl/open-path-doc is used for open it in dired-mode. I tried this piece of code: (setq ...
2
votes
1answer
211 views

Key binding to a sequence of commands

I'm trying to define a key binding that executes a sequence of commands. I add this code to my ~/.emacs file (require 'origami) (defun open-close-node () "Open/Close node origami mode" (...
3
votes
2answers
127 views

elisp search functions

I'm trying to debug a piece of elisp that is in an orgmode template I'd like to use. (link here) The problem is occurring in the source block that is supposed define the cite links. (org-add-link-...
0
votes
0answers
125 views

Custom functions in emacs?

I'm finding I run C-x C-f and then: /ssh:$user@$host|sudo:$host:/ Where $host is a device IP. I'm relatively new to emacs, I want to create a custom function that accepts values for $host and $user....
1
vote
1answer
30 views

Read-string does not always return a value

I have written a small function to search MDN docs and display them on the browser. However, sometimes the function does not work and an empty query is made. My code is as follows: (defun search-...
0
votes
1answer
86 views

Using result of an Elisp function as input to replace-regexp in interactive mode

I am using replace-regexp interactively. Can I programmatically refer to a match or otherwise interpolate values in the replacement string? In Ruby, for example, it is easily done, by using the #{ <...
3
votes
1answer
60 views

Should the sharp quote should be used for the first argument of advice-add?

... when a symbol referencing a function is actually used? Documentation states: Like ‘add-function’ but for the function named SYMBOL. Contrary to ‘add-function’, this will properly handle the ...
2
votes
1answer
84 views

keybinding to switch to specific application

I'm running Emacs in a GUI, and I like having a keybinding that quickly switches me to a terminal. Yes, I know there's eshell, term, and shell in Emacs, but I still prefer a dedicated terminal ...
1
vote
1answer
93 views

How to evaluate a defun with square brackets in column 0 of its docstring?

I have problems running eval-defun for a defun when there is a square bracket [ in column 0 of its doc string. For example: (defun test () "Test function. [Some text]" (message "Hello")) When I ...
5
votes
2answers
230 views

Keybinding for buffer word count

The following in my .emacs file does not produced the desired result of showing me the word count for the current buffer (it "does nothing"): (global-set-key (kbd "<f9>") (kbd "C-u M-=")) Is ...
9
votes
2answers
413 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 ...
3
votes
2answers
111 views

Function for compressing a number range

I'm working with TeX-Files which are converted from other formats. One thing that pops up in these are vertical lines in tables like the following: \cline{1-1}\cline{2-2}...\cline{n-n} This can be ...
4
votes
2answers
467 views

Moving cursor to the middle of the line where it currently is

Is there a way to define a function that, when called, would move the cursor to the middle (or close to the middle) of the current line, similarly to how we can move it to the beginning and end of the ...
-1
votes
1answer
76 views

Emacs Lisp Error when called as command but works well when called as function

https://github.com/Cheatinikle/Spacemacs-settings/blob/master/emacs-package/preetest-mode.el This is my full source code, and 'just-utils package is also included in the repository. The problem is, ...
0
votes
2answers
141 views

Automatically break long function signatures, calls, etc

void parse(std::vector<float>& io_vertices, std::vector<unsigned>& io_indices) {} Oftentimes when we code we need to break lines repeatedly as new expressions and statements enter ...
1
vote
1answer
96 views

How to find out which package a command belongs to

I have found a command M-x project-find-regexp, how can I find out from where it comes from, ELPA/Melpa package or part of GNU/Emacs?