all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Abbrev , as ,_
@ 2003-10-30  0:27 Jiri Pejchal
  2003-10-30  1:27 ` Jesper Harder
  0 siblings, 1 reply; 5+ messages in thread
From: Jiri Pejchal @ 2003-10-30  0:27 UTC (permalink / raw)



When I code in Java or C++ I always type space after ",".
For example foo(a, f)
                  ^                
                  |
                  
Can Emacs put the space there automatically?
I tried to make an abbrev for it, but it didn't work for me.


--
Jiri Pejchal

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abbrev , as ,_
  2003-10-30  0:27 Abbrev , as ,_ Jiri Pejchal
@ 2003-10-30  1:27 ` Jesper Harder
  2003-10-30  4:27   ` Dan Anderson
  0 siblings, 1 reply; 5+ messages in thread
From: Jesper Harder @ 2003-10-30  1:27 UTC (permalink / raw)


Jiri Pejchal <xpejchal@fi.muni.cz> writes:

> When I code in Java or C++ I always type space after ",".
> For example foo(a, f)
>                   ^                
>                   |
>                   
> Can Emacs put the space there automatically?
> I tried to make an abbrev for it, but it didn't work for me.

You could do something like this:

(define-key c-mode-map "," (lambda ()
			     (interactive)
			     (insert ", ")))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abbrev , as ,_
  2003-10-30  1:27 ` Jesper Harder
@ 2003-10-30  4:27   ` Dan Anderson
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Anderson @ 2003-10-30  4:27 UTC (permalink / raw)
  Cc: help-gnu-emacs

Out of curiosity, wouldn't that mean that typing in:

foo = "1,2,3,4,5";

Would create:

foo = "1, 2, 3, 4, 5";

And cause problems?  Granted many times commas and spaces go hand in
hand, but in scenarios like a CSV list it would be horribly wrong.

-Dan

On Wed, 2003-10-29 at 20:27, Jesper Harder wrote:
> Jiri Pejchal <xpejchal@fi.muni.cz> writes:
> 
> > When I code in Java or C++ I always type space after ",".
> > For example foo(a, f)
> >                   ^                
> >                   |
> >                   
> > Can Emacs put the space there automatically?
> > I tried to make an abbrev for it, but it didn't work for me.
> 
> You could do something like this:
> 
> (define-key c-mode-map "," (lambda ()
> 			     (interactive)
> 			     (insert ", ")))
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abbrev , as ,_
@ 2003-10-30 14:46 Roberto Huelga
  0 siblings, 0 replies; 5+ messages in thread
From: Roberto Huelga @ 2003-10-30 14:46 UTC (permalink / raw)



El Jueves, 30 octubre, 2003, a las 05:27 AM, Dan Anderson escribió:

> Out of curiosity, wouldn't that mean that typing in:
>
> foo = "1,2,3,4,5";
>
> Would create:
>
> foo = "1, 2, 3, 4, 5";
>
> And cause problems?  Granted many times commas and spaces go hand in
> hand, but in scenarios like a CSV list it would be horribly wrong.
>
> -Dan

Here is the solution, it don't expand in comments, strings and others 
contexts.

(define-key c-mode-map ","
   (lambda ()
     (interactive)
     (let* ((face (get-text-property (point) 'face )))
     (if
	(or (equal face 'font-lock-comment-face)
	    (equal face 'font-lock-string-face)
	    (equal face 'font-lock-warning-face)
	    (equal face 'font-lock-doc-face))
	(insert ",")
	(insert ", ")
       ))))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abbrev , as ,_
       [not found] <mailman.2813.1067525348.21628.help-gnu-emacs@gnu.org>
@ 2003-10-30 17:06 ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2003-10-30 17:06 UTC (permalink / raw)


[ Try to use TAB to indent your code, so it's easier to read for others. ]

>      (let* ((face (get-text-property (point) 'face )))
>      (if
> 	(or (equal face 'font-lock-comment-face)
> 	    (equal face 'font-lock-string-face)
> 	    (equal face 'font-lock-warning-face)
> 	    (equal face 'font-lock-doc-face))
> 	(insert ",")
> 	(insert ", ")
>        ))))

AKA

   (insert
    (if (member (get-text-property (point) 'face)
                '(font-lock-comment-face font-lock-string-face
                  font-lock-warning-face font-lock-doc-face))
        "," ", "))


-- Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-10-30 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-30  0:27 Abbrev , as ,_ Jiri Pejchal
2003-10-30  1:27 ` Jesper Harder
2003-10-30  4:27   ` Dan Anderson
  -- strict thread matches above, loose matches on Subject: below --
2003-10-30 14:46 Roberto Huelga
     [not found] <mailman.2813.1067525348.21628.help-gnu-emacs@gnu.org>
2003-10-30 17:06 ` Stefan Monnier

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.