Questions tagged [defun]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
45 views

Making a dynamic, interactive function

I have make a macro that creates dynamic functions: (defmacro tjb-make-register-macro (func-name out-string) (list 'defun func-name () '(interactive) (list 'insert out-string))) ;; This call ...
1
vote
1answer
21 views

How to write a command which uses the prefix argument AND some strings

I want to write a command which uses a prefix argument and reads some strings. I know both parts individually: (defun xtest(arg) (interactive "P") ... reads the prefix arg. (defun xtest(t1 ...
1
vote
1answer
36 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 ...
4
votes
2answers
171 views

defun in defun is not local?

I am reading SICP to learn Lisp, the book uses Scheme dialect. I want accommodate it to emacs lisp, I find something weird in 3.1.1 and cannot figure it out, say I have a test.el file: (defun make-...
0
votes
1answer
101 views

defun removes function in spacemacs config

I re-defined the function org-archive-subtree to call another function as described in the function below. I did this in spacemacs/user-config, now I can't call org-archive-subtree and C-h v (describe ...
1
vote
1answer
149 views

Make a variable visible to some functions only

Consider the following metacode: ;;; -*- lexical-binding: t -*- (defvar var1 ...) (defvar var2 ...) (defun main () "Main entry point" ...) (defun func1 ...) (defun func2 ...) ... (defun funcn ...)...
0
votes
1answer
53 views

Trying to copy everything between double quotes, and then make a list of everything that was copied

So I have a defun that I made that is supposed to copy every thing that is between double quotes and then make a list of everything that was copied. I don't know what the problem is, but it doesn't ...
0
votes
2answers
64 views

How to create a function which calls edit-indirect-region and then changes the mode in the buffer?

I'm beginner user of Emacs and I found trouble while trying to bind a custom function to a key. I successfully bind some keys to edit-indirect-region using following code: (global-set-key (kbd "C-c ...
3
votes
2answers
52 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
0answers
224 views

Interactive lambda functions [closed]

How do I create interactive lambda functions? (use-package general :ensure t :config (general-evil-setup t) ;;(setq general-default-keymaps 'evil-normal-state-map) (general-define-key :...
0
votes
1answer
36 views

How do I update this defun to select region

I wrote this function which takes a string and writes out self.var for each entry in the string. This helps me create python classes faster. (defun elf-python-self (str) "Parse the arguemnts in STR ...
1
vote
1answer
89 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 ...
0
votes
2answers
95 views

Play chess, login on a FICS server

I wish to play chess with chess.el on a FICS server using M-x chess-ics but using that logs me as a guest player. How can I login with my registered user/password? EDIT I've come with a way to login....
0
votes
1answer
64 views

Adding to kill-buffer-hook results in “setq: Wrong type argument”

Subtract a buffer's (the file's) size from a variable before killing it. Emacs 26. (defvar cumulative-open-bytes '0 ) (defun buffer-settings-calc-bytes () (interactive) (let ((current-open-file-...
13
votes
3answers
248 views

Defun inside let with lexical binding gives byte-compile warning “the function is not known to be defined”

I want to get the effect of a static variable by using defun inside of let with lexical binding to create a closure. However, when byte-compiling the file, I get a warning. Am I doing something wrong, ...
6
votes
1answer
892 views

How to make local function binding for closure?

For example, when defining the natural number sequence stream, I can use ;; -*- lexical-binding: t; -*- (defun nats (n) (cons n (lambda () (nats (1+ n))))) (nats 0) => (0 closure ((n . 0) ...
0
votes
1answer
27 views

eval-last-sexp produces unnecessary void-variable error when using a macro containing eval

Suppose I have defined the following macro: (defmacro mymacro (a) "" (eval a)) If I then use eval-last-sexp (i.e. C-x C-e) to evaluate the following, (defun somefcn (b) "" (mymacro b)) I get the ...
1
vote
0answers
113 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. ...
2
votes
0answers
92 views

Optional docstring in defun

After taking a look at the definition of defun in byte-run.el, it seems that the macro does some very interesting things regarding checking for the existence of a docstring. First, it uses a declare ...