help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fill comma separated list


From: Jorge A. Alfaro-Murillo
Subject: Re: fill comma separated list
Date: Thu, 02 Jun 2016 14:36:53 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Kaushal Modi writes:

Jorge A. Alfaro-Murillo writes:

Let's play emacs golf: (I assume no whitespace and cursor at the initial 5): F3 C-e <space> C-d C-e <space> C-d C-e <backspace> C-n C-a F4 C-0 F4
14 key strokes.

With cursor at the initial 5, (1) F3 (2,3) M-4 M-^ (In fact, I have bound the functionality of C-u M-^ to C-j [see below]) (4,5) M-4 M-^ (6) C-n (7,8) M-0 F4 (you do not need to hit F4 and then do M-0 F4)

True! I didn't know that thanks!

8 keys (10 keys, if adding the 2 spaces) I count M-4/M-0 as single keystrokes as I use the Alt key, not Esc. That should be OK? :)

Cool! Most people would have do C-u instead of M-4, I thought there was something special with the 4, M-^ runs delete-indentation which joins this line with the previous and with universal argument joins this line with the following one.

I was also not sure if with OP wanted spaces or to remove the commas at the end. He posted it without the ; and I did it without commas at the end. For the emacs golf let's play leaving it at

5.1816,-3.81,4.8768,
5.1816,-4.4196,4.8768,
6.4008,-4.4196,5.48640,
6.4008,-3.81,5.486400;

For the OP, if you want indentation you should remove the commas at the end and take a look at csv-mode, in particular C-c C-a. Alternatively, transform it to:

|5.1816|-3.81|4.8768,|
|5.1816|-4.4196|4.8768|
|6.4008|-4.4196|5.48640|
|6.4008|-3.81|5.486400|

And take a look at
===== If interested, I bind C-j to below: (defun modi/pull-up-line () "Join the following line onto the current one (analogous to `C-e', `C-d') or `C-u M-^' or `C-u M-x join-line'. If the current line is a comment and the pulled-up line is also a comment, remove the comment characters from that line." (interactive) (join-line -1) ;; If the current line is a comment (when (nth 4 (syntax-ppss)) ;; Remove the comment prefix chars from the pulled-up line if present (save-excursion ;; Delete all comment-start and space characters (while (looking-at (concat "\\s<" ; comment-start char as per syntax table "\\|" (substring comment-start 0 1) ; first char of `comment-start' "\\|" "\\s-")) ; extra spaces (delete-forward-char 1)) (insert-char ? )))) ; insert space --

--
Jorge.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]