From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?B?Q3PDoW55aSBQw6Fs?= Newsgroups: gmane.emacs.help Subject: Re: Toggle WikiLink on and off does not work? Date: Thu, 17 Aug 2017 10:17:34 +0200 Message-ID: References: <86valnzhwa.fsf@zoho.com> Reply-To: csanyipal@gmail.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1502957907 18262 195.159.176.226 (17 Aug 2017 08:18:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 17 Aug 2017 08:18:27 +0000 (UTC) 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 10:18:20 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 1diG0M-0003mz-Cv for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Aug 2017 10:18:14 +0200 Original-Received: from localhost ([::1]:38451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diG0P-0001Ab-Jz for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Aug 2017 04:18:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diFzq-00018T-N2 for help-gnu-emacs@gnu.org; Thu, 17 Aug 2017 04:17:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diFzk-0003Oy-P2 for help-gnu-emacs@gnu.org; Thu, 17 Aug 2017 04:17:42 -0400 Original-Received: from mail-pg0-x233.google.com ([2607:f8b0:400e:c05::233]:36351) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diFzk-0003Og-Iw for help-gnu-emacs@gnu.org; Thu, 17 Aug 2017 04:17:36 -0400 Original-Received: by mail-pg0-x233.google.com with SMTP id i12so38163454pgr.3 for ; Thu, 17 Aug 2017 01:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:content-transfer-encoding; bh=pi5Z3fkJG7eg+5bkpVYB4GAAGGdPivolL39j/7+OeGg=; b=hugvOnmZEFXhR5rUz2HI8LZj0AfZLpBaiPdNScFc/31bwrZoOQnV+GKRN+/MCFwvPV wb14FOs7yDOLpSGwvtQpZLNUPBzivJUlUO0rTR07qm3Y9h2jCAH85RTcV3rRiDdUjIKh itPxEIV5WNwkvAcmfIESvzM00WUh0vRhjlypFEiUEkXqj763SXqCKl/345pCYbVzPF71 XnvqBLcJ9UtiyV/40xFLwd6G+TGiKKZFRKD9t8oGGml+N65PIN/cE3WKfwFnVGiUUKLC 7K3Q9pHQBhEe1+lskuyhMer0eDhhm76sKeqqSj3sgFNbxk3RlOFBkgoIYLVMVhY6nnuH GF/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:content-transfer-encoding; bh=pi5Z3fkJG7eg+5bkpVYB4GAAGGdPivolL39j/7+OeGg=; b=tQri2YryGaZRUkwyFBuwcMlSBFcPQxNNqLbDpO/DW9ca/JOgAq29ne4KAUYko2KceA 6toTncs3/yl2qrSTpj+5ep/RK93CWLyAN1AZ791yRFu5vgRuPufvTzgI26M4o6psCZuR LXne/DdZadmWnKNkpXDad2i0zNsgO0F0RbR0KmYt1OWbZpfha/Xb+2YA2GCjf5Sq/K0M LrxkWpqPb7EkbI81+HhPms7bwTxZElUqSCygLkysCi1rQHFGCVw2dDcPjCYa0q86zFiW dW8+k6eq/M24Yvf9HKR3MO5EIq2y3q/jODb7yUzEa8lDHHpSdFOn+I2N6o1JyfHUAaJw 73Xw== X-Gm-Message-State: AHYfb5jecjVme8ttwL1s4u6CB/YsjtBs8Y/yFr+VgeOXCx3Dm9sqMj+C dBrYupCmufpQkVJde5rRPA3s2+1wqBLpZps= X-Received: by 10.84.224.72 with SMTP id a8mr3442625plt.399.1502957855280; Thu, 17 Aug 2017 01:17:35 -0700 (PDT) Original-Received: by 10.100.142.22 with HTTP; Thu, 17 Aug 2017 01:17:34 -0700 (PDT) In-Reply-To: <86valnzhwa.fsf@zoho.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::233 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:114065 Archived-At: 2017-08-16 16:50 GMT+02:00 Emanuel Berg : > Cs=C3=A1nyi P=C3=A1l wrote: > >> ;; Toggle WikiLink on and off >> (defun emacs-wiki-unlink-toggle () >> "Toggle string in the beginning of the current word, to un/m= ake 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 wor= d 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! 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 fil= e: (require 'emacs-wiki) ;; Toggle WikiLink on and off (defun emacs-wiki-unlink-toggle () (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 "")))) (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, eg. if I have in a Wiki page the WikiLink word, and the cursor is on that word,= then the C-c C-n gives: WikiLink but WikiLink remain to be a Wiki Link. And if I after that hit again C-c C-n then the disappeared, I get aga= in: WikiLink 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? --=20 Best, Pali