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
2answers
271 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
271 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
2answers
41 views

Why does `narrow-to-region` complain that its args are not `integer-or-marker-p`?

I have some functions that depend on smart-parens code. (defun outer-paren () "Move point to the outermost parenthesis." (interactive) (ignore-errors (while t (up-list))) (sp-...
1
vote
1answer
121 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
81 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 ...
1
vote
1answer
32 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
36 views

general function to concat token at point with function and send to *R*

I'm moving my R setup over to emacs and ess -- and am struggling with the emacs / LISP customisation process. In an answer to another question, I learnt how to create a function that concats a ...
1
vote
1answer
20 views

Wrong type argument: symbolp, 10

I would like create function that ask me how length I want the Pomodoro but it say wrong type argument. (defun changePomoLength () (interactive) (set-variable org-pomodoro-length (read-string "...
1
vote
1answer
69 views

built-in function to return the argument itself

The line below shows the first element which is not nil. (message "%s" (cl-some #'(lambda (x) x) '(nil nil "hello" nil))) ;; Output: hello Is there a built-in function which is equivalent to (...
1
vote
1answer
252 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
1answer
47 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
33 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
102 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?
1
vote
1answer
128 views

Symbol’s function definition is void

I am trying to make an interactive toggle in emacs 27.0.90 When I eval-region no warnings or errors are shown. However, when I do (helm/toggle-frame) in ielm it throws Symbol’s function definition is ...
1
vote
1answer
64 views

How to call a function that is the value of a variable?

Can someone explain to me why the code below throws an error (void-function fn)? (let ((lexical-binding t) (fn (lambda (y) (+ y 4))) (x 4)) (pcase x (10 (- x 2)) (4 (fn x)))) ...
1
vote
1answer
31 views

Evaluate allows for combinations whose operators are compound expressions

I find the amazing power of scheme in sicp Exercise 1.4. Observe that our model of evaluation allows for combinations whose operators are compound expressions. Use this observation to describe ...
1
vote
1answer
37 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-...
1
vote
1answer
133 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 ...
1
vote
2answers
51 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)
1
vote
1answer
478 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
1answer
173 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 | |----+---+---+--...
1
vote
2answers
64 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?
1
vote
2answers
143 views

Getting latest command from function, but function exceeds “max-lisp-eval-depth”

This defines the Helm-source for Emacs commands history. (defvar helm-source-emacs-commands-history (helm-build-sync-source "Emacs commands history" :candidates (lambda () ...
1
vote
1answer
603 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'...
1
vote
1answer
76 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 ...
1
vote
1answer
138 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
1answer
118 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 ...
1
vote
1answer
610 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-...
1
vote
1answer
83 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 ...
1
vote
1answer
54 views

Expression as var

Is it possible for a variable to be set to an expression that will be evaluated each time that variable is accessed? The idea would be that a user could then set the variable to be either a string or ...
1
vote
1answer
331 views

How to break out of function indirection loop

I have a problem that I suspect is a general Emacs problem. If I run a certain package, simple-rtm, and then try and use M-x to run any command, I get the error in the bottom line of the screen: ...
1
vote
1answer
80 views

How to create named functions for dynamic key bindings?

I am creating a keymap based on a configuration file. The resulting keys all call the same function but with different arguments. Here is the code I am using for a single key: (defun add-do-my-stuff-...
1
vote
0answers
42 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). ...
1
vote
2answers
92 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
0answers
83 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
32 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-...
1
vote
0answers
66 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 ...
1
vote
0answers
163 views

Sublime Text like Ctrl-Delete/Backspace

Is there any easy way (or maybe a package) which provides Ctrl-Del/Backspace behavior like in Sublime? The default rule of sublime is delete-to-next-word-boundary. I did not find similar options. ...
1
vote
0answers
138 views

My function seems to not know a variable has changed and gives the wrong output

I want to change the shebang string every time I create a new Python file, some projects use Python 2 and other use Python 3, so the shebang should change according to the value of a variable in the ....
1
vote
2answers
54 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
3answers
71 views

Default argument when nil is provided

I'm writing a function which wraps org-export-as for use in html conversion of a file. In this function, I define the options for org-export-with-toc, org-export-with-section-numbers, and org-html-...
0
votes
2answers
409 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-...
0
votes
2answers
86 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 ...
0
votes
3answers
42 views

How to find information about a function?

To be able to learn about functions on my own I would like to know where I can find information about them (within emacs or otherwise).
0
votes
1answer
30 views

Convert function-quoted form #'… to string

I have tried (symbol-name x), but it doesn't work if the argument is a lambda: ok: #'execute-extended-command not ok: #'(lambda (&optional frame) (interactive) (message "hi 8"))
0
votes
2answers
38 views

How do I define a function to execute as a command with M-x? [duplicate]

I wish to M-x my-func and let my code run. This seems basic but where can I get more documentation about this, if possible inside emacs itself?
0
votes
1answer
47 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?
0
votes
1answer
137 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 #{ <...
0
votes
2answers
252 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 ...
0
votes
1answer
48 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". ...