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: Wed, 16 Aug 2017 16:50:13 +0200 Message-ID: <86valnzhwa.fsf@zoho.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1502895079 11500 195.159.176.226 (16 Aug 2017 14:51:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 16 Aug 2017 14:51:19 +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 Wed Aug 16 16:51:14 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 1dhzf3-0002US-SW for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Aug 2017 16:51:09 +0200 Original-Received: from localhost ([::1]:51614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhzfA-0001JN-2U for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Aug 2017 10:51:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhzee-0001GI-MR for help-gnu-emacs@gnu.org; Wed, 16 Aug 2017 10:50:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhzeb-0004eT-H3 for help-gnu-emacs@gnu.org; Wed, 16 Aug 2017 10:50:44 -0400 Original-Received: from [195.159.176.226] (port=44478 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dhzeb-0004eC-4w for help-gnu-emacs@gnu.org; Wed, 16 Aug 2017 10:50:41 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dhzeH-0008PP-9G for help-gnu-emacs@gnu.org; Wed, 16 Aug 2017 16:50:21 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 63 Original-X-Complaints-To: usenet@blaine.gmane.org Mail-Copies-To: never Cancel-Lock: sha1:1EO5zR50XuYeXY3hetdCzguaROA= 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:114061 Archived-At: Csányi Pál wrote: > ;; Toggle WikiLink on and off > (defun emacs-wiki-unlink-toggle () > "Toggle 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 "") > (delete-char 5) > (insert "")))) 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 "") 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