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

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

Re: Adding String to Beginning of Lines


From: Michael Heerdegen
Subject: Re: Adding String to Beginning of Lines
Date: Tue, 10 Nov 2020 19:03:49 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Christopher Dimech <dimech@gmx.com> writes:

> Have tried to add a keybinding for the function, but after pressing
> the keyseq, I am getting "H-z is undefined".
>
> (define-key emacs-lisp-mode-hook (kbd "H-z") 'rec-field-nwltok)

Yeah, because it's, ehm, nonsense.

You want to bind your key in a keymap, and do that in the hook, e.g.

(add-hook 'emacs-lisp-mode-hook
          (defun my-emacs-lisp-mode-hook-fun ()
            (define-key emacs-lisp-mode-map (kbd "H-z") #'rec-field-nwltok)))

Hooks contain functions.  I use to use named functions because lambdas
cannot be identified should you reload your piece of code and thus get
added multiple times.  If you don't care (i.e. if you know for sure you
don't reload your init file) a lambda also works.


Regards,

Michael.




reply via email to

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