Ads by Google

Tuesday, April 29, 2008

Sunday, April 27, 2008

Binding Keys in Emacs

In Emacs, the keys can be rebound to call any function one desires.One of the many uses of rebinding is to call frequent functions that are operated on the buffer one is working on. And the key bindings can be local or global depending upon whether the functionality makes sense across all buffers or only to the type of buffers worked on (text, tex etc.)

Here for example is what I have mapped for TeX mode. I have outline-mode enabled by default for LaTeX files.
(add-hook 'LaTeX-mode-hook
(function (lambda ()
(setq fill-column 68)
(auto-fill-mode t)
(flyspell-mode 1)
(TeX-PDF-mode 1) ;;turn on PDF mode.
(outline-minor-mode t)
(ruler-mode t)
(local-set-key "\C-cf" 'beamer-template-frame)
(setq ispell-extra-args '("--mode=tex"))
(paren-toggle-matching-quoted-paren 1)
(paren-toggle-matching-paired-delimiter 1))))
Now, this puts an outline-mode menu on the menu-bar whose keybindings
are atrocious! :-)

Now in outline-mode, the most frequently used functions are

Show All
Show Entry
Hide Body
Hide Entry

at least by me.

Now, I'd like to map the keys as follows

Hide Body F7

Show All S-F7 shift F7
Hide Entry F8

Show Entry S-F8 shift F8

Next, open a LaTeX file and enable outline-mode, if it has not been done so. Then, M-x local-set-key RET f7 hide-body. Test it by hitting F7. If it works, then do C-x ESC ESC, you should see the following form in the minibuffer. Copy it to the scratch buffer. Repeat the above M-x local-set-key with S-F7 to bind it to show-all and copy the form to the scratch buffer.

You should have something like this in your scratch buffer.
(local-set-key (quote [f7]) (quote hide-body))
(local-set-key (quote [S-f7]) (quote show-all))
Repeat the above actions for hide-entry and show-entry to use F8. Of course you can bind it to any other key than the suggested F7 & F8 function keys. If you're happy with it, you could add it to the LaTeX-mode-hook function after the outline-mode is enabled.

Note that the idea of C-x ESC ESC ( repeat-complex-command) to get the key bindings is got from here. As the post suggests, it's far easier to let Emacs generate the correct key binding forms instead of doing it by hand.

And it might be a good idea to associate some logic to the key bindings. I use the key and shift key to toggle between two opposite actions. At least that sounds logical to me.

Friday, April 25, 2008

Proved Right!

Back then, I speculated that the reason Sun bought out MySQL was probably due to its spat with Oracle over pricing multicore chips.

Well, this story sort of confirms that.

Pricing on a processor based system is now more complex with cores more than 1. and it's going to sock the first guy with more cores per chip, from their trusted partners.

Wednesday, April 23, 2008

What did they have in mind....

when a variable called track-eol is created which you can set as

(setq track-eol t) ?
Apparently if you set this to a non-nil value and if you're at the end of a line, C-n and C-p will track up or down to the end of the line you just moved to.

I've enabled it in the past and I can't say I found it tremendously useful and wondering if anyone has ever seen some good use for it. It's mentioned in the manual. Drop me a line if you ever think of a good use for it. I have a nebulous thought it might be useful for fixed width data files?

*shrug*

Copy it to the scratch buffer, eval it and open a few text files and see whether you like it all.

Monday, April 21, 2008

Increase your productivity with Minor Modes

One of the features that increases your productivity are the minor modes that can be enabled to help your work. Abbreviation mode, Foot note mode, flyspell mode are some of the minor modes that allow you to correct typos, add footnotes and do spell check.

In addition there are lots of other minor modes have been added to the main branch of Emacs that can complement the existing ones.

Like Table, that allows you to create ASCII tables to align text and also create spiffy text based tables. It also provides a LaTeX export function that helps in creating a LaTeX table. Frankly, I've been using the table-insert function to create all my LaTeX tables. Saves me the repetitive edit-view-correct cycle by a huge margin.

Another simple one is ruler-mode that puts a ruler on top of the text area. If you do a M-x find-file RET ruler-mode, the commentary will explain what are the features you can use enabling the minor mode. Tremendously useful when working with fixed width data; slightly better than following the mode line for the column position, I dare say.

And one other under appreciated mode for newbies and intermediate Emacs users is outline-mode. Found in org-mode and one that can be set in LaTeX mode (with AucTeX), the showing and hiding of the sections allows one to navigate large documents quite easily. Instead of scrolling up and down the document, it's easier to fold the arbitrary sections to focus on the section at hand.

Saturday, April 19, 2008

The closest to text intellisense in Emacs

Emacs users know that M-/ is used to the expand the text at point for possible completions. One good thing is that it searches all the buffers for possible completions. While this is not the same as programming language intellisense stuff you find in programming editors from Microsoft, Sun and Eclipse, it's still a better choice than a language specific offering.

Why? Because it gives the same consistent behaviour in whatever buffer you're in. You can be sure that if you had typed it before, it can be plugged into the current buffer in whatever mode it is in with a minimal of keystrokes. This is in contrast to other specialised editors which can offer the feature for Java, C or C++, say.

OK, the choice of M-/ is not exactly great for those who are not good typists.

But this is Emacs; there is a way to use TAB as the more natural keystroke to expand the text at point. Plugging in the code given at this link will make text expansion or completion a lot more natural. Having done that, I've pretty much stopped using M-/ for text expansion.

One other way to do text completion is to use Predictive mode which learns from your typing style; Having used it before, I could see the benefits but I ran into some resource usage errors with the dictionary and hence stopped using it.

I'd encourage people to try predictive mode if only to see the possibilities that might arise for you. A typing session that is customised to the way you write. It might be very useful for people who are in some specialised fields with limited but large words usage.

Thursday, April 17, 2008

LaTeX tip: Always use small fonts for Verbatim environment

On the TeX newsgroup, this was a nice tip to use. Indented code tends to move off the paper with normal fonts and the only way was to wrap the verbatim environment under \small.

But you'd have to do that for every verbatim listing.

Making the change in the document preamble makes the code listing simple.

For those interested in more sophisticated LaTeX pretty printing, the listings package is pretty good and comes with support for a number of languages. For anything fancier than the normal verbatim environment, that is a very good package to use.

Tuesday, April 15, 2008

Cleaning up or Deleting LaTeX intermediate files using AucTeX

Anyone using LaTeX knows that there are a number of intermediate files that are generated in the course of compiling the document. After the final file is generated, there is no need to keep those files around. But one has to delete them manually or plug the extensions in a shell script to delete them.

Fortunately AucTeX provides a simple interface to clean the files. Hitting C-c C-c and typing 'Clean' or 'Clean All' deletes the intermediate files associated with the current .tex in the buffer.

That's right, it ONLY deletes the intermediate files with respect to the current buffer where C-c C-c is called.

The difference between 'Clean' and 'Clean All' is that, in the latter case, the output files are also deleted. And the files can also be deleted by calling M-x TeX-clean.

So, what intermediate files are deleted? Depending on the type of file being edited, it varies. For example, for LaTeX files, it's

LaTeX-clean-intermediate-suffixes is a variable defined in `latex.el'.
Its value is ("\\.aux" "\\.bbl" "\\.blg" "\\.brf" "\\.fot" "\\.glo"
"\\.gls" "\\.idx" "\\.ilg" "\\.ind" "\\.lof" "\\.log" "\\.lot"
"\\.nav" "\\.out" "\\.snm" "\\.toc" "\\.url")


To know the exact way things can be customised, see the AucTeX manual, especially Cleaning.

Monday, April 14, 2008

In my previous post, I outlined how to get Auctex to launch Acrobat Reader. Here's a minor change based on the same poster's advice. If the reader is the default application to view pdf files in Windows, you don't even need the acrord32 in the configuration. Just


TeX-output-view-style is a variable defined in `tex.el'.
Its value is
(("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "dvips %d -o && start \"\" %f")
("^dvi$" "." "yap -1 %dS %d")
("^pdf$" "." "cygstart %o")
("^html?$" "." "start \"\" %o"))

is enough.

Sunday, April 13, 2008

Making AucTeX launch the Windows Acrobat Reader

When I compile documents using AucTeX, I used to manually open and close the generated pdf by navigating to the file location and opening the file using Windows based Acrobat reader.

The Reader locks the file when in use, so if you recompile the document when the pdf is still open by the Reader, you'd get the "can't write to output file" error.

One workaround I used was, the cygwin based xpdf viewer which doesn't lock the file. But you'd have to refresh the file every time something changed, by hitting 'r' in the xpdf application.

The problem with the default AucTeX install was that it had the start "" %o as the entry for View which didn't do anything. Even though I don't use that feature, I thought, let's get this to point to Acrobat Reader and save it.

Turned out, you need to customise TeX-output-view-style. Setting it to


start "acrord32" %o
acrord32 %o


didn't work. Finally, one poster on the AucTeX mailing list give the answer which made it self evident. Since I was using cygwin, he suggested I use cygstart instead of start.

That worked like a charm and now my TeX-output-view-style looks like

Its value is
(("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "dvips %d -o && start \"\" %f")
("^dvi$" "." "yap -1 %dS %d")
("^pdf$" "." "cygstart acrord32 %o")
("^html?$" "." "start \"\" %o"))

Friday, April 11, 2008

Gnus v5.10.10 is released

Just saw this in the Gmane newsgroup. A new version of Gnus has been released. Those using imap would be happy to know that the unread count should be coming out correctly now. At least that's what the Release notes claim. :-)

And the drafts editing has been changed to the more logical 'e', I see.

And there are a whole bunch of other changes. Since I've been tracking the CVS version, I've been thinking that these features were already a part of the bundled Gnus version.

That's the problem with bleeding edge; you think some feature is so obvious and when people ask about a certain feature, you keep wondering why they are not using the obvious menu option.

Why I use Gnus: Reason #1

For the sheer language and wisecracks in the manual. For example

Gnus gives you all the opportunity you could possibly want for shooting yourself in the foot. Let's say you create a group that will contain all the mail you get from your boss. And then you
accidentally unsubscribe from the group. Gnus will still put all the mail from your boss in the unsubscribed group, and so, when your boss mails you "Have that report ready by Monday or you're fired!", you'll never see it and, come Tuesday, you'll still believe that you're gainfully employed while you really should be out collecting empty bottles to save up for next month's rent money.

With entries like that in the manual, even if you don't understand anything in it the first time around, you'll come back for more.

But then I'm one of those weirdos who can happily spend hours reading the manual, sometimes.

Thursday, April 10, 2008

Shell scripting gotchas: value too great for base (error token is "09")

Staring at the screen doesn't help.

Rerunning the code another 5 times doesn't help either.

It's still the same error. And it had been working so well for so many days. The code in question

if [[ $SDAY -eq $EDAY && $SMON -eq $EMON && $SYEAR -eq $EYEAR ]]; then
echo "Data is current for $value_set"
break
fi

You know you're good at shell scripting when you start making elementary mistakes and enter brain freeze territory frequently. I mean, your code can't just stop like that, can it?

And slowly you wrack your brains to see what you should be looking at.

Finally you read the error message and figure out that this is something to do with the base system.

You google and smack your head and realise, the dates were being read as octal and like clockwork it fails on 09th of April. You start to think of all the code to strip leading 0s and suitably chastened you stick to a simpler version which goes like

if [[ "$EYEAR$EMON$EDAY" -eq "$SYEAR$SMON$SDAY" ]]; then
echo "No deltas to be captured"
break
fi

The dates have to match, so it doesn't matter if it is a string or number.

Overconfidence, the bane of a programmer.

Wednesday, April 9, 2008

Where did my read mails go when using Gnus?

This seems to be a standard question for new Gnus users(ummm....yeah, it was for me too when I started). And this is sort of answered in the FAQ too.

Because Gnus treats email too as a form of net news some of the defaults may not be acceptable to people who use Gnus as a mail reader. If you look at the FAQ entry, the suggestion would appear ridiculous that you press a key combination just to see all the messages in a mail group.

A more simpler method (is anything ever simple with Gnus?) is to change the Group Parameters of the group to make it the default behaviour that all mail messages are seen.

In the Group Buffer, against the mail group, hit G P and you'd be presented with a buffer where you need to enter the following elisp form. Delete the nil shown in the buffer and enter


((display . all))


hit C-c C-c

and you're done. Enter the mail group and you should be able to see all the mail messages whether read or unread. Another minor convenience you may like to have is to set it like this.

((visible . t)
(display . all))


which causes the mail group to be visible even if there are no new messages to read. Though for a text based news reader, it will be apparent that this is not exactly convenient as you'd be spending time moving the arrow keys to navigate over mail groups with no new messages.

Rather it's easier to let Gnus tell you that there are unread messages. Unless of course, you spend time rooting through your old mails.

The whole section on reading mails is also quite instructive for other conveniences that you wish you had. At least, this question, is a real time saver and makes things easier on the eyes.

W w is your friend.

Monday, April 7, 2008

Have you checked the Emacs NEWS file?

When you download and install the latest Emacs release, always check the release notes by checking the NEWS file. This can be pulled up by hitting C-h n in any Emacs buffer.

The NEWS file contains all the changes incorporated in the current release and has all the feature list implemented in the major release number. So NEWS.21 will have all the information about 21.x releases and NEWS.20 about the 20.x and so on.

Why should you check the NEWS file?

Well, you really don't as most Emacs features will probably work the way you expect them to work. When you upgrade and some feature breaks(very rare), the first thing is to check the NEWS to see whether the defaults have been changed.

As was my case in

** The HOME directory defaults to Application Data under the user profile.

If you used a previous version of Emacs without setting the HOME
environment variable and a `.emacs' was saved, then Emacs will continue
using C:/ as the default HOME. But if you are installing Emacs afresh,
the default location will be the "Application Data" (or similar
localized name) subdirectory of your user profile. A typical location
of this directory is "C:\Documents and Settings\USERNAME\Application Data",
where USERNAME is your user name.

This change means that users can now have their own `.emacs' files on
shared computers, and the default HOME directory is less likely to be
read-only on computers that are administered by someone else.
When I copied my installation over without my .Emacs into a new machine, it was irritating to see it look under the above "Application Data" folder. A quick look at the NEWS file, sorted that out.

Then again, another feature which I think should not have been implemented(I think it encourages bad practices with OSes which are not well designed to work with file names with spaces)
** When Emacs prompts for file names, SPC no longer completes the file name.
This is so filenames with embedded spaces could be input without the
need to quote the space with a C-q. The underlying changes in the
keymaps that are active in the minibuffer are described below under
"New keymaps for typing file names".

If you want the old behavior back, add these two key bindings to your
~/.emacs init file:

(define-key minibuffer-local-filename-completion-map
" " 'minibuffer-complete-word)
(define-key minibuffer-local-must-match-filename-map
" " 'minibuffer-complete-word)
The NEWS also has new features that have been implemented, bugs that have been fixed, popular lisp packages which have been folded into the main tree and deprecated support for various platforms.

Make sure you READ the NEWS file before reporting any bug too.

Sunday, April 6, 2008

The coming Open Source Database wars

Well, it's the commercial vendors who will be duking it, rather. With the recent Sun acquisition of MySQL and IBM throwing some dough to PostresSQL, (Enterprise DB to be pedantic), things are getting interesting.

I think it has less to do with database feature sets and more to do with pricing. If I understand something about database licensing, it's done mostly on a per CPU basis or number of cores.

Pricing will determine what kind of technology adoption will happen on multicore chips. While increased performance may be got by putting 4,8 or more cores on the chip, the pricing done on a per core basis will undo all the technical advantages.

If two vendors have the same number of chips on similar systems but one has more cores than the other per chip and the pricing for the Oracle database is done on a per core basis.....you can see where this is heading.

Disaster, for all the technical progress made.

I think that's why SUN bought out MySQL; From Oracle's point of view, putting more cores on a single chip means less revenue as less chips/system does more now. The only way it can make money is to switch to a core based licensing revenue stream. That would mean, SUN's systems would come out costlier compared to a similar CPU based system from IBM, say.

SUN and Oracle has been close for years and the sudden acquisition must mean that the low end SMB market is going to get poached from Oracle.

Soon, expect new TPC benchmarks from SUN using MySQL as the database.

Then the message would be loud and clear to Oracle. As a matter of prediction, Oracle would cozy up to IBM and optimise things for their Power chips I guess.

Update: see this link for more confirmation.

Friday, April 4, 2008

Now, the EC gets interested in OOXML!

Actually no. Given the initial intent and final vote of the OOXML, the EC is now planning to look into the voting process itself.

A little too late now; a bit like the cops in the movies.

Even with all the clamouring, it'll take years for any allegations to be proved or falsified. By that time, OOXML would have become mainstream thus making it all moot.

Rather, the standard should be on indefinite hold till a consensus is reached by all concerned that Microsoft got the votes fair and square.

Who's going to complain about this?

Microsoft? Actually, they'd benefit as they have nothing to hide, wouldn't they?

The Open Source crowd? It's not a standard yet, till the allegations are proved either way, so they might have to wait a couple of years before they have a technical locus standi in this discussion.

That about settles it then?

*wink

All this will be apparent to those who've the "Yes Minister" series where the Minister and the Civil Services folks clash over policy.

Thursday, April 3, 2008

Reading Digest mails with Gnus

One of the reasons why I use Gnus, is the ability to read mailing lists in digest form very easily.

Lots of mailing lists have the option of sending digests of all the mails sent that day, in a couple of mails (say usually under 64K) per day. This is better than having your mailbox inundated with hundreds of emails from the list. And delays the latest Virus/Bot attack too. :)

A digest mail is no different from another email, so most email clients treat it as another article or mail message. But if you open it, it's quite unappealing to read it. One huge text file, with mails separated by a newline. You'd have to scroll up to the TOC (generated from the Subject lines) to get the context and follows up in order to read. Especially on interesting mail threads, it's very irritating.

And to repeat it's all text. Imagine trying to read 64K chunks of plain text. I get around 8 in day on the sas-l list.

This is where Gnus shines. If you open the mail, Gnus opens it normally. Then hit C-d, Tada!

it's now splits the digest as individual mails showing each email by date and author. Just like you'd see any normal mail. And to boot, if you hit C-M-t, it threads the same digest to the extent possible(I mean, some mail threads can span digests, can't it?)

Hitting C-d is the only extra work involved.

This feature alone is the biggest time saver in terms of reading mailing lists for me. A quick glance at the threaded subjects of the digest and I'm ready to either read a few or simply exit the temporary buffer created.

Gnus is awesome in this regard.

Wednesday, April 2, 2008

The Impression I create with Gnus!

Sometimes I forget that Emacs is not a mainstream editor in India. And lots of folks haven't even heard of it.

Since I use Emacs for almost everything and the most common application I'm in, is Gnus, I get a lot of curious enquiries. Some are easy to divine while others are slightly weird where it's like there is a pregnant silence and you both wish the conversation had not started.

Is that a DOS application?
is the most common question. That is sort of OK, as I have white on black emacs screen and it probably is easy to mistake Emacs for a DOS application when glancing quickly(hah!)

Those who examine it a little more closely ask more questions. Earlier I used to say "Gnus", now I say my "mail client" and quickly add that I prefer plain text. The question which is asked

What is that?


At this point, UNIX guys nod their heads, Windows guys/Managers smile and others simply think I'm kooky.

Why?


Oh, I prefer the keyboard to the mouse, I say. It's easier to do this, that and that (vigorous hand waving by me) and getting a little animated.

You don't use insert mail app here?
No, you see it's a part of Emacs and Emacs is..... (even more excited and fast speech)

Why?

See, you can do PCVS, mail, Usenet.... (swivels around to Laptop and runs through a couple of keychords)

At this point, the newbies listen on, others look at their watch, while even more others mutter some excuse, and some say "nice" and wander on.

The hapless noob is well and truly in my clutches. :-)

You know vi, I ask?

Just started learning it, he replies.

Well, don't learn it, learn Emacs, I earnestly prod him.

Is it easy?
It takes about 6 months and after that it's easy I say. Faces fall; see, you'll have to unlearn CUA and relearn the Emacs way, terminology usage and all.

Is it Free?

Of course, I'll give my copy of it, I say.

Which is the last I hear from him.

I think I'm doing a terrible disservice to the FSF GNU Emacs hackers. World domination will have to wait.

Making CD images and ISOs on Windows

Thanks to cygwin, there is now a way to create isos and CD images on windows. You don't need to get those commercial software to create those images.

This list of software is what you'd need to work with to create, query and extract info from iso files.

Fortress 1.0 released

Saw this on gmane ; rekindled my memories on what this was all about. I remember the name Guy Steele and was thinking that this could turn out to be interesting language on High Performance Computing.

Check out the source page and as an emacs user, you'd be glad to know that there is also an emacs mode for it.

Will be downloading it and trying it out.

Tuesday, April 1, 2008

OOXML and Microsoft: Getting the votes

Looks like a lot of "negotiations" have changed the outcome of the OOXML standards vote. OOXML is probably going to be voted as an ISO standard. Appears that I spoke too soon.

The next logical thing is get funding for another truly open document standard.

As Andrew Tannenbaum says, the good thing about standards is that there are so many to choose from!

If the open source waters are being muddied, muddy it a little more and move to the new standard. However long it takes. A document is one of the fundamental blocks of business transactions in an electronic world. Making it unreadable at some future date due to legal and technical reasons is clearly not in anyone's interest.

Royalty free, non discriminatory and under a standards body NOT controlled by any entity is what the target should be.