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

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

Re: Major and minor modes


From: Emanuel Berg
Subject: Re: Major and minor modes
Date: Wed, 14 Jun 2017 11:36:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Another thing to note is that the major mode is
just a tool, a good tool, but not a necessary
tool for every lite code snippet.

Here (last) is an example. It is a zsh wrapper
to some awk code that I found on the net.
Of course, that made the need for awk-mode even
smaller. But I did edit the awk, in the
Shell-script[zsh] mode, without even thinking
about not being in awk-mode.

And that is actually a good rule of thumb.
When you experience not being in the right mode
is a disadvantage to your work, then you should
think of a way to factor out the foreign code.

numbers () {
    # thank you: https://unix.stackexchange.com/a/13779
    echo "items\tsum\tlow\thigh\tmedian\tmean"
    sort -n | awk '
          BEGIN {
            c = 0;
            sum = 0;
          }
          $1 ~ /^[0-9]*(\.[0-9]*)?$/ {
            a[c++] = $1;
            sum += $1;
          }
          END {
            ave = int(sum/c) + 1;
            if ( (c % 2) == 1 ) {
              median = a[ int(c/2) ];
            } else {
              median = ( a[c/2] + a[c/2-1] ) / 2;
            }
            OFS="\t";
            print c, sum, a[0], a[c-1], median, ave
          }
        '
}

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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