Questions tagged [elisp-macro]

12 questions
3
votes
3 answers

Why does a macro inside a loop only expand once in Elisp?

Let's say I define (defmacro macro-print (str) (print "hello")) and run (let ((i 0)) (while (< i 3) (macro-print i) (setq i (+ 1 i)))) The output is "hello" nil why is this? I was expecting to see 3 hellos. This is because, according…
Isabella
  • 167
  • 3
3
votes
4 answers

Elisp use apply on progn for list of functions

I am a new emacs user. And trying to write some Elisp to learn this software better. While I meet some problems. I want to use apply on progn to run a list of functions in sequence. But I got errors as below. I am just confused and need some help to…
Xiong chenyu
  • 135
  • 1
  • 9
2
votes
1 answer

How does macroexpansion actually work in Lisp?

I would like a more detailed explanation of how macro expansion works, at least in Emacs Lisp but an overview of other Lisps would be appreciated. The way I usually see it explained is that the arguments of the macro are passed unevaluated to the…
Isabella
  • 167
  • 3
2
votes
2 answers

Elisp: defmacro with &body and &rest behave differently?

I thought &body and &rest were supposed to behave the same, so this puzzled me: ELISP> (defmacro mrest (&rest rest)) …
John Graham
  • 135
  • 6
2
votes
1 answer

How to give a list as arguments to a macro in elisp?

I want to achieve something like this: (setq my-global-keybindings '(([?\C-x ?\C-d] . dired) ([?\C-x ?\C-b] . ibuffer) ([?\C-x b] . ivy-switch-buffer))) (apply #'bind-keys* my-global-keybindings) But bind-keys* is a macro…
godblessfq
  • 218
  • 1
  • 10
1
vote
0 answers

Getting request-default-error-callback when attempting a post request with request.el in emacs lisp?

I am trying to use request.el to make a simple post request in elisp to my API, running on localhost. Here is the request in restclient.el format that I am trying to make in elisp using request.el: POST…
TheDarkHoarse
  • 416
  • 4
  • 9
1
vote
3 answers

Is defining unnamed macros possible? ("lambda" macros?)

My goal is to evaluate an expression at compile time, like some simple things as (+ 1 1). But, I would like an integer "2" to be compiled in, instead of a full "1+1" operation to be done at runtime, without using a named macro. This makes my source…
Luke Lee
  • 261
  • 3
  • 11
1
vote
2 answers

Emacs Lisp Macro Does Not Expand Alist

Here's my macro, what it is supposed to do is to wrap a body in let with bindings from vars-alist (defmacro with-vars-alist (vars-alist &rest body) `(let (,@(mapcar (lambda (cell) (list (car cell) (cdr cell))) vars-alist)) ,@body)) When I am…
EvgeniySharapov
  • 3,078
  • 3
  • 27
  • 38
0
votes
1 answer

Lisp - "list 'if x y nil" what is usage of the tick (') symbol and "list" function here?

I am taking a programming language principle class where the professor talks about macro using Lisp (Precisly, Elisp). However, he didn't teach us how to write this language. As a result, I am trying to learn myself. However, there are something…
Yan Zhuang
  • 436
  • 3
  • 10
0
votes
2 answers

How to prevent macroexpand-all to skip first form in list?

I am trying to expand all macros inside a nested list structure. macroexpand-all almost works, but skips (does not expand) the first form in every nested list. I am using this as a template-mechanism for org-agenda-custom-commands. I can generate…
bitclick
  • 1
  • 2
0
votes
1 answer

Nested macros for defalias don't work, but macroexpand output works? - Emacs Elisp

I'm trying to implement user command aliases with a customizable prefix for my package. I wrote two nested macros to accomplish this. The trs-defalias-from-suffix macro returns the correct value as if an alias was created, but none exists when I…
Cyberthal
  • 103
  • 3
0
votes
1 answer

How to use local variable in Elisp defmacro?

I write a elisp macro in my configuration file of emacs, but like something shown below ,(intern (format "%s-display-table" name)) is used several times, how can I use a something like variable to represent it? ;; Change the glyphs of "wrap",…
Johnson
  • 3
  • 1