Re: Pipe text from mg to external command
A refined version of the diff with 2 less bugs and shorter by ~40 or so lines. Changes from previous version... Reuse region_get_data() to extract C string from selected region instead of custom line by line iteration, thereby reducing number of send(2) syscalls. Fix a bug which causes gratuitous text from previous invocation to appear if previous command input's last line doesn't have a '\n'. Fix a crash issue when a region from "Shell Command Ouput" buffer is pipe'd to external command. Index: README === RCS file: /cvs/src/usr.bin/mg/README,v retrieving revision 1.8 diff -u -p -r1.8 README --- README 1 Aug 2011 12:15:23 - 1.8 +++ README 5 Apr 2012 19:02:18 - @@ -61,7 +61,9 @@ recognized as special cases. On systems with 16 bit integers, the kill buffer cannot exceed 32767 bytes. - +Unlike GNU Emacs, Mg's minibuffer isn't multi-line aware and hence +some commands like "shell-command-on-region" always pop up a buffer to +display output irrespective of output's size. New implementation oddities: Index: def.h === RCS file: /cvs/src/usr.bin/mg/def.h,v retrieving revision 1.118 diff -u -p -r1.118 def.h --- def.h 10 Dec 2011 14:09:48 - 1.118 +++ def.h 16 Mar 2012 04:59:14 - @@ -567,6 +567,8 @@ int prefixregion(int, int); int setprefix(int, int); int region_get_data(struct region *, char *, int); voidregion_put_data(const char *, int); +int markbuffer(int, int); +int piperegion(int, int); /* search.c X */ int forwsearch(int, int); Index: funmap.c === RCS file: /cvs/src/usr.bin/mg/funmap.c,v retrieving revision 1.36 diff -u -p -r1.36 funmap.c --- funmap.c14 Mar 2012 13:56:35 - 1.36 +++ funmap.c16 Mar 2012 04:59:14 - @@ -113,6 +113,7 @@ static struct funmap functnames[] = { {localbind, "local-set-key",}, {localunbind, "local-unset-key",}, {makebkfile, "make-backup-files",}, + {markbuffer, "mark-whole-buffer",}, {do_meta, "meta-key-mode",},/* better name, anyone? */ {negative_argument, "negative-argument",}, {newline, "newline",}, @@ -166,6 +167,7 @@ static struct funmap functnames[] = { {setfillcol, "set-fill-column",}, {setmark, "set-mark-command",}, {setprefix, "set-prefix-string",}, + {piperegion, "shell-command-on-region",}, {shrinkwind, "shrink-window",}, #ifdef NOTAB {space_to_tabstop, "space-to-tabstop",}, Index: keymap.c === RCS file: /cvs/src/usr.bin/mg/keymap.c,v retrieving revision 1.47 diff -u -p -r1.47 keymap.c --- keymap.c14 Mar 2012 13:56:35 - 1.47 +++ keymap.c16 Mar 2012 04:59:14 - @@ -135,7 +135,7 @@ static PF cXcar[] = { #endif /* !NO_MACRO */ setfillcol, /* f */ gotoline, /* g */ - rescan, /* h */ + markbuffer, /* h */ fileinsert, /* i */ rescan, /* j */ killbuffer_cmd, /* k */ @@ -257,7 +257,7 @@ static PF metal[] = { rescan, /* y */ rescan, /* z */ gotobop,/* { */ - rescan, /* | */ + piperegion, /* | */ gotoeop /* } */ }; Index: mg.1 === RCS file: /cvs/src/usr.bin/mg/mg.1,v retrieving revision 1.58 diff -u -p -r1.58 mg.1 --- mg.19 Feb 2012 09:00:14 - 1.58 +++ mg.116 Mar 2012 04:59:14 - @@ -196,6 +196,8 @@ call-last-kbd-macro set-fill-column .It C-x g goto-line +.It C-x h +mark-whole-buffer .It C-x i insert-file .It C-x k @@ -260,6 +262,8 @@ copy-region-as-kill execute-extended-command .It M-{ backward-paragraph +.It M-| +shell-command-on-region .It M-} forward-paragraph .It M-~ @@ -572,6 +576,9 @@ Bind a key mapping in the local (topmost Unbind a key mapping in the local (topmost) mode. .It make-backup-files Toggle generation of backup files. +.It mark-whole-buffer +Marks whole buffer as a region by putting dot at the beginning and mark +at the end of buffer. .It meta-key-mode When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. @@ -734,6 +741,8 @@ Used by auto-fill-mode. Sets the mark in the current window to the current dot location. .It set-prefix-string Sets the prefix string to be used by the 'prefix-region' command. +.It shell-command-on-region +Provide the text in region to the shell command as input. .It shrink-window Shrink current window by one line. The window immediately below is expanded to pick up the slack. Index
Re: Pipe text from mg to external command
irrespective of all the talk going on here... :) -Toby.
Re: Pipe text from mg to external command
Regardless, I stand by my original comment. :) On Thursday, March 29, 2012, Jason McIntyre wrote: > On Thu, Mar 29, 2012 at 12:00:56AM -0400, Kjell Wooding wrote: > > There's nothing *technically* wrong with "irrespective," but it is a tad > > awkward when compared with "regardless." > > > > there's nothing *at all* wrong with "irrespective". you obviously just > don;t like it (if we don;t use words or phrases, they often sound odd, > or just plain wrong). but that's no reason to ask someone to change it. > > having said that, there is a huge bias towards "regardless" in the man > pages, and relatively few instances of "irrespective". perhaps it is no > longer fashionable. > > > "irregardless" is a hangable offense. > > > > aww! but it's so cute! > > jmc
Re: Pipe text from mg to external command
On Thu, Mar 29, 2012 at 10:26 AM, Jason McIntyre wrote: > On Thu, Mar 29, 2012 at 12:00:56AM -0400, Kjell Wooding wrote: >> There's nothing *technically* wrong with "irrespective," but it is a tad >> awkward when compared with "regardless." >> > > there's nothing *at all* wrong with "irrespective". you obviously just > don;t like it (if we don;t use words or phrases, they often sound odd, > or just plain wrong). but that's no reason to ask someone to change it. > > having said that, there is a huge bias towards "regardless" in the man > pages, and relatively few instances of "irrespective". perhaps it is no > longer fashionable. > >> "irregardless" is a hangable offense. >> > > aww! but it's so cute! And so is bikeshedding :)
Re: Pipe text from mg to external command
On Thu, Mar 29, 2012 at 12:00:56AM -0400, Kjell Wooding wrote: > There's nothing *technically* wrong with "irrespective," but it is a tad > awkward when compared with "regardless." > there's nothing *at all* wrong with "irrespective". you obviously just don;t like it (if we don;t use words or phrases, they often sound odd, or just plain wrong). but that's no reason to ask someone to change it. having said that, there is a huge bias towards "regardless" in the man pages, and relatively few instances of "irrespective". perhaps it is no longer fashionable. > "irregardless" is a hangable offense. > aww! but it's so cute! jmc
Re: Pipe text from mg to external command
There's nothing *technically* wrong with "irrespective," but it is a tad awkward when compared with "regardless." "irregardless" is a hangable offense. On Wed, Mar 28, 2012 at 1:40 AM, Jason McIntyre wrote: > On Tue, Mar 27, 2012 at 10:46:46PM -0400, Kjell Wooding wrote: > > s/irrespective/regardless/ > > > > there's nothing wrong with "irrespective". it's used correctly here (to > mean exactly the same as "regardless"). are you maybe confusing it with > the classic "irregardless"? > > "irregardless" is sometimes worth slipping in, in my opinion ;) > > jmc > > > On Tue, Mar 27, 2012 at 12:57 PM, Sunil Nimmagadda < > > su...@sunilnimmagadda.com> wrote: > > > > > This version implements some off-list review comments... > > > > > > 1. Discard explicit checking whether command exists and it's > > > permissions since shell already does and reports error. > > > > > > 2. Remove unnecessary bzero call. > > > > > > 3. Document minor deviation from emacs behaviour in README. > > > > > > Index: README > > > === > > > RCS file: /cvs/src/usr.bin/mg/README,v > > > retrieving revision 1.8 > > > diff -u -p -r1.8 README > > > --- README 1 Aug 2011 12:15:23 - 1.8 > > > +++ README 20 Mar 2012 17:54:12 - > > > @@ -61,7 +61,9 @@ recognized as special cases. > > > On systems with 16 bit integers, the kill buffer cannot exceed 32767 > > > bytes. > > > > > > - > > > +Unlike GNU Emacs, Mg's minibuffer isn't multi-line aware and hence > > > +some commands like "shell-command-on-region" always pop up a buffer to > > > +display output irrespective of output's size. > > > > > > New implementation oddities:
Re: Pipe text from mg to external command
On Tue, Mar 27, 2012 at 10:46:46PM -0400, Kjell Wooding wrote: > s/irrespective/regardless/ > there's nothing wrong with "irrespective". it's used correctly here (to mean exactly the same as "regardless"). are you maybe confusing it with the classic "irregardless"? "irregardless" is sometimes worth slipping in, in my opinion ;) jmc > On Tue, Mar 27, 2012 at 12:57 PM, Sunil Nimmagadda < > su...@sunilnimmagadda.com> wrote: > > > This version implements some off-list review comments... > > > > 1. Discard explicit checking whether command exists and it's > > permissions since shell already does and reports error. > > > > 2. Remove unnecessary bzero call. > > > > 3. Document minor deviation from emacs behaviour in README. > > > > Index: README > > === > > RCS file: /cvs/src/usr.bin/mg/README,v > > retrieving revision 1.8 > > diff -u -p -r1.8 README > > --- README 1 Aug 2011 12:15:23 - 1.8 > > +++ README 20 Mar 2012 17:54:12 - > > @@ -61,7 +61,9 @@ recognized as special cases. > > On systems with 16 bit integers, the kill buffer cannot exceed 32767 > > bytes. > > > > - > > +Unlike GNU Emacs, Mg's minibuffer isn't multi-line aware and hence > > +some commands like "shell-command-on-region" always pop up a buffer to > > +display output irrespective of output's size. > > > > New implementation oddities:
Re: Pipe text from mg to external command
s/irrespective/regardless/ On Tue, Mar 27, 2012 at 12:57 PM, Sunil Nimmagadda < su...@sunilnimmagadda.com> wrote: > This version implements some off-list review comments... > > 1. Discard explicit checking whether command exists and it's > permissions since shell already does and reports error. > > 2. Remove unnecessary bzero call. > > 3. Document minor deviation from emacs behaviour in README. > > Index: README > === > RCS file: /cvs/src/usr.bin/mg/README,v > retrieving revision 1.8 > diff -u -p -r1.8 README > --- README 1 Aug 2011 12:15:23 - 1.8 > +++ README 20 Mar 2012 17:54:12 - > @@ -61,7 +61,9 @@ recognized as special cases. > On systems with 16 bit integers, the kill buffer cannot exceed 32767 > bytes. > > - > +Unlike GNU Emacs, Mg's minibuffer isn't multi-line aware and hence > +some commands like "shell-command-on-region" always pop up a buffer to > +display output irrespective of output's size. > > New implementation oddities: > > Index: def.h > === > RCS file: /cvs/src/usr.bin/mg/def.h,v > retrieving revision 1.118 > diff -u -p -r1.118 def.h > --- def.h 10 Dec 2011 14:09:48 - 1.118 > +++ def.h 16 Mar 2012 04:59:14 - > @@ -567,6 +567,8 @@ int prefixregion(int, int); > int setprefix(int, int); > int region_get_data(struct region *, char *, int); > voidregion_put_data(const char *, int); > +int markbuffer(int, int); > +int piperegion(int, int); > > /* search.c X */ > int forwsearch(int, int); > Index: funmap.c > === > RCS file: /cvs/src/usr.bin/mg/funmap.c,v > retrieving revision 1.36 > diff -u -p -r1.36 funmap.c > --- funmap.c14 Mar 2012 13:56:35 - 1.36 > +++ funmap.c16 Mar 2012 04:59:14 - > @@ -113,6 +113,7 @@ static struct funmap functnames[] = { >{localbind, "local-set-key",}, >{localunbind, "local-unset-key",}, >{makebkfile, "make-backup-files",}, > + {markbuffer, "mark-whole-buffer",}, >{do_meta, "meta-key-mode",},/* better name, anyone? */ >{negative_argument, "negative-argument",}, >{newline, "newline",}, > @@ -166,6 +167,7 @@ static struct funmap functnames[] = { >{setfillcol, "set-fill-column",}, >{setmark, "set-mark-command",}, >{setprefix, "set-prefix-string",}, > + {piperegion, "shell-command-on-region",}, >{shrinkwind, "shrink-window",}, > #ifdef NOTAB >{space_to_tabstop, "space-to-tabstop",}, > Index: keymap.c > === > RCS file: /cvs/src/usr.bin/mg/keymap.c,v > retrieving revision 1.47 > diff -u -p -r1.47 keymap.c > --- keymap.c14 Mar 2012 13:56:35 - 1.47 > +++ keymap.c16 Mar 2012 04:59:14 - > @@ -135,7 +135,7 @@ static PF cXcar[] = { > #endif /* !NO_MACRO */ >setfillcol, /* f */ >gotoline, /* g */ > - rescan, /* h */ > + markbuffer, /* h */ >fileinsert, /* i */ >rescan, /* j */ >killbuffer_cmd, /* k */ > @@ -257,7 +257,7 @@ static PF metal[] = { >rescan, /* y */ >rescan, /* z */ >gotobop,/* { */ > - rescan, /* | */ > + piperegion, /* | */ >gotoeop /* } */ > }; > > Index: mg.1 > === > RCS file: /cvs/src/usr.bin/mg/mg.1,v > retrieving revision 1.58 > diff -u -p -r1.58 mg.1 > --- mg.19 Feb 2012 09:00:14 - 1.58 > +++ mg.116 Mar 2012 04:59:14 - > @@ -196,6 +196,8 @@ call-last-kbd-macro > set-fill-column > .It C-x g > goto-line > +.It C-x h > +mark-whole-buffer > .It C-x i > insert-file > .It C-x k > @@ -260,6 +262,8 @@ copy-region-as-kill > execute-extended-command > .It M-{ > backward-paragraph > +.It M-| > +shell-command-on-region > .It M-} > forward-paragraph > .It M-~ > @@ -572,6 +576,9 @@ Bind a key mapping in the local (topmost > Unbind a key mapping in the local (topmost) mode. > .It make-backup-files > Toggle generation of backup files. > +.It mark-whole-buffer > +Marks whole buffer as a region by putting dot at the beginning and mark > +at the end of buffer. > .It meta-key-mode > When disabled, the meta key can be used to insert extended-ascii (8-bit) > characters. > @@ -734,6 +741,8 @@ Used by auto-fill-mode. > Sets the mark in the current window to the current dot location. > .It set-prefix-string > Sets the prefix string to be used by the 'prefix-region' command. > +.It shell-command-on-region > +Provide the text in region to the shell command as input. >
Re: Pipe text from mg to external command
This version implements some off-list review comments... 1. Discard explicit checking whether command exists and it's permissions since shell already does and reports error. 2. Remove unnecessary bzero call. 3. Document minor deviation from emacs behaviour in README. Index: README === RCS file: /cvs/src/usr.bin/mg/README,v retrieving revision 1.8 diff -u -p -r1.8 README --- README 1 Aug 2011 12:15:23 - 1.8 +++ README 20 Mar 2012 17:54:12 - @@ -61,7 +61,9 @@ recognized as special cases. On systems with 16 bit integers, the kill buffer cannot exceed 32767 bytes. - +Unlike GNU Emacs, Mg's minibuffer isn't multi-line aware and hence +some commands like "shell-command-on-region" always pop up a buffer to +display output irrespective of output's size. New implementation oddities: Index: def.h === RCS file: /cvs/src/usr.bin/mg/def.h,v retrieving revision 1.118 diff -u -p -r1.118 def.h --- def.h 10 Dec 2011 14:09:48 - 1.118 +++ def.h 16 Mar 2012 04:59:14 - @@ -567,6 +567,8 @@ int prefixregion(int, int); int setprefix(int, int); int region_get_data(struct region *, char *, int); voidregion_put_data(const char *, int); +int markbuffer(int, int); +int piperegion(int, int); /* search.c X */ int forwsearch(int, int); Index: funmap.c === RCS file: /cvs/src/usr.bin/mg/funmap.c,v retrieving revision 1.36 diff -u -p -r1.36 funmap.c --- funmap.c14 Mar 2012 13:56:35 - 1.36 +++ funmap.c16 Mar 2012 04:59:14 - @@ -113,6 +113,7 @@ static struct funmap functnames[] = { {localbind, "local-set-key",}, {localunbind, "local-unset-key",}, {makebkfile, "make-backup-files",}, + {markbuffer, "mark-whole-buffer",}, {do_meta, "meta-key-mode",},/* better name, anyone? */ {negative_argument, "negative-argument",}, {newline, "newline",}, @@ -166,6 +167,7 @@ static struct funmap functnames[] = { {setfillcol, "set-fill-column",}, {setmark, "set-mark-command",}, {setprefix, "set-prefix-string",}, + {piperegion, "shell-command-on-region",}, {shrinkwind, "shrink-window",}, #ifdef NOTAB {space_to_tabstop, "space-to-tabstop",}, Index: keymap.c === RCS file: /cvs/src/usr.bin/mg/keymap.c,v retrieving revision 1.47 diff -u -p -r1.47 keymap.c --- keymap.c14 Mar 2012 13:56:35 - 1.47 +++ keymap.c16 Mar 2012 04:59:14 - @@ -135,7 +135,7 @@ static PF cXcar[] = { #endif /* !NO_MACRO */ setfillcol, /* f */ gotoline, /* g */ - rescan, /* h */ + markbuffer, /* h */ fileinsert, /* i */ rescan, /* j */ killbuffer_cmd, /* k */ @@ -257,7 +257,7 @@ static PF metal[] = { rescan, /* y */ rescan, /* z */ gotobop,/* { */ - rescan, /* | */ + piperegion, /* | */ gotoeop /* } */ }; Index: mg.1 === RCS file: /cvs/src/usr.bin/mg/mg.1,v retrieving revision 1.58 diff -u -p -r1.58 mg.1 --- mg.19 Feb 2012 09:00:14 - 1.58 +++ mg.116 Mar 2012 04:59:14 - @@ -196,6 +196,8 @@ call-last-kbd-macro set-fill-column .It C-x g goto-line +.It C-x h +mark-whole-buffer .It C-x i insert-file .It C-x k @@ -260,6 +262,8 @@ copy-region-as-kill execute-extended-command .It M-{ backward-paragraph +.It M-| +shell-command-on-region .It M-} forward-paragraph .It M-~ @@ -572,6 +576,9 @@ Bind a key mapping in the local (topmost Unbind a key mapping in the local (topmost) mode. .It make-backup-files Toggle generation of backup files. +.It mark-whole-buffer +Marks whole buffer as a region by putting dot at the beginning and mark +at the end of buffer. .It meta-key-mode When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. @@ -734,6 +741,8 @@ Used by auto-fill-mode. Sets the mark in the current window to the current dot location. .It set-prefix-string Sets the prefix string to be used by the 'prefix-region' command. +.It shell-command-on-region +Provide the text in region to the shell command as input. .It shrink-window Shrink current window by one line. The window immediately below is expanded to pick up the slack. Index: region.c === RCS file: /cvs/src/usr.bin/mg/region.c,v retrieving revision 1.29 diff -u -p -r1.29 region.c --- region.c5 Jun 2009 18:02:06 - 1.29
Re: Pipe text from mg to external command
Third attempt, and these are the changes done since the first version of this diff. 1. Check for existence of the command to be executed and also the permissions. 2. Replace popen(3) which messed stdout with socketpair(2), fork(2) and execl(2). 3. IO multiplexing using poll(2) to prevent deadlock while transferring large text to and from external command. 4. Fixed a memory leak while using strdup(3). 5. style(9) consistencies. In emacs, if the output from the command is less than 12 lines, it shows the output in minibuffer otherwise emacs pops up a *Shell Command Output* buffer and displays in it. Since mg's minibuffer isn't multi-line aware, this diff pops up *Shell Command Output* and displays output in that buffer irrespective of output's size. Comments? Index: def.h === RCS file: /cvs/src/usr.bin/mg/def.h,v retrieving revision 1.118 diff -u -p -r1.118 def.h --- def.h 10 Dec 2011 14:09:48 - 1.118 +++ def.h 16 Mar 2012 04:59:14 - @@ -567,6 +567,8 @@ int prefixregion(int, int); int setprefix(int, int); int region_get_data(struct region *, char *, int); voidregion_put_data(const char *, int); +int markbuffer(int, int); +int piperegion(int, int); /* search.c X */ int forwsearch(int, int); Index: funmap.c === RCS file: /cvs/src/usr.bin/mg/funmap.c,v retrieving revision 1.36 diff -u -p -r1.36 funmap.c --- funmap.c14 Mar 2012 13:56:35 - 1.36 +++ funmap.c16 Mar 2012 04:59:14 - @@ -113,6 +113,7 @@ static struct funmap functnames[] = { {localbind, "local-set-key",}, {localunbind, "local-unset-key",}, {makebkfile, "make-backup-files",}, + {markbuffer, "mark-whole-buffer",}, {do_meta, "meta-key-mode",},/* better name, anyone? */ {negative_argument, "negative-argument",}, {newline, "newline",}, @@ -166,6 +167,7 @@ static struct funmap functnames[] = { {setfillcol, "set-fill-column",}, {setmark, "set-mark-command",}, {setprefix, "set-prefix-string",}, + {piperegion, "shell-command-on-region",}, {shrinkwind, "shrink-window",}, #ifdef NOTAB {space_to_tabstop, "space-to-tabstop",}, Index: keymap.c === RCS file: /cvs/src/usr.bin/mg/keymap.c,v retrieving revision 1.47 diff -u -p -r1.47 keymap.c --- keymap.c14 Mar 2012 13:56:35 - 1.47 +++ keymap.c16 Mar 2012 04:59:14 - @@ -135,7 +135,7 @@ static PF cXcar[] = { #endif /* !NO_MACRO */ setfillcol, /* f */ gotoline, /* g */ - rescan, /* h */ + markbuffer, /* h */ fileinsert, /* i */ rescan, /* j */ killbuffer_cmd, /* k */ @@ -257,7 +257,7 @@ static PF metal[] = { rescan, /* y */ rescan, /* z */ gotobop,/* { */ - rescan, /* | */ + piperegion, /* | */ gotoeop /* } */ }; Index: mg.1 === RCS file: /cvs/src/usr.bin/mg/mg.1,v retrieving revision 1.58 diff -u -p -r1.58 mg.1 --- mg.19 Feb 2012 09:00:14 - 1.58 +++ mg.116 Mar 2012 04:59:14 - @@ -196,6 +196,8 @@ call-last-kbd-macro set-fill-column .It C-x g goto-line +.It C-x h +mark-whole-buffer .It C-x i insert-file .It C-x k @@ -260,6 +262,8 @@ copy-region-as-kill execute-extended-command .It M-{ backward-paragraph +.It M-| +shell-command-on-region .It M-} forward-paragraph .It M-~ @@ -572,6 +576,9 @@ Bind a key mapping in the local (topmost Unbind a key mapping in the local (topmost) mode. .It make-backup-files Toggle generation of backup files. +.It mark-whole-buffer +Marks whole buffer as a region by putting dot at the beginning and mark +at the end of buffer. .It meta-key-mode When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. @@ -734,6 +741,8 @@ Used by auto-fill-mode. Sets the mark in the current window to the current dot location. .It set-prefix-string Sets the prefix string to be used by the 'prefix-region' command. +.It shell-command-on-region +Provide the text in region to the shell command as input. .It shrink-window Shrink current window by one line. The window immediately below is expanded to pick up the slack. Index: region.c === RCS file: /cvs/src/usr.bin/mg/region.c,v retrieving revision 1.29 diff -u -p -r1.29 region.c --- region.c5 Jun 2009 18:02:06 - 1.29 +++ region.c18 Mar 2012 17:39:32 - @@ -9,9 +9,26 @@ * internal use. */ +#include +#include
Re: Pipe text from mg to external command
> This version properly captures data from external command and puts it > into *Shell Command Output* buffer. These are the new commands added > to mg with this diff... > > C-x h mark-whole-buffer > M-| shell-command-on-region > > Comments? I'll try and review this diff this weekend. Did anyone test the previous diff? -lum
Re: Pipe text from mg to external command
This version properly captures data from external command and puts it into *Shell Command Output* buffer. These are the new commands added to mg with this diff... C-x h mark-whole-buffer M-| shell-command-on-region Comments? Index: buffer.c === RCS file: /cvs/src/usr.bin/mg/buffer.c,v retrieving revision 1.77 diff -u -p -r1.77 buffer.c --- buffer.c23 Jan 2011 00:45:03 - 1.77 +++ buffer.c10 Mar 2012 12:30:19 - @@ -792,10 +792,8 @@ notmodified(int f, int n) return (TRUE); } -#ifndef NO_HELP /* - * Popbuf and set all windows to top of buffer. Currently only used by - * help functions. + * Popbuf and set all windows to top of buffer. */ int popbuftop(struct buffer *bp, int flags) @@ -814,7 +812,6 @@ popbuftop(struct buffer *bp, int flags) } return (popbuf(bp, flags) != NULL); } -#endif /* * Return the working directory for the current buffer, terminated Index: def.h === RCS file: /cvs/src/usr.bin/mg/def.h,v retrieving revision 1.118 diff -u -p -r1.118 def.h --- def.h 10 Dec 2011 14:09:48 - 1.118 +++ def.h 10 Mar 2012 12:30:19 - @@ -567,6 +567,8 @@ int prefixregion(int, int); int setprefix(int, int); int region_get_data(struct region *, char *, int); voidregion_put_data(const char *, int); +int markbuffer(int, int); +int piperegion(int, int); /* search.c X */ int forwsearch(int, int); Index: funmap.c === RCS file: /cvs/src/usr.bin/mg/funmap.c,v retrieving revision 1.35 diff -u -p -r1.35 funmap.c --- funmap.c28 Nov 2011 04:41:39 - 1.35 +++ funmap.c10 Mar 2012 12:30:19 - @@ -119,6 +119,7 @@ static struct funmap functnames[] = { {localbind, "local-set-key",}, {localunbind, "local-unset-key",}, {makebkfile, "make-backup-files",}, + {markbuffer, "mark-whole-buffer",}, {do_meta, "meta-key-mode",},/* better name, anyone? */ {negative_argument, "negative-argument",}, {newline, "newline",}, @@ -172,6 +173,7 @@ static struct funmap functnames[] = { {setfillcol, "set-fill-column",}, {setmark, "set-mark-command",}, {setprefix, "set-prefix-string",}, + {piperegion, "shell-command-on-region",}, {shrinkwind, "shrink-window",}, #ifdef NOTAB {space_to_tabstop, "space-to-tabstop",}, Index: keymap.c === RCS file: /cvs/src/usr.bin/mg/keymap.c,v retrieving revision 1.46 diff -u -p -r1.46 keymap.c --- keymap.c28 Nov 2011 04:41:39 - 1.46 +++ keymap.c10 Mar 2012 12:30:19 - @@ -137,7 +137,7 @@ static PF cXcar[] = { #endif /* !NO_MACRO */ setfillcol, /* f */ gotoline, /* g */ - rescan, /* h */ + markbuffer, /* h */ fileinsert, /* i */ rescan, /* j */ killbuffer_cmd, /* k */ @@ -259,7 +259,7 @@ static PF metal[] = { rescan, /* y */ rescan, /* z */ gotobop,/* { */ - rescan, /* | */ + piperegion, /* | */ gotoeop /* } */ }; Index: mg.1 === RCS file: /cvs/src/usr.bin/mg/mg.1,v retrieving revision 1.58 diff -u -p -r1.58 mg.1 --- mg.19 Feb 2012 09:00:14 - 1.58 +++ mg.110 Mar 2012 12:30:22 - @@ -196,6 +196,8 @@ call-last-kbd-macro set-fill-column .It C-x g goto-line +.It C-x h +mark-whole-buffer .It C-x i insert-file .It C-x k @@ -260,6 +262,8 @@ copy-region-as-kill execute-extended-command .It M-{ backward-paragraph +.It M-| +shell-command-on-region .It M-} forward-paragraph .It M-~ @@ -572,6 +576,9 @@ Bind a key mapping in the local (topmost Unbind a key mapping in the local (topmost) mode. .It make-backup-files Toggle generation of backup files. +.It mark-whole-buffer +Marks whole buffer as a region by putting dot at the beginning and mark +at the end of buffer. .It meta-key-mode When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. @@ -734,6 +741,8 @@ Used by auto-fill-mode. Sets the mark in the current window to the current dot location. .It set-prefix-string Sets the prefix string to be used by the 'prefix-region' command. +.It shell-command-on-region +Provide the text in region to the shell command as input. .It shrink-window Shrink current window by one line. The window immediately below is expanded to pick up the slack. Index: region.c === RCS file: /cvs/src/usr.bin/mg/regi
Re: Pipe text from mg to external command
I can have a look at this, though it may not be for a week or so. Testers/comments welcome... mark
Pipe text from mg to external command
This diff allows a user pipe text from current region in mg to external command. Also adds a command to mark whole buffer. Comments? Index: def.h === RCS file: /home/sunil/cvs/src/usr.bin/mg/def.h,v retrieving revision 1.118 diff -u -p -r1.118 def.h --- def.h 10 Dec 2011 14:09:48 - 1.118 +++ def.h 25 Dec 2011 19:18:58 - @@ -567,6 +567,8 @@ int prefixregion(int, int); int setprefix(int, int); int region_get_data(struct region *, char *, int); voidregion_put_data(const char *, int); +int markbuffer(int, int); +int cmdregion(int, int); /* search.c X */ int forwsearch(int, int); Index: funmap.c === RCS file: /home/sunil/cvs/src/usr.bin/mg/funmap.c,v retrieving revision 1.35 diff -u -p -r1.35 funmap.c --- funmap.c28 Nov 2011 04:41:39 - 1.35 +++ funmap.c25 Dec 2011 19:24:00 - @@ -119,6 +119,7 @@ static struct funmap functnames[] = { {localbind, "local-set-key",}, {localunbind, "local-unset-key",}, {makebkfile, "make-backup-files",}, + {markbuffer, "mark-whole-buffer",}, {do_meta, "meta-key-mode",},/* better name, anyone? */ {negative_argument, "negative-argument",}, {newline, "newline",}, @@ -172,6 +173,7 @@ static struct funmap functnames[] = { {setfillcol, "set-fill-column",}, {setmark, "set-mark-command",}, {setprefix, "set-prefix-string",}, + {cmdregion, "shell-command-on-region",}, {shrinkwind, "shrink-window",}, #ifdef NOTAB {space_to_tabstop, "space-to-tabstop",}, Index: keymap.c === RCS file: /home/sunil/cvs/src/usr.bin/mg/keymap.c,v retrieving revision 1.46 diff -u -p -r1.46 keymap.c --- keymap.c28 Nov 2011 04:41:39 - 1.46 +++ keymap.c25 Dec 2011 19:19:06 - @@ -137,7 +137,7 @@ static PF cXcar[] = { #endif /* !NO_MACRO */ setfillcol, /* f */ gotoline, /* g */ - rescan, /* h */ + markbuffer, /* h */ fileinsert, /* i */ rescan, /* j */ killbuffer_cmd, /* k */ @@ -259,7 +259,7 @@ static PF metal[] = { rescan, /* y */ rescan, /* z */ gotobop,/* { */ - rescan, /* | */ + cmdregion, /* | */ gotoeop /* } */ }; Index: mg.1 === RCS file: /home/sunil/cvs/src/usr.bin/mg/mg.1,v retrieving revision 1.57 diff -u -p -r1.57 mg.1 --- mg.128 Nov 2011 07:58:23 - 1.57 +++ mg.125 Dec 2011 19:53:20 - @@ -196,6 +196,8 @@ call-last-kbd-macro set-fill-column .It C-x g goto-line +.It C-x h +mark-whole-buffer .It C-x i insert-file .It C-x k @@ -260,6 +262,8 @@ copy-region-as-kill execute-extended-command .It M-{ backward-paragraph +.It M-| +shell-command-on-region .It M-} forward-paragraph .It M-~ @@ -572,6 +576,9 @@ Bind a key mapping in the local (topmost Unbind a key mapping in the local (topmost) mode. .It make-backup-files Toggle generation of backup files. +.It mark-whole-buffer +Marks whole buffer as a region by putting dot at the beginning and mark +at the end of buffer. .It meta-key-mode When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. @@ -734,6 +741,8 @@ Used by auto-fill-mode. Sets the mark in the current window to the current dot location. .It set-prefix-string Sets the prefix string to be used by the 'prefix-region' command. +.It shell-command-on-region +Provide the text in region to the shell command as input. .It shrink-window Shrink current window by one line. The window immediately below is expanded to pick up the slack. Index: region.c === RCS file: /home/sunil/cvs/src/usr.bin/mg/region.c,v retrieving revision 1.29 diff -u -p -r1.29 region.c --- region.c5 Jun 2009 18:02:06 - 1.29 +++ region.c25 Dec 2011 19:38:22 - @@ -9,6 +9,8 @@ * internal use. */ +#include + #include "def.h" static int getregion(struct region *); @@ -366,4 +368,66 @@ region_put_data(const char *buf, int len else linsert(1, buf[i]); } +} + +/* + * Mark whole buffer by first traversing to end-of-buffer + * and then to beginning-of-buffer. Mark, dot are implicitly + * set to eob, bob respectively during traversal. + */ +int +markbuffer(int f, int n) +{ + if (gotoeob(f,n) == FALSE) + return (FALSE); + if (gotobob(f,n) == FALSE) + return (FALSE); + return (TRUE); +} + +/* + * Pipe text