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
1
vote
1answer
99 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
240 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
472 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
497 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
77 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
167 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
104 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?
2
votes
2answers
89 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 ...
0
votes
1answer
39 views

Why doesn't generate-new-buffer work in M-x?

According to the documentation generate-new-buffer "buffername" creates a new empty buffer with the given name, yet when I try it in M-x the prompt refuses the name and replaces it with "No match". ...
1
vote
1answer
62 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 ...
3
votes
1answer
508 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 ...
1
vote
1answer
85 views

How to print a quoted sexp using '… (reader syntax) instead of using (quote …)?

The result of (print 'foo) is (quote foo). Is there a similar function whose result is 'foo, which is what people generally write?
2
votes
3answers
486 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?
5
votes
1answer
2k views

Insert line above/below

I have a couple of functions for inserting blank lines above and below the current line: (defun insert-line-below () (interactive) (move-end-of-line nil) (open-line 1)) (defun insert-line-...
7
votes
1answer
411 views

What does `(fset SYMBOL KEYMAP)` do?

I was reading through the projectile source file and they do the following: (defvar projectile-command-map (let ((map (make-sparse-keymap))) ; define-keys map) "Keymap for Projectile ...
3
votes
0answers
93 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 ...
5
votes
2answers
1k views

How do I invoke a non-interactive lisp function interactively?

This is dim, but I've forgotten how to do this, and I can't work it out, sorry: I'm in python mode with elpy, and I want to run the function python-nav-beginning-of-defun in a python buffer, to see ...
0
votes
1answer
94 views

function that takes a function as argument and returns a new function

I'd like to write an elisp-function that has a function as argument and returns a new function. Let's say the new function double-the-function should write the returned value of the argument-function ...
3
votes
2answers
79 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 ...
1
vote
2answers
416 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 ...
0
votes
2answers
55 views

Changing default output of a function

When I run (+ 1 1) using eval-print-last-sexp in a buffer, this function inserts a newline and outputs 2. I'd rather its output were just ' 2' (space and 2). How can I change this?
4
votes
2answers
72 views

How can I record where a function is defined if it's done indirectly?

I've got a few functions in api-wrap.el that I'll refer to as 'macro code', here simplified to clarify the question: function (generate-form prefix kind &rest args) returns an unevaluated form ...
0
votes
1answer
78 views

My emacs doesn't contain a function in the online emacs manual

Command comment-line is not recognized by my version of emacs. How can I install this function? UPDATE: It may be relevant that my system shows at least two emacs, at /usr/local/bin/emacs; and at /...
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/...
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-...
5
votes
1answer
279 views

Emacs pdf-tools writing function

Recently I am indulging in Emacs. I tried to use it as my LaTeX tool, so I installed pdf-tools. If I add (pdf-tools-install) in my init file, it will take about 2 seconds to start Emacs. So I want ...
1
vote
1answer
504 views

auto kill a shell buffer when command finishes

i have this function you guys helped me write (defun z/dired-shell-other-window-beets () (interactive) (let ((command (concat "beet import " (format "%S" (dired-get-filename))))) (switch-...
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-...
3
votes
1answer
206 views

How to invoke functions that are quoted in let?

I'm trying to do some processing of values passed in a plist. Processing is quite similar: get a value, convert it to number if necessary, check if within bounds and if yes, return a string with that ...
0
votes
1answer
187 views

Create a sub-mode of an existing mode which overrides certain functions?

I want to make a few customizations to cmake-model.el. The big-picture view of this lisp file is as follows: ... ;; This function I want to modify (defun cmake-indent () ... ) ... ;; Mode ...
6
votes
1answer
419 views

How to make interactive functions (simply) undoable?

This question refers exclusively to interactive functions that modify the contents of the current buffer. What does one need to do to ensure that a single execution of (undo), right after running the ...
2
votes
3answers
197 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 ...
0
votes
1answer
359 views

*** Eval error *** Invalid function:

Step 1 make-toggle-func returns a anonymous function ... (defun make-toggle-func (book-name repl-name code-file) `(function (lambda (x) (interactive) (setq book-name ,book-...
0
votes
3answers
164 views

run emacs function in the shell with parameter

Since there is parameter I need to use, so I will not use single quote as the question's answer First, I try emacsclient -q --eval (progn (find-file "ORG/${UN}.org") (org-latex-export-to-pdf)) ...
0
votes
1answer
141 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 ...
2
votes
1answer
271 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: ...
3
votes
1answer
327 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 ...
2
votes
1answer
60 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 ...
1
vote
1answer
581 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
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 ...
3
votes
3answers
279 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" ...
2
votes
2answers
135 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 ...
1
vote
0answers
62 views

How to trigger function on particularly named buffer creation?

How does one trigger a function to run when a buffer of a particular name is created? My use case is connecting to freenode with ERC for Emacs related channels. I manually call a function to create a ...
0
votes
1answer
52 views

If a function is passed as an argument to another function, is the first function's name accessible?

I have some code that takes as an argument a function: (defun message-name (fn) ) I would like to be able to, if the function has a name, message it. For example, if called this way: (message-...
0
votes
1answer
806 views

Symbol's function definition is void on built-in variables?

For some reason I am getting errors for built-in variables that are available in the documentation. For instance, evaluating in the scratch buffer the following all return: Symbol's function ...
5
votes
2answers
196 views

Finding the source of a function after macro expansion?

(I'm a rookie and I use Spacemacs) I'm trying to find the source of a certain function*. I can find the .el file in which it's defined by using find-function, however the defun is created ...
0
votes
1answer
49 views

Reacting to custom key press

My goal was to improve the php mode. Very often I have to define an array element. And the possible code is this: $array['key'] $array[$key] So, I wanted to create Emacs function, reacting upon ...
1
vote
1answer
74 views

help with writing a dired function to convert md to org with pandoc CLI..started but stuck

im trying to write a function that will be used in dired where i would launch it on the file at point and it will convert it using pandoc. i have the following code chunk (warning: my coding skills ...
3
votes
1answer
180 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 ...