Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #489712

Re: Programming Challenge - Winner Gets Prize [SOLVED]

From owl <owl@rooftop.invalid>
Newsgroups comp.os.linux.advocacy
Subject Re: Programming Challenge - Winner Gets Prize [SOLVED]
Date 2019-03-24 03:49 +0000
Organization O.W.L.
Message-ID <sz8b983tg3.aghu4@rooftop.invalid> (permalink)
References (6 earlier) <xz80aga03.tyho34@rooftop.invalid> <q76evr0qap@news4.newsguy.com> <sz0b8934g.a@rooftop.invalid> <q76gca06e7@news2.newsguy.com> <szxb803ga.ghuo3@rooftop.invalid>

Show all headers | View raw


owl <owl@rooftop.invalid> wrote:
> F. Russell <fr@random.info> wrote:
>> On Sat, 23 Mar 2019 23:34:39 +0000, owl wrote:
>> 
>>> 
>>> I don't see that option.
>>>
>> 
>> Actually the option is called "Insert stdout on completion."
>> 
> 
> Yeah.  I saw that, and when I ran your script on the selection,
> it inserted after the selected text.  It did not replace it.
> 
> 
>> The cooledit documentation does not have much info on scripting
>> but it says to examine the other built-in scripts for guidance.
>> 
>> So look at the other scripts and you will see what is happening.
>> 
>> 
>>> 
>>> Select some text anywhere and run xsel -o in a terminal.  That output
>>> can be fed to a script.
>>> 
>> 
>> OK.  But that does not have any relevance here.
>> 
> 
> It does, because it means there is no need for any internal mechanism
> to deal with the selection.  It can be passed to a script just by selecting
> the text and calling the script with $(xsel -o) as an argument or by
> having the script itself run $(xsel -o) to grab the selection.
> 
>>> 
>>> Your script is defining the cutoff.  Of course "vim can do that", because
>>> vim can work with any script or pipeline of scripts.  And there is no need
>>> to enter them into some internal dialog.  With vim you just call the script
>>> with its path using :!
>>>
>> 
>> But my script does not have to define the cutoff value.  I may decide
>> that I want a different cutoff for different places.  Thus I could dynamically
>> assign the cutoff value, with a dialog prompt, before each and every replacement.
>> 
>> Can vim assign script values dynamically by prompting the user?  I thought
>> not.
>> 
> 
> Sure.  Because, for one thing, the script itself could prompt with zenity
> if you wanted a nice gui dialog, or you could use Vim's builtin scripting
> language to write a function that prompts the user and then passes the
> response to a script.
> 
> :nnoremap <F7> :call Cut()<CR>
> function! Cut()
>  call inputsave()
>  let cutoff=input('How many? ')
>  call inputrestore()
>  execute ".!./tah " . cutoff
> endfunction
> 
> That could be in your .vimrc, or in a file that you would read in with
> the :source command.  It will prompt you at the bottom of the window
> for a number, then run the script "./tah" with that number as ${1}
> and paste the output on the current line.
> 

These two lines in either .vimrc or in a sourced file will either work
on a vim visual selection (not the X selection) or make the selection
for you, given the cursor is on the starting point, and will then do
the replacement inline, overwriting the selection.

:vnoremap <F7> d<Esc>i<CR><CR><Esc>kp:.!./fab<CR>k:.,+2j<CR>:.s/ //g<CR>
:nnoremap <F7> vf^ld<Esc>i<CR><CR><Esc>kp:.!./fab<CR>k:.,+2j<CR>:.s/ //g<CR>

In normal mode, just go to the starting point and hit F7.
In visual mode, you hit F7, and it will work on the selection you made.

There is a bug that I haven't worked out yet:  if the exponentiated
item is the last thing on the line, it erroneously puts the preceding
[+-/*] operator after the replacement.  Temporarily adding a '.' or 'x'
or something at the end makes it work. (Or just take it to a new line
and rejoin afterward). Every other case seems to work fine.  I haven't
tied it to a prompting function for the max exponent.  This is using
the following code for 'fab':

#!/bin/bash
while read x;do
  stuff=$(echo ${x} |sed -e 's/\(.*\)\^.*/\1/g')
  count=$(echo ${x} |sed -e 's/.*\^\(.*\)/\1/g')
  if [ "${count}" -lt 7 ];then
    for (( i = 1; i <= ${count} ; i++)); do
      echo -n "${stuff}"
       if [ "${i}" -lt "${count}" ]; then
         echo -n "*"
       fi
    done
  else
    echo -n "pow(${stuff},${count})"
  fi
done

Back to comp.os.linux.advocacy | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Programming Challenge - Winner Gets Prize "F. Russell" <frussell@random.info> - 2019-03-22 17:38 +0000
  Re: Programming Challenge - Winner Gets Prize Steve Carroll <fretwizzer@gmail.com> - 2019-03-22 10:47 -0700
    Re: Programming Challenge - Winner Gets Prize "F. Russell" <frussell@random.info> - 2019-03-22 17:56 +0000
      Re: Programming Challenge - Winner Gets Prize "F. Russell" <frussell@random.info> - 2019-03-22 18:07 +0000
      Re: Programming Challenge - Winner Gets Prize Steve Carroll <fretwizzer@gmail.com> - 2019-03-22 12:11 -0600
    Re: Programming Challenge - Winner Gets Prize Melzzzzz <Melzzzzz@zzzzz.com> - 2019-03-22 19:29 +0000
  Re: Programming Challenge - Winner Gets Prize owl <owl@rooftop.invalid> - 2019-03-22 19:48 +0000
    Re: Programming Challenge - Winner Gets Prize Melzzzzz <Melzzzzz@zzzzz.com> - 2019-03-22 19:51 +0000
      Re: Programming Challenge - Winner Gets Prize owl <owl@rooftop.invalid> - 2019-03-22 19:54 +0000
        Re: Programming Challenge - Winner Gets Prize Melzzzzz <Melzzzzz@zzzzz.com> - 2019-03-22 19:56 +0000
          Re: Programming Challenge - Winner Gets Prize owl <owl@rooftop.invalid> - 2019-03-22 19:59 +0000
    Re: Programming Challenge - Winner Gets Prize "F. Russell" <frussell@random.info> - 2019-03-22 20:04 +0000
      Re: Programming Challenge - Winner Gets Prize owl <owl@rooftop.invalid> - 2019-03-22 20:46 +0000
        Re: Programming Challenge - Winner Gets Prize owl <owl@rooftop.invalid> - 2019-03-23 00:51 +0000
          Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-23 21:00 +0000
            Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-23 22:58 +0000
              Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-23 23:20 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-23 16:33 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-23 23:34 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-23 23:44 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-24 00:59 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-24 03:49 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-23 21:16 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-24 12:41 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-24 13:55 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-24 14:30 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-24 14:49 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 08:15 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-24 15:31 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <fretwizzer@gmail.com> - 2019-03-24 08:48 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-24 16:00 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <fretwizzer@gmail.com> - 2019-04-01 07:09 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steven Petruzzellis <frelwizzen@gmail.com> - 2019-04-01 08:40 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Snit <usenet@gallopinginsanity.com> - 2019-03-24 17:23 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-24 17:25 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-24 18:48 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-24 19:27 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-24 23:03 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 16:33 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-24 23:35 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-25 00:18 +0000
                In my hands, vim is a worthless piece of shit. Jeff-Relf.Me  @. - 2019-03-24 18:01 -0700
                Re: In my hands, vim is a worthless piece of shit. Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 18:21 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 19:24 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Melzzzzz <Melzzzzz@zzzzz.com> - 2019-03-25 02:40 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] owl <owl@rooftop.invalid> - 2019-03-25 03:02 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-25 10:15 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <"Steve Carroll"@noSPAM.none> - 2019-03-25 14:56 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] "F. Russell" <fr@random.info> - 2019-03-25 09:30 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Mel <mel@zzzzz.com> - 2019-03-25 10:42 +0100
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Melzzzzz <Melzzzzz@zzzzz.com> - 2019-03-25 02:39 +0000
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 13:11 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 14:29 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 08:00 -0700
                Re: Programming Challenge - Winner Gets Prize [SOLVED] Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 07:11 -0700
          Re: Programming Challenge - Winner Gets Prize Melzzzzz <Melzzzzz@zzzzz.com> - 2019-03-23 22:29 +0000
            Re: Programming Challenge - Winner Gets Prize Steve Carroll <frelwizzen@gmail.com> - 2019-03-23 16:48 -0700
              Re: Programming Challenge - Winner Gets Prize Steve Carroll <frelwizzen@gmail.com> - 2019-03-23 18:53 -0700
                Re: Programming Challenge - Winner Gets Prize Steve Carroll <frelwizzen@gmail.com> - 2019-03-24 05:07 -0700
        Re: Programming Challenge - Winner Gets Prize "F. Russell" <fr@random.info> - 2019-03-23 15:31 +0000
          Re: Programming Challenge - Winner Gets Prize Steve Carroll <fretwizzer@gmail.com> - 2019-03-23 09:30 -0700
          Re: Programming Challenge - Winner Gets Prize "F. Russell" <fr@random.info> - 2019-03-23 18:49 +0000
  Re: Programming Challenge - Winner Gets Prize Nobody you know <nobody@nowhere.com> - 2019-03-23 20:25 -0400

csiph-web