all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom <tom@somewhere.com>
To: help-gnu-emacs@gnu.org
Subject: Re: simple first emacs script
Date: Wed, 15 Dec 2010 17:28:38 +0000	[thread overview]
Message-ID: <dV6Oo.31755$ol5.19895@newsfe06.ams2> (raw)
In-Reply-To: <87hbefytr8.fsf@kuiper.lan.informatimago.com>

Wow Pascal that is quite an amazing response thanks.

You introduced several new things I don't know about so I can't comment 
on them until I go away and learn them but in response to what I do 
understand.

Yes the indentation was destroyed by newsreader, but thanks for pointing 
me to paredit as I was finding managing parenthesis a pain.

> The (require 'csv-mode) form would be better placed on the toplevel
> (ie. above the defun form).

I don't get this.  If I understand you correctly you are suggesting 
something like this:
(require 'csv-mode)
(defun ...
           )

If I do this then wont the require mode cease to be part of the 
functions definition.  Normally it would not be required to set the mode 
the csv as the file extension would be .csv and csv-mode is called 
automatically, but the raw files I receive have random extensions - I 
suppose I could rename them all to overcome this but it seemed simpler 
to tell the function to go into csv mode otherwise it tries to process 
the file in fundamental mode.


> Instead of push-mark (I don't see the matching pop-mark), you might use
> the save-excursion macro.

I did actually start with save-excursion but I have no interest in 
saving the point the mark, the whole point of pushing the mark and 
moving the point to the start of the buffer was to specify the region 
arguments in csv-kill-fields, i.e.
(csv-kill-fields '(4 ...) (point) (mark))

I guess this might be more logically done with
(csv-kill-fields '(4 ...) (point-min) (point-max))
would that be considered better form?

Thanks for the advice on eql cond, case, and distribution of my column 
specifiers that will clean things up a bit.  I don't know enough to 
follow your iota operator but that gives me something to work towards

> when (and unless and other macros) has an implicit progn, so there's no
> need to embed one in it.

That is handy to know.

> Ah, if you read the documentation of csv-kill-fields,  you will see that
> it depends on the right setting of the variable csv-separators to know
> what separator to use.  By default I have it set to a comma.  So you
> want to bind this variable in your function:
>
>      (let ((csv-separators '(" ")))
>        (csv-kill-fields ...))
> Note however that it is a single character string, and that your fields
> are separated by several.  When I try it, it fails with csv-kill-fields
> complaining about the number of columns.  It is probably better to use
> commas to separate the fields, ...

I have read the documentation (that doesn't mean I understood it 
though).  I have the csv separators specified in my .emacs file (it seem 
it will accept both " " and "," so csv-modes seems to read my files 
correctly.  But I guess it is logical to specify these in the function 
in case I run it on a computer without these specified.  I don't seem to 
get problems  with csv-kill-fields complaining about number of columns 
but maybe I have just worked through it with trial and error and no real 
understanding.

> Indeed, this is a good intension.  You can separate interactive user
> interface commands from the functions doing the actual work, so that you
> can reuse the later.  The interactive form allow you to merge both
> usages.
>
> You only have to add the wanted parameter, and specify it in the
> interactive form.  You can also specify some parameters optional:
>
>
>      (defun nirs-data-clean (number-of-channels&optional replace-StO2-0-p)
>         ...)
>
> The simple interactive form would use a multiline string:
>
>        (interactive "*nEnter number of channels (1-4):
> sReplace 0 StO$_2$ values with na (y/n): ")
>
> Unfortunately, interactive doesn't provide for a 'boolean' input, so
> we'll keep using the sophisticated form:

When I said I can't do this I was looking to specify boolean input, good 
to know I shouldn't waste my time looking for it.  I could have probably 
worked it out the way you showed but it would have probably taken me a 
few hours of testing so thanks for demonstrating that.

Your final script seems more solid than mine, as in it behaves in the 
same way on either iteration even after undoing.  It doesn't seem to 
work perfectly with across all channel options in some of the files I 
ran it one, but there are lots of ideas in there (such as temporarily 
using commas) for me to incorporate into my script so thanks again.


  reply	other threads:[~2010-12-15 17:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-15 12:55 simple first emacs script Tom
2010-12-15 14:51 ` Pascal J. Bourguignon
2010-12-15 17:28   ` Tom [this message]
2010-12-15 18:37     ` Pascal J. Bourguignon
2010-12-16 15:21       ` Tom
2010-12-16 21:55       ` Stefan Monnier
2010-12-17 22:13         ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='dV6Oo.31755$ol5.19895@newsfe06.ams2' \
    --to=tom@somewhere.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.