[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to insert single quotes around a command?
From: |
Seweryn Kokot |
Subject: |
Re: how to insert single quotes around a command? |
Date: |
Fri, 31 Oct 2008 15:33:56 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
martin rudalics <rudalics@gmx.at> 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