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: Thu, 17 Aug 2017 13:54:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Here is how I would write it, I think. It seems
to work at least when inserting or removing the
tag is concerned.

If it gets more complicated, you might want to
factor out the searches (the
`re-search-forward's) and put them into
a `let', then check the associated values if
they are nil or not (see the help for
re-search-forward how to make it not report an
error on no hit), and then move point to
(match-beginning 0) - but only if you feel the
need to, using re-search-forward "inline" if
you will is a fine way to do it as well.

See answer one for comments what I did.
Except for [[:alpha:]] which I didn't mention.

In answer two there are some other comments.
This is answer three :)

    (defun emacs-wiki-unlink-toggle ()
      (interactive)
      (save-excursion
        (if (looking-at "[[:space:]]")
            (goto-char (1- (re-search-forward "[[:alpha:]<]")))
          (goto-char (1+ (re-search-backward "[[:space:]]"))))
        (let*((nop "<nop>")
              (nop-len (length nop)))
          (if (looking-at nop)
              (delete-char nop-len)
            (insert nop)))))

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




reply via email to

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