If I understand you properly, you're asking how to automate calling a command with a specific set of arguments. To do this, first take a look at the command in question:
C-h f shell-command-on-region:
shell-command-on-region is an interactive compiled Lisp function in
It is bound to M-|, .
(shell-command-on-region START END COMMAND &optional OUTPUT-BUFFER REPLACE
ERROR-BUFFER DISPLAY-ERROR-BUFFER REGION-NONCONTIGUOUS-P)
This gives us the outline of the command we want to call. The part I've trimmed at the end explains the arguments in detail.
The command you actually want to call is:
(shell-command-on-region <beginning-of-region> <end-of-region> "uniq -c" nil t)
We need to replace the bits in
<...> with actual elisp. The
apropos command can help here:
M-x apropos region beginning:
Function: Return the integer value of point or mark, whichever is
That's handy. The same thing works for
region end, although there are a few more things to work through.
That gets us the following:
(shell-command-on-region (region-beginning) (region-end) "uniq -c" nil t)
Now all we need to do is wrap that in an interactive function, aka a
command, that we can call:
(defun uniqc ()
(region-end) "uniq -c" nil t))
Now we can test that out. Paste it in your scratch buffer, but the cursor after the end of the defun, and type
C-j. Then set a region, and call
M-x uniqc. Voila! It does what we want.
You can save that code directly in your .emacs, and then you'll have
uniqc available everytime you start emacs. You can also bind it to a key if you want a shortcut; there are lots of questions here about keybindings.
Finally, there's a convenience for getting the region beginning and end that can make our function a little neater:
(defun uniqc (BEG END)
(shell-command-on-region BEG END "uniq -c" nil t))
See the elisp manual for a full explanation of how to use the