help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: global-set-key with function taking arguments


From: William Xu
Subject: Re: global-set-key with function taking arguments
Date: Sun, 01 Nov 2020 11:57:40 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin)

jai-bholeki via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> This is the way I set a keybinding
> (global-set-key (kbd "C-H-<down>") 'transpose-paragraphs)
>
> To set a keybinding with a function taking parameters, I use
> (global-set-key (kbd "C-H-<up>")
> ( lambda () (interactive) (transpose-paragraphs -1) )
> )
>
> However, may one write
> (global-set-key (kbd "C-H-<up>") '(transpose-paragraphs -1) )

You could define a macro wraper around: 

#+begin_src emacs-lisp
(defmacro my-make-interactive (&rest body)
  `(lambda ()
     (interactive)
     (progn ,@body)))

(global-set-key (kbd "C-H-<up>") (my-make-interactive (transpose-paragraphs 
-1)))
#+end_src

-- 
William




reply via email to

[Prev in Thread] Current Thread [Next in Thread]