Questions tagged [defun]
The defun tag has no usage guidance.
31
questions
1
vote
1
answer
26
views
How can I create an alias for a function name?
Does Elisp allow the equivalent of an alias for a function name?
0
votes
1
answer
20
views
How to access the last-yanked text programmatically?
How can I use the last thing yanked in a command I'm writing?
For example, if the last text I yanked was "test" I want to use this string somehow in my command.
(I use avy and evil.)
0
votes
1
answer
37
views
Use of cl-defun
What is a use case for cl-defun, where defun wouldn't work or would be hard to work with? I am using it to count the number of opening and closing bracemarks.
(cl-defun rk-bracemark-count-from-...
3
votes
2
answers
57
views
Create a function that returns a new function definition
I'm creating a modular system for my use of Emacs, so I can call modules on the fly, as I need them. Just like a lazy call, but I must explicitly call them.
Anyways, I found this riddle, I want a ...
1
vote
1
answer
88
views
How to pass a string argument to a function from global-set-key definition inside .emacs
Inside my .emacs file I have these two functions:
(defun bh/switch-to-vs ()
(interactive)
(universal-argument)
(shell "*vs*"))
(defun bh/switch-to-android ()
(interactive)
(...
0
votes
2
answers
250
views
copy string at point func
I'm trying to build a simple proc that copies the text on which the point is set and returns the point to where it was, but can't make it work properly.
Before you say "thing-at-point" - I ...
0
votes
1
answer
36
views
How can I save a function defintion
I want to extend a standard Emacs function (package--save-selected-packages), but to cover my tracks I want to save the old defintion under a new name and then redintion teh standard function.
I tried ...
3
votes
3
answers
180
views
How does scoping work in emacs lisp
A lot of emacs configurations shared publicly have this format:
;; 01-something.el
(provide 'something)
;; init.el
(require 'something)
Suppose I'm writing a defun named "s-join" inside 01-...
1
vote
0
answers
29
views
How to define interactive function that will not auto-complete?
If I do this:
(defun foo-bar-baz ()
(interactive)
(message "foo-bar-baz"))
And then M-x foo-baz RET (note no "bar") then completion matches foo-bar-baz and it executes.
Is ...
1
vote
0
answers
143
views
Defining a function that takes keyword arguments and a variable number of positional ones
I want to define a function that takes both keyword arguments (as in &key) and a variable number of positional ones (&rest). They should be independent of each other, the keyword list should ...
0
votes
1
answer
319
views
Identities between let/lambda/defun expressions and simplifying nested progn
I learned that a lambda and let works as if they already include a progn in their definition. That is (let ((x 1) (y 2) (z 3)) A B C) works as if it had a progn after binding the variables: (let ((x 1)...
0
votes
1
answer
1k
views
Symbol's value as variable is void [duplicate]
first, defined this interactive function:
(defun system-is-windows ()
(interactive)
(string-equal system-type "windows-nt"))
then call this function in one setting.el file
; don't show the ...
1
vote
1
answer
162
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
1
answer
57
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
1
answer
89
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 ...
5
votes
2
answers
942
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
1
answer
177
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 ...
4
votes
1
answer
219
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
1
answer
130
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
2
answers
113
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
2
answers
67
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
0
answers
775
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
1
answer
48
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
1
answer
192
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
2
answers
188
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
1
answer
174
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-...
16
votes
3
answers
625
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
1
answer
1k
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
1
answer
51
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
0
answers
225
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
0
answers
144
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 ...