About Archive Tags RSS Feed


so you might get lucky, and you might not

7 April 2008 21:50


One thing I do a lot is select a region of text, then have it replaced with the output of a command.

The most common job is sorting a number of lines, such as "use XX:YY;" lines in perl scripts.

Finally having gotten annoyed enough about how clunky shell-command-on-region was I wrote my own lisp function:

Only after that did I discover M-x sort-lines. D'oh. Still I guess my solution is more general, and less difficult to use. (I find the use of the Emacs prefix troublesome to type; since you have to do it in advance - I almost always forget.)

I also learnt of M-x list-matching-lines yesterday. Thats a new discovery which really rocks. (I can use "^sub " to find a list of subroutines, etc.)


This could be improved, and fleshed out a lot if there were any interest.

But its neat as-is:

#  Dump packages in the NEW queue.
#  This could be improved, perhaps:
#  --show-names --show-dates, etc.  Or just show all info in a table.
wget --quiet -O-  http://ftp-master.debian.org/new.html | \
 perl -ne 'print $1 . "\n" if ( $_ =~ /^<td valign="top" class="sid">([^<]+)<\/td>$/ )'

I thought there was something similar in the devscripts package, or contained within debian-goodies but apparently not.

ObQuote:Battle Royale



Comments on this entry

icon Daniel Burrows at 14:19 on 7 April 2008

Check out the documentation for the "interactive" form; it lets you tell Emacs how to prompt for arguments if you don't give them as a prefix:

(defun foo (str) "Insert the given string"
  (interactive "sEnter the string to insert: ")
  (insert str))
icon Steve at 14:26 on 7 April 2008

Thanks for the tip, I'll update my code shortly.

In the past I've written several complete Emacs packages, but its been many years since I did so, and I forget an awful lot. Took me almost an hour to write that piece of code :(