Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
20 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
34 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
537 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
34 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
98 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
59 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
27 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
25 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
53 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
136 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
52 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
32 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
36 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
45 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 ...
0
votes
1answer
56 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
115 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-...
3
votes
2answers
76 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
45 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?
4
votes
2answers
50 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
152 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" (...
4
votes
2answers
102 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
63 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
23 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
51 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
0answers
56 views

Calling Applescript from Emacs

In my Org workflow, I am trying to use the do-applescript function to hide an active Emacs session. Can you tell me what I am doing wrong with the following that I think should work but is not? ...
3
votes
1answer
48 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
68 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
41 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
196 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 ...
7
votes
2answers
293 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
98 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
338 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
67 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
97 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
79 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
66 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
35 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
40 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
255 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
51 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
2answers
272 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?
6
votes
1answer
927 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-...
6
votes
1answer
259 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 ...
4
votes
0answers
77 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 ...
6
votes
2answers
774 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
71 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 ...
4
votes
2answers
64 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
252 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
48 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?
5
votes
2answers
62 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 ...