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
3answers
634 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?
3
votes
2answers
53 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 ...
3
votes
1answer
628 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 ...
3
votes
1answer
64 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
77 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
358 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
88 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
407 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
114 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
179 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
382 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
114 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
87 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
2answers
140 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
1answer
327 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
53 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)) ;;...
3
votes
1answer
119 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
1answer
193 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
73 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
100 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
7answers
905 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 ...
2
votes
3answers
707 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
178 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
107 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
70 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
233 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
151 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
122 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
2answers
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
1k 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
104 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 ...
2
votes
1answer
59 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
83 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-...
2
votes
1answer
255 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
1answer
744 views

Pass function symbol as argument via function or single quote?

Are 'function-name and (function function-name) completely equivalent, or are there conditions under which I must use the more verbose (function function-name)? (apply 'message ( list "call func via ...
2
votes
2answers
187 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
240 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
73 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
375 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
1answer
35 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 ...
2
votes
2answers
152 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
96 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
69 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
154 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
1answer
96 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
323 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
0answers
190 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
3answers
157 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
176 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
511 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 ...