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
3
votes
1answer
42 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 ...
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
220 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 ...
3
votes
2answers
78 views

Can I define a function/macro in emacs named .?

I would like to define this function: (defun . (object method &rest args) (apply (plist-get object method) args)) But, not surprisingly I get: if: Dot in wrong context Not surprising because ...
3
votes
3answers
257 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" ...
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 ...
3
votes
1answer
131 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 ...
3
votes
1answer
305 views

Defining a generic function and implementing specialised methods

Emacs provides support for polymorphism, supporting "generic functions", like in CLOS. According to Emacs manual: A generic function specifies an abstract operation, by defining its name and list ...
3
votes
1answer
72 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: ...
3
votes
1answer
281 views

function calls from command line, using emacsclient

I used to read my emails from command line with emacs -f gnus. To read my emails using emacsclient, I'm doing emacsclient -c --eval '(gnus)'. Just want to know, is there a simpler alternative to that? ...
3
votes
1answer
179 views

Elisp nested function stops execution

I can not figure out why does when I factored out function it started to work wrong. Here's the my function to kill all dired buffers, its bound to dired-mode-map that work as expected and ...
3
votes
1answer
61 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 ...
3
votes
0answers
91 views

copy to clipboard without overwriting kill ring

I'm looking for a way to copy to clipboard from emacs without passing through the kill-ring, moving the marker or using the mouse. If I use x-select-enable-primary and x-select-enable-clipboard, I can ...
2
votes
3answers
225 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)...
2
votes
1answer
160 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
2answers
102 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
3answers
450 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?
2
votes
2answers
68 views

simple function in dired to create a dir with current date?

so im trying to create a simple script to create a directory in dired with a pre defined string (the current date). i have another script that inputs the current date in a format i want (defun z-...
2
votes
3answers
189 views

Bringing a function into a lexical environment

I'm using a closure to keep track of some stuff to do with state; I want to be able to ‘include’ a function into that closure, so it can access the state. The only way this is possible is by creating ...
2
votes
2answers
132 views

Can I pass an arbitrary symbol/keyword as a non-nil argument?

If a function takes a parameter whose only significance is in whether it's nil or non-nil, is there any reason not to pass it a well-named symbol to clarify what's going on in the calling code? For ...
2
votes
3answers
113 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 . "\\(\...
2
votes
1answer
962 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 ...
2
votes
1answer
55 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 ...
2
votes
1answer
1k views

Symbol's function definition is void: insert-string

;; Specify the startup banner. Default value is `official', it displays ;; the official spacemacs logo. An integer value is the index of text ;; banner, `random' chooses a random text banner in `core/...
2
votes
1answer
212 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" (...
2
votes
2answers
139 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 ...
2
votes
2answers
223 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 ...
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 ...
2
votes
1answer
344 views

Monkey patching a function

Some context: I'm doing some linux kernel development on a Debian VM so naturally I'm using tramp. I want to use semantic-symref, but the trouble is that: Semantic will eventually call cedet-gnu-...
2
votes
2answers
110 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 ...
2
votes
2answers
86 views

Monkey patch and restore builtin set-window-dedicated-p during advice

I would like to make set-window-dedicated-p a NOP when called from xref--show-pos-in-buf. Below is an attempt to do so using advice. It doesn't work, I think because fset is not really copying the ...
2
votes
1answer
58 views

Writing bytes to a file using library f.el [duplicate]

I'm trying to do something very simple, write bytes to a file using the f library: (require 'f) And I create a list of bytes: (setq random-data (loop for i from 0 to 40 collect (random 150))) So ...
2
votes
1answer
103 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?
2
votes
1answer
69 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 ...
2
votes
2answers
116 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 ...
2
votes
1answer
86 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 ...
2
votes
1answer
261 views

(key-binding (this-command-keys)) not translating keybindings

I have put the following code (partially adapted from a company-mode issue and a Stack Exchange question) in my init.el in order to adjust the keybindings active in the company-mode completions menu: ...
2
votes
1answer
480 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'...
2
votes
0answers
185 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 ...
1
vote
6answers
654 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
3answers
147 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 ...
1
vote
2answers
90 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 ...
1
vote
2answers
382 views

using functions with mandatory and optional arguments

I am trying to understand, what some functions are doing, in order to code something similar. The following example was copied from the file acro.el from the AUCTeX package. This is just a random ...
1
vote
2answers
243 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
234 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 ...
1
vote
1answer
98 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?
1
vote
1answer
30 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) ...
1
vote
1answer
38 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 ...
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)) [...
1
vote
1answer
56 views

practical relevance of storing value and function into one symbol

With Emacs Lisp it is possible to store a value and a function within the same symbol. (setq foo 6) (defun foo () (message "blah %d" foo))) Then you can do: (symbol-function 'foo) which returns the ...