[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: Csányi Pál
Subject: Re: Toggle WikiLink on and off does not work?
Date: Thu, 17 Aug 2017 10:17:34 +0200

2017-08-16 16:50 GMT+02:00 Emanuel Berg <>:
> 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!

So I am trying to understand your advices.
This is the elisp program language and I am a newbie here.

Here is the code for the Emacs Wiki mode, which I have now in my .emacs file:
(require 'emacs-wiki)

;; Toggle WikiLink on and off
(defun emacs-wiki-unlink-toggle ()
    (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>"))))

(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

A want to add to this question more.
Actually, with the previous setup the C-c C-n keybinding works,
if I have in a Wiki page the WikiLink word, and the cursor is on that word, then
the C-c C-n gives:
but WikiLink remain to be a Wiki Link.
And if I after that hit again C-c C-n then the <nop> disappeared, I get again:

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?

This is what not works here. Why?

Best, Pali

reply via email to

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