From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Seweryn Kokot Newsgroups: gmane.emacs.help Subject: Re: how to insert single quotes around a command? Date: Fri, 31 Oct 2008 15:33:56 +0100 Message-ID: <87y704ltpn.fsf@poczta.po.opole.pl> References: <490AFDB8.7030703@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1225463510 6207 80.91.229.12 (31 Oct 2008 14:31:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Oct 2008 14:31:50 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 31 15:32:52 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kvv3N-0000PT-01 for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Oct 2008 15:32:45 +0100 Original-Received: from localhost ([127.0.0.1]:36170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kvv2F-00074c-J4 for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Oct 2008 10:31:35 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kvv1m-00072g-JT for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 10:31:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kvv1k-00071p-9S for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 10:31:05 -0400 Original-Received: from [199.232.76.173] (port=44654 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kvv1k-00071j-4Z for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 10:31:04 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:51958 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kvv1j-00047U-Ey for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 10:31:03 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Kvv1W-0001qx-Ag for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 14:30:51 +0000 Original-Received: from nat-warynskiego.po.opole.pl ([217.173.199.132]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 31 Oct 2008 14:30:50 +0000 Original-Received: from sewkokot by nat-warynskiego.po.opole.pl with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 31 Oct 2008 14:30:50 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 40 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nat-warynskiego.po.opole.pl X-Operating-System: Debian GNU/Linux User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:BwVHJ5KVaBrxZWuqE676wRlh7ew= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:59288 Archived-At: martin rudalics writes: >> Many times when I write doc strings for elisp functions I forget to insert >> single-quotes around commands or variables like `a-command' or insert it >> wrong like 'a-command'. Is there a function or keybinding to do it >> properly? Maybe a function which enclose a selected command with >> single-quotes? > > I'm using: > > (defun insert-hyphen-or-two () > (interactive) > (cond > ((or (bolp) (not (looking-back "'"))) > ;; insert just one ' > (self-insert-command 1)) > ((save-excursion > (backward-char) > ;; Skip symbol backwards. > (and (not (zerop (skip-syntax-backward "w_"))) > (not (looking-back "`")) > (or (insert-and-inherit "`") t)))) > (t > ;; insert `' around following symbol > (delete-backward-char 1) > (unless (looking-back "`") (insert-and-inherit "`")) > (save-excursion > (skip-syntax-forward "w_") > (unless (looking-at "'") (insert-and-inherit "'")))))) > > (global-set-key [39] 'insert-hyphen-or-two) > > martin Thank you for this very useful function! It took me some time to understand how to use this function ;-), because invoking it by M-x `insert-hyphen-or-two' inserts character -- regards, Seweryn