all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* fill comma separated list
@ 2016-05-19 13:02 papab
  2016-05-19 13:12 ` Emanuel Berg
  2016-06-02 16:41 ` Jorge A. Alfaro-Murillo
  0 siblings, 2 replies; 9+ messages in thread
From: papab @ 2016-05-19 13:02 UTC (permalink / raw)
  To: help-gnu-emacs

I have a whole bunch of sequences of numbers, like this:
   5.1816,             
   -3.81,              
   4.8768,             
   5.1816,             
   -4.4196,            
   4.8768,             
   6.4008,             
   -4.4196,            
   5.48640,  
   6.4008,             
   -3.81,              
   5.486400;

I'd like to be able to make it look like this easily:
   5.1816, -3.81,  4.8768,             
   5.1816, -4.4196, 4.8768,             
   6.4008, -4.4196, 5.486400,  
   6.4008, -3.81,   5.48640

3 numbers per row.
Suggestions?  Some variation of fill-paragraph?


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

* Re: fill comma separated list
  2016-05-19 13:02 fill comma separated list papab
@ 2016-05-19 13:12 ` Emanuel Berg
  2016-06-02 16:08   ` Kaushal Modi
       [not found]   ` <mailman.702.1464883755.1216.help-gnu-emacs@gnu.org>
  2016-06-02 16:41 ` Jorge A. Alfaro-Murillo
  1 sibling, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2016-05-19 13:12 UTC (permalink / raw)
  To: help-gnu-emacs

papab <brad.r.haack@gmail.com> writes:

> I have a whole bunch of sequences of numbers,
> like this: 5.1816, -3.81, 4.8768, 5.1816,
> -4.4196, 4.8768, 6.4008, -4.4196, 5.48640,
> 6.4008, -3.81, 5.486400;
>
> I'd like to be able to make it look like this
> easily: 5.1816, -3.81, 4.8768, 5.1816,
> -4.4196, 4.8768, 6.4008, -4.4196, 5.486400,
> 6.4008, -3.81, 5.48640
>
> 3 numbers per row. Suggestions?
> Some variation of fill-paragraph?

You want to separate data, programming
(modification of the data), and interface
(display of the result).

Here, there is no modification of the data, but
you still want the display (interface) to be
programmable, as sometime in the future perhaps
you want four data items per row and then it'll
be super-fast to change the digit 3 into a 4
with no other change necessary!

This is called MVC but what happens when people
explain and/or define that is that everyone
gets confused and irritated. But it is
actually simple!

So if you understood my description as I think
you did, *don't* read the Wikipedia article on
MVC! [1]

I'd do:

    1. Put the data in a text file with no
       commas and one and only one data item
       per line.

    2. Write a defun that reads that into
       a Lisp list.

    3. Write a defun that iterates the list and
       prints a newline for every X items, 3 in
       your case.

Tell me if you need help with any of those
steps :)

[1] Hey, I told you not to read it!

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 34 Blogomatic articles -                   


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

* Re: fill comma separated list
  2016-05-19 13:12 ` Emanuel Berg
@ 2016-06-02 16:08   ` Kaushal Modi
       [not found]   ` <mailman.702.1464883755.1216.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Kaushal Modi @ 2016-06-02 16:08 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs, brad.r.haack

This works:

With this in a buffer:

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

C-x h ; Mark whole buffer
C-u M-| ; Run shell-command-on-region and replace region with results
paste -d' ' - - -

Do 'man paste' to learn more about that.

On Thu, Jun 2, 2016 at 11:50 AM Emanuel Berg <embe8573@student.uu.se> wrote:

> papab <brad.r.haack@gmail.com> writes:
>
> > I have a whole bunch of sequences of numbers,
> > like this: 5.1816, -3.81, 4.8768, 5.1816,
> > -4.4196, 4.8768, 6.4008, -4.4196, 5.48640,
> > 6.4008, -3.81, 5.486400;
> >
> > I'd like to be able to make it look like this
> > easily: 5.1816, -3.81, 4.8768, 5.1816,
> > -4.4196, 4.8768, 6.4008, -4.4196, 5.486400,
> > 6.4008, -3.81, 5.48640
> >
> > 3 numbers per row. Suggestions?
> > Some variation of fill-paragraph?
>
> You want to separate data, programming
> (modification of the data), and interface
> (display of the result).
>
> Here, there is no modification of the data, but
> you still want the display (interface) to be
> programmable, as sometime in the future perhaps
> you want four data items per row and then it'll
> be super-fast to change the digit 3 into a 4
> with no other change necessary!
>
> This is called MVC but what happens when people
> explain and/or define that is that everyone
> gets confused and irritated. But it is
> actually simple!
>
> So if you understood my description as I think
> you did, *don't* read the Wikipedia article on
> MVC! [1]
>
> I'd do:
>
>     1. Put the data in a text file with no
>        commas and one and only one data item
>        per line.
>
>     2. Write a defun that reads that into
>        a Lisp list.
>
>     3. Write a defun that iterates the list and
>        prints a newline for every X items, 3 in
>        your case.
>
> Tell me if you need help with any of those
> steps :)
>
> [1] Hey, I told you not to read it!
>
> --
> underground experts united .... http://user.it.uu.se/~embe8573
> Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
>                    - so far: 34 Blogomatic articles -
>
-- 

-- 
Kaushal Modi


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

* Re: fill comma separated list
  2016-05-19 13:02 fill comma separated list papab
  2016-05-19 13:12 ` Emanuel Berg
@ 2016-06-02 16:41 ` Jorge A. Alfaro-Murillo
  2016-06-02 17:47   ` Kaushal Modi
  1 sibling, 1 reply; 9+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2016-06-02 16:41 UTC (permalink / raw)
  To: help-gnu-emacs

papab writes:

> I have a whole bunch of sequences of numbers, like this:
>    5.1816,
>    -3.81,
>    4.8768,
>    5.1816,
>    -4.4196,
>    4.8768,
>    6.4008,
>    -4.4196,
>    5.48640,
>    6.4008,
>    -3.81,
>    5.486400;
>
> I'd like to be able to make it look like this easily:
>    5.1816, -3.81,  4.8768,
>    5.1816, -4.4196, 4.8768,
>    6.4008, -4.4196, 5.486400,
>    6.4008, -3.81,   5.48640
>
> 3 numbers per row.
> Suggestions?  Some variation of fill-paragraph?

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.
-- 
Jorge.




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

* Re: fill comma separated list
       [not found]   ` <mailman.702.1464883755.1216.help-gnu-emacs@gnu.org>
@ 2016-06-02 17:11     ` Emanuel Berg
  0 siblings, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2016-06-02 17:11 UTC (permalink / raw)
  To: help-gnu-emacs

Kaushal Modi <kaushal.modi@gmail.com> writes:

> This works:
>
> With this in a buffer:
>
> 5.1816, -3.81, 4.8768, 5.1816, -4.4196, 4.8768,
> 6.4008, -4.4196, 5.48640, 6.4008, -3.81,
> 5.486400;
>
> C-x h ; Mark whole buffer C-u M-| ; Run
> shell-command-on-region and replace region with
> results paste -d' ' - - -

Good for you. For everyone else, this juggling
is an impressive circus stunt which will
enthrall the masses, but true power comes in
this case from separating data, functions, and
interface. This is the exception that proves
the rule that computer science teachers are
always wrong.

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 42 Blogomatic articles -                   


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

* Re: fill comma separated list
  2016-06-02 16:41 ` Jorge A. Alfaro-Murillo
@ 2016-06-02 17:47   ` Kaushal Modi
  2016-06-02 18:36     ` Jorge A. Alfaro-Murillo
  0 siblings, 1 reply; 9+ messages in thread
From: Kaushal Modi @ 2016-06-02 17:47 UTC (permalink / raw)
  To: Jorge A. Alfaro-Murillo, help-gnu-emacs

On Thu, Jun 2, 2016 at 1:14 PM Jorge A. Alfaro-Murillo <
jorge.alfaro-murillo@yale.edu> wrote:

>
> 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.
>

http://i.imgur.com/dTdQRiG.gifv
Only the C-n key is not shown logged in the gif. But here is what I did

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)

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? :)

=====

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

-- 

-- 
Kaushal Modi


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

* Re: fill comma separated list
  2016-06-02 17:47   ` Kaushal Modi
@ 2016-06-02 18:36     ` Jorge A. Alfaro-Murillo
  2016-06-02 18:50       ` Jorge A. Alfaro-Murillo
  2016-06-02 19:06       ` Kaushal Modi
  0 siblings, 2 replies; 9+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2016-06-02 18:36 UTC (permalink / raw)
  To: help-gnu-emacs

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.




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

* Re: fill comma separated list
  2016-06-02 18:36     ` Jorge A. Alfaro-Murillo
@ 2016-06-02 18:50       ` Jorge A. Alfaro-Murillo
  2016-06-02 19:06       ` Kaushal Modi
  1 sibling, 0 replies; 9+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2016-06-02 18:50 UTC (permalink / raw)
  To: help-gnu-emacs

Jorge A. Alfaro-Murillo writes:

> 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 

I meant to say orgtbl-mode, but I sent before finishing the 
message.
-- 
Jorge.




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

* Re: fill comma separated list
  2016-06-02 18:36     ` Jorge A. Alfaro-Murillo
  2016-06-02 18:50       ` Jorge A. Alfaro-Murillo
@ 2016-06-02 19:06       ` Kaushal Modi
  1 sibling, 0 replies; 9+ messages in thread
From: Kaushal Modi @ 2016-06-02 19:06 UTC (permalink / raw)
  To: Jorge A. Alfaro-Murillo, help-gnu-emacs

On Thu, Jun 2, 2016, 2:46 PM Jorge A. Alfaro-Murillo <
jorge.alfaro-murillo@yale.edu> wrote:

>
> Cool! Most people would have do C-u instead of M-4,


I used M-4 so that I don't have to switch from Ctrl key to Alt key to do
M-^. By using M-4, I press Alt, then 4 and then ^ all the while keeping Alt
pressed. It just feels better typing that combo rather than C-u + M-^.

I thought
> there was something special with the 4,


I don't think so. I don't recall if delete-indentation checks for just
presence of a non-nil prefix argument or checks if user hit C-u or C-u C-u.
If the function checked for just non-nil prefix, M-0 would also work. I
used M-4 just to be on the safe side.

M-^ runs
> delete-indentation which joins this line with the previous and
> with universal argument joins this line with the following one.
>

Yes, join-line is an alias to delete-indentation.


> I was also not sure if with OP wanted spaces or to remove the
> commas at the end.


Yeah, it wasn't too clear.
-- 

-- 
Kaushal Modi


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

end of thread, other threads:[~2016-06-02 19:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-19 13:02 fill comma separated list papab
2016-05-19 13:12 ` Emanuel Berg
2016-06-02 16:08   ` Kaushal Modi
     [not found]   ` <mailman.702.1464883755.1216.help-gnu-emacs@gnu.org>
2016-06-02 17:11     ` Emanuel Berg
2016-06-02 16:41 ` Jorge A. Alfaro-Murillo
2016-06-02 17:47   ` Kaushal Modi
2016-06-02 18:36     ` Jorge A. Alfaro-Murillo
2016-06-02 18:50       ` Jorge A. Alfaro-Murillo
2016-06-02 19:06       ` Kaushal Modi

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.