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

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

Re: simple first emacs script


From: Tom
Subject: Re: simple first emacs script
Date: Wed, 15 Dec 2010 17:28:38 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7

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 via email to

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