From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Toggle WikiLink on and off does not work? Date: Thu, 17 Aug 2017 13:54:47 +0200 Message-ID: <86pobuwgs8.fsf@zoho.com> References: <86valnzhwa.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1502970949 20213 195.159.176.226 (17 Aug 2017 11:55:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 17 Aug 2017 11:55:49 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 17 13:55:44 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diJOn-0004oG-6V for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Aug 2017 13:55:41 +0200 Original-Received: from localhost ([::1]:47495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diJOt-0001B3-Rn for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Aug 2017 07:55:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diJOP-0001At-Vi for help-gnu-emacs@gnu.org; Thu, 17 Aug 2017 07:55:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diJOL-0007Yp-6B for help-gnu-emacs@gnu.org; Thu, 17 Aug 2017 07:55:18 -0400 Original-Received: from [195.159.176.226] (port=49048 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diJOK-0007XQ-Ux for help-gnu-emacs@gnu.org; Thu, 17 Aug 2017 07:55:13 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1diJO8-0002mV-Ta for help-gnu-emacs@gnu.org; Thu, 17 Aug 2017 13:55:00 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 36 Original-X-Complaints-To: usenet@blaine.gmane.org Mail-Copies-To: never Cancel-Lock: sha1:y1OdGWVdv+PVUxtx2QcleW5T9bs= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:114067 Archived-At: 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-len (length nop))) (if (looking-at nop) (delete-char nop-len) (insert nop))))) -- underground experts united http://user.it.uu.se/~embe8573