* how to insert single quotes around a command?
@ 2008-10-31 10:06 Seweryn Kokot
2008-10-31 18:30 ` Ian Eure
0 siblings, 1 reply; 8+ messages in thread
From: Seweryn Kokot @ 2008-10-31 10:06 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
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?
Thanks in advance.
--
regards,
Seweryn
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to insert single quotes around a command?
@ 2008-10-31 12:44 martin rudalics
2008-10-31 14:33 ` Seweryn Kokot
0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2008-10-31 12:44 UTC (permalink / raw)
To: sewkokot; +Cc: help-gnu-emacs
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to insert single quotes around a command?
2008-10-31 12:44 martin rudalics
@ 2008-10-31 14:33 ` Seweryn Kokot
0 siblings, 0 replies; 8+ messages in thread
From: Seweryn Kokot @ 2008-10-31 14:33 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to insert single quotes around a command?
2008-10-31 10:06 how to insert single quotes around a command? Seweryn Kokot
@ 2008-10-31 18:30 ` Ian Eure
2008-10-31 20:22 ` Seweryn Kokot
0 siblings, 1 reply; 8+ messages in thread
From: Ian Eure @ 2008-10-31 18:30 UTC (permalink / raw)
To: Seweryn Kokot; +Cc: help-gnu-emacs
On Oct 31, 2008, at 3:06 AM, Seweryn Kokot wrote:
> Hello,
>
> 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?
>
Sounds like you want insert-pair:
(define-key (current-global-map) "\M-'" 'insert-pair)
(define-key (current-global-map) "\C-c`" 'insert-pair)
Which makes M-' insert a pair of single quotes, and C-c ` insert `'.
Then you can do M-1 M-' or M-1 C-c ` to enclose the sexp following
point in the correct quotes.
insert-pair is super handy, I use M-(sym) for () "" [] etc.
- Ian
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to insert single quotes around a command?
[not found] <mailman.2562.1225457196.25473.help-gnu-emacs@gnu.org>
@ 2008-10-31 20:09 ` Barry Margolin
0 siblings, 0 replies; 8+ messages in thread
From: Barry Margolin @ 2008-10-31 20:09 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.2562.1225457196.25473.help-gnu-emacs@gnu.org>,
martin rudalics <rudalics@gmx.at> wrote:
> > 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 ()
Why is it called "insert-hyphen-or-two" when it inserts quotes, not
hyphens?
> (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
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to insert single quotes around a command?
2008-10-31 18:30 ` Ian Eure
@ 2008-10-31 20:22 ` Seweryn Kokot
0 siblings, 0 replies; 8+ messages in thread
From: Seweryn Kokot @ 2008-10-31 20:22 UTC (permalink / raw)
To: help-gnu-emacs
Ian Eure <ian@digg.com> writes:
> On Oct 31, 2008, at 3:06 AM, Seweryn Kokot wrote:
>
>> Hello,
>>
>> 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?
>>
>
> Sounds like you want insert-pair:
> (define-key (current-global-map) "\M-'" 'insert-pair)
> (define-key (current-global-map) "\C-c`" 'insert-pair)
>
> Which makes M-' insert a pair of single quotes, and C-c ` insert `'.
> Then you can do M-1 M-' or M-1 C-c ` to enclose the sexp following
> point in the correct quotes.
>
> insert-pair is super handy, I use M-(sym) for () "" [] etc.
>
> - Ian
Thanks for inspiration. I also found `skeleton-pair-insert-maybe'
function from skeleton library
(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe) % ()
(global-set-key "[" 'skeleton-pair-insert-maybe) % []
(global-set-key "{" 'skeleton-pair-insert-maybe) % ""
(global-set-key "\"" 'skeleton-pair-insert-maybe) % ''
(global-set-key "`" 'skeleton-pair-insert-maybe) % `'
This inserts pairs of chars and also enclose a region. Now I have at
least three solutions and will see with time what fits me better.
--
regards,
Seweryn
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to insert single quotes around a command?
@ 2008-10-31 21:42 martin rudalics
0 siblings, 0 replies; 8+ messages in thread
From: martin rudalics @ 2008-10-31 21:42 UTC (permalink / raw)
To: sewkokot; +Cc: help-gnu-emacs
> It took me some time to understand how
> to use this function ;-), because invoking it by M-x `insert-hyphen-or-two'
> inserts
> character
Sorry, I'll try to be less cryptic next time. I use this function
because most often I first expand the name of the symbol and then
hitting "'" twice means I don't have to think about an extra command to
do what I want. It doesn't work in c-mode because till now I was too
lazy to define a separate symbol-table for this.
martin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to insert single quotes around a command?
@ 2008-10-31 21:42 martin rudalics
0 siblings, 0 replies; 8+ messages in thread
From: martin rudalics @ 2008-10-31 21:42 UTC (permalink / raw)
To: barmar; +Cc: help-gnu-emacs
> Why is it called "insert-hyphen-or-two" when it inserts quotes, not
> hyphens?
I must have been drinking when I wrote that ;-)
martin
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-10-31 21:42 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-31 10:06 how to insert single quotes around a command? Seweryn Kokot
2008-10-31 18:30 ` Ian Eure
2008-10-31 20:22 ` Seweryn Kokot
-- strict thread matches above, loose matches on Subject: below --
2008-10-31 12:44 martin rudalics
2008-10-31 14:33 ` Seweryn Kokot
[not found] <mailman.2562.1225457196.25473.help-gnu-emacs@gnu.org>
2008-10-31 20:09 ` Barry Margolin
2008-10-31 21:42 martin rudalics
2008-10-31 21:42 martin rudalics
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.