[Top][All Lists]

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

Re: Toggle WikiLink on and off does not work?

From: Emanuel Berg
Subject: Re: Toggle WikiLink on and off does not work?
Date: Thu, 17 Aug 2017 13:42:35 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Csányi Pál wrote:

> (define-key emacs-wiki-unlink-toggle "\C-\M-n")
> When I load the .emacs file with 'M-x
> load-file' command, I get message: Wrong number
> of arguments: define-key, 2

Here you use `C-h f define-key RET' to bring up
the help, where you see that the interface to
`define-key' is

    (define-key KEYMAP KEY DEF)

So it should be

    (define-key emacs-wiki-mode-map "\C-c\C-n" #'emacs-wiki-unlink-toggle)

The reason you do `require' before this is that
otherwise, there isn't any
`emacs-wiki-mode-map' to set!

> A want to add to this question more. Actually,
> with the previous setup the C-c C-n keybinding
> works

OK, yes, I admit I only got confused by that
hook solution with local-set-key. There are
many ways to set keys and naturally I'm the
most into my own ways. So if it works it works.

The reason hooks are considered less reliable
and are a tiny bit slower is that they execute
every time. So the functions there execute over
and over. It shouldn't really influence
the speed. Perhaps the interactive feel, if
your "feelings" are really fine turned.

However with require + define you do it once
and that's it. It is always what I try first
and most time it works. Sometimes it doesn't
work tho and without having digged into that
I guess when some subsection of a software
component is brought to life, it resets keys
that should have been left alone. Whenever that
happens, I still use define, I just enclose it
in a function and have that called from the
hook function. As in:

;; (setq erc-mode-hook nil)
(defun erc-mode-hook-f ()
  ; [...] some unrelated stuff cut for clarity
  (set-erc-keys) ; why needed?
(add-hook 'erc-mode-hook #'erc-mode-hook-f)

;; keys - why is a call needed in the hook as well?
(defun set-erc-keys ()
  (let ((the-map erc-mode-map))
    (define-key the-map "\C-\M-p" #'erc-previous-command)
    (define-key the-map "\C-\M-n" #'erc-next-buffer)
    ; [...]
(set-erc-keys) ; not enough, apparently

> So If I understand right, if one untoggle the
> Wiki Link, then the link should disappeared,
> and WikiLink should not be underlined. And vica
> versa. Right?

I don't know because I just skimmed thru the
defun looking for simple style things to
spot/correct, I didn't think about what it was
supposed to do. I don't use wikis myself.
But if the key is up and running, debugging
will be much faster :) So what should the
function do, that it doesn't, or, what does it
do, that it shouldn't?

underground experts united

reply via email to

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