Ads by Google

Sunday, August 30, 2009

A Lisp book incident

The herd effect in programming is very powerful.  Whatever is the programming flavour this year, that's where the crowd is going to be.  Lots of Java, C#, VB etc.   If you ever wondered on the uptake of Lisp and its ilk....

A few years ago, I happened on a copy of Winston Horn's Lisp book in a book store.   The book seemed untouched, was dusty and was jammed in one corner of a bookshelf.  When I wanted to buy it, the owner seemed happy to get rid of it.  He even gave me a good discount over the list price saying "That's the last copy I have and you're the first person in years to buy this book"

hmmm....

Lugging it around my workplace, a few weeks later, I misplaced it.  Searching all over the usual places, I couldn't locate it.  Resigned to the fact that I lost the book within a few weeks of purchase, I made a half hearted call to security, whether someone returned the book there.

To my delight, he said, that the book was found by one of the security personnel in the cafeteria and I could come and collect it.

When I went to get it, the head of security said "What is this Lisp?  I've not heard of it.  If this had been a Java, C# or ASP book, you'd not have got the book back. It would have been taken by someone."

Guess that's the bright side of getting your book back. OTOH, Lisp popularity....

Sunday, August 23, 2009

WoMan: An Emacs interface to read man pages

If you've worked with terminals and launched man in it, it's a bit weird to suddenly use vi commands to navigate the man pages.  And it really is a problem to navigate on older *nixes with the way the screen moves or refreshes itself. Well, Emacs has a really good interface to read manpages call WoMan (Without Man).  Nicely formatted, easier navigation and ability to jump from section to section is among the features I like in it.

It can be launched as M-x woman and will prompt for a command you want the manpage on.  Now, if you have cygwin installed, it should work without a hitch, otherwise you might have to customise woman-manpath and woman-path to point to where the manpages lie.  Reading the variable documentation on both using C-h v , which should tell you how to set it.

Note that, it launches a new frame (Window in Microsoft terminology) to display the manpage and would probably be in a different font.  You can close the frame by pressing C-x 5 0.


Saturday, August 15, 2009

Getting DocView to work on Windows Emacs

Emacs 23 has a new document viewer called docview.  From the manual

is a viewer for DVI, Postscript (PS),and PDF documents.  It provides features such as slicing, zooming, and searching inside documents.  It works by converting the document to a set of images using the `gs' (GhostScript) command, and displaying those images.

To get it to work on Windows, you'd at least need to have a working LaTeX system like MiKTeX.  And also have ghostscript installed.  Now, if you read the Docview info, this is all you need to get it work but on Windows you need to jump through additional hoops to view it.

As a first step, M-x getenv RET PATH should show something like this.

C:\MiKTeX2.7\miktex\bin;C:\cygwin\bin;C:\cygwin\usr\bin;C:\gnu\bin\;....

Next configure all doc-view-*-program to point to the correct binaries.
Upto this point, docview will work to convert the DVI or PDF file to a PNG file.  In order to view the files, you need to have Emacs with Image support.  On Windows, the following DLLs are required to make it work.
glut32.dll
jpeg62.dll
libimage.dll
libpng12.dll
libpng13.dll
libpng3.dll
librle3.dll
libtiff3.dll
zlib1.dll
which can be had from downloading the following from the gnuwin32 site.
libpng-1.2.37-bin.zip
libpng-1.2.37-dep.zip
tiff-3.8.2-1-bin.zip
jpeg-6b-4-bin.zip                        
tiff-3.8.2-1-dep.zip
jpeg-6b-4-dep.zip                        
Note that the actual version numbers may differ.  Just take only the DLLs and dump them in the Emacs bin directory. Or you could put them somewhere in the search path, so that you don't have to do this step every time a new Emacs version is released.

Docview should now work without a hitch.  The added bonus is that other image formats can also be viewed within Emacs with all the other DLLs plugged in, in Image mode.

In my set up, docview program variables point to a mix of MiKTeX and Cygwin binaries and that has not created any issues so far.

Thursday, August 13, 2009

Sending Emails from the commandline Part 2

Previously I had posted about my challenges in getting attachments sent and being seen reliably as one in most MUAs. Spending a few more days pottering around and testing, I finally settled on mpack. Using mutt, I could not get it to work consistently in an cygwin environment as it kept dumping core.

I downloaded mpack, ran make and then installed it. Based on the manpage and a few examples on the web, I rejigged my shell script use mpack to generate a MIME encoded mail message, wrapped with msmtp needed headers and mailed it out. Works flawlessly.

So far.

The code snippet below is the way I used it.
function send_it () {
/usr/sbin/msmtp -t < $1
echo "mail send status" $?
if [ $? -ne 0 ]; then
echo "Fail: $1 file not deleted"
else
echo "Success: Removing $1 file"
rm $1
fi
}

function mpack_it () {
# outmimefile, zip file name, tmpfile split_part
mpack -s "Generated Output $4 : `date` " -o $1 $2
#change inline to attachment, insert msmtp needed headers and delete message-ID
sed 's/inline/attachment/' $1 | sed "/^Subject:/i\
To: \nFrom: xxxxxx@gmail.com \nBcc: $LIST"|sed '1,1d' > $3

}


The attachment itself is base64 encoded.

This solution, I'm reasonably satisfied with, though I'm pretty sure when I try an all Win32 solution, it might flame out spectacularly.

Sunday, August 9, 2009

RefTeX 4.34 released

Just got an email stating that a new version of RefTeX has been released.  You may want to upgrade depending on your needs.


Saturday, August 8, 2009

Sending attachments from the command line

I spent about 2 hours trying to get this sorted out but I'm pretty much unsatisfied with  the results.

I want to send emails with largish attachments from a script.  And I use msmtp as my MTA.  After reading up things and trail and error, this works for me.

$( cat ./mail.txt; uuencode output.zip output.zip) | /usr/sbin/msmtp -d -t

where  mail.txt has the From,To,Subject and body text and the .msmtprc file has the mailserver userid and password details to connect to the smtp server.  Since I use the cygwin based msmtp, as a script this sends out emails as desired.

The problem is that, the file is not recognised as an attachment in some mail clients and sometimes the encoded file is inline in the body of the text.  On Lotus Notes of my colleague, it appears an attachment in the mail body but he sees no attachment icon to identify it in the folder.  In Gmail  Sent Mail folder, the attachment is completely inline in the mail body and that is significantly going to slow opening those mails in the browser.

Reading up a bit more, I sort of figured, that the attachment needs to be MIME encoded for the attachment to reliably seen as attachments in most MUAs.

Asking around with the author of msmtp, it turns out MIME support is more of MUA thing rather than the MTA.  He suggested using mutt or any other MUA to accomplish the same.  So I have

mutt -s "$SUBJ" -a A_N_scrips.zip  -b "$LIST" < $TMPFILE
where LIST is the list of email addresses and TMPFILE is the message body.  This works except that on large attachments, mutt seems to dump core.  I worked around that by splitting the attachments and sending it in 2 different emails.  Not good but enough to send the files across.  Of course, you need an .muttrc file to be configured to use msmtp to send the mail.

But I think, using an MUA to send a MIME encoded file is a bit much.

Are there any other methods to do it?  Without using Perl?

Wednesday, August 5, 2009

Maximising your screen real estate

If you're a bit like me in that you rarely use the tool bar and menu bar in Emacs, it might be a good idea to turn it off to get some additional lines in your buffer. While it may be strange to look at initially, you soon get used to it as you rarely ever need it.

Add the following to your .emacs
(tool-bar-mode nil)
(menu-bar-mode nil)
And in the rare case you want those back, you can invoke it by M-x tool-bar-mode or M-x menu-bar-mode to get them back.


Saturday, August 1, 2009

Emacs 23.1, Gnus and msmtp

After I upgraded my Emacs to the latest version on Windows, I found that my mail sending was not working anymore. And I use msmtp on cygwin to send emails instead of sendmail by subbing the sendmail binary with msmtp.

;;;;dont set this if you use msmtp!!!
;; (setq message-send-mail-function 'smtpmail-send-it)
(setq sendmail-program "/usr/sbin/msmtp")


This has been working for ages without any issues and I had not made any changes to my .gnus file. Baffling.

What's more, the *Messages* buffer kept saying 'Starting Firefox...'

So, I checked whether msmtp was sending emails through the command line. Check. works fine.

Inspected my .gnus file to see whether the paths were pointing to Emacs 22.2 version. Check. Nothing.

There I was, staring at the .gnus buffer wondering what to do next. Maybe debug this? I set
(setq gnus-verbose 9)
(setq gnus-verbose-backends 9)

and try sending again. Nothing in the *Messages* buffer.

I stare some more at .gnus buffer.
;;;;dont set this if you use msmtp!!!
;; (setq message-send-mail-function 'smtpmail-send-it)
;; (setq smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil)))

hmmm...dimly I sort of make out message sending is not working. Maybe I better check out the documentation and see what it says.
I hit C-h v on message-send-mail-function and I see

Valid values include `message-send-mail-with-sendmail'
`message-send-mail-with-mh', `message-send-mail-with-qmail',
`message-smtpmail-send-it', `smtpmail-send-it',
`feedmail-send-it' and `message-send-mail-with-mailclient'. The
default is system dependent and determined by the function
`message-send-mail-function'.
See also `send-mail-function'.


I get into the Emacs manual and search for 'send-mail-function'. And I find this

The variable `send-mail-function' controls how the default mail user
agent sends mail. It should be set to a function. In most cases, the
default is `sendmail-send-it', which delivers mail using the Sendmail
installation on the local host. On Mac OS X and MS-Windows, however,
the default is normally `mailclient-send-it', which passes the mail
buffer on to the system's designated mail client (see `mailclient.el').
To send mail through an SMTP server, set `send-mail-function' to
`smtpmail-send-it' and set up the Emacs SMTP library (*note Emacs SMTP
Library: (smtpmail)Top.).

So, that's why it was invoking Firefox! The OS was thinking Firefox was the associated default mail client and Emacs was simply calling that.

So message-send-mail-function was calling message-send-mail-with-mailclient instead of message-send-mail-with-sendmail.

I set
(setq message-send-mail-function 'message-send-mail-with-sendmail)

and now everything is back to normal. Now, if you noticed the Emacs manual talks only about send-mail-function and not message-send-mail-function. But since Gnus uses message.el, it was easy for me to find the correct switches.