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

[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: Wed, 16 Aug 2017 16:50:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Csányi Pál wrote:

> ;; Toggle WikiLink on and off
> (defun emacs-wiki-unlink-toggle ()
>       "Toggle <nop> string in the beginning of the current word, to un/make a
>     word emacs-wiki link. The current word depends on the point: if the cursor
>     is on a non-whitespace character, it's considered a word surrounded by
>     whitespace. If the cursor is on a whitespace character, the next word is
>     looked up. This way addressing a word works intuitively after having
>     arrived on the spot using forward-word."
>       (interactive)
>       (save-excursion
>     (if (looking-at "[[:space:]]")
>         (goto-char (- (re-search-forward "[A-Za-z<]") 1))
>       (goto-char (+ (re-search-backward "[[:space:]]") 1)))
>     (if (looking-at "<nop>")
>         (delete-char 5)
>       (insert "<nop>"))))

Some comments on the code:

The docstring is very technical - usually it
only describes what happens, leaving out most
implementation details. Usually, but
not always!

Also, the lines are very long so for some
people they won't fit on a screen. Break them
off and insert blank lines. Use \n if need be.

You know about `1+' and `1-' to add/subtract 1?

If the "5" is because (length "<nop>") is five,
it is better to compute that - data that is
derived from other data should be computed so
that, if other data change, so does data.

Indentation: add four spaces before the
first "(if".

> (add-hook 'emacs-wiki-mode-hook
>       '(lambda () (local-set-key "\C-c\C-n" 'emacs-wiki-unlink-toggle)))
>
> but in Wiki mode I can't toggle on or off a WikiLink.
> Why?

You don't need a lambda here (and they need not
be quoted). You can put a # before the
function quote.

Using `local-set-key' is one way to do it,
I would however `require' the emacs-wiki,
and then use `define-key' with the mode map, as
in:

    (require 'erc)
    (define-key erc-mode-map "\C-\M-p" #'erc-previous-command)

Ask again if it didn't help!

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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