Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, July 22, 2011

Add a menu item to emacs

I convinced my girlfriend to start using emacs for her HTML/CSS/PHP needs a while ago. I thought it would be a nice learning experience both on how someone who doesn't particularly like to get to know the programs she works with and on how to change it to suit her needs.
Even though she's not using it as much as I'd like yet, she has been using it and things have come up.

For starters, she didn't like the default keybindings,
C-x C-f to save
C-w to cut, M-w to copy and C-y to paste
So the first thing I looked up was enabling cua-mode. This already helped her a lot.

Now, she likes to be able to view both her HTML and CSS file at the same time, so very easy, C-x 3 to split the windows side-by-side. As before, though, she doesn't like the key binding. So I looked into how menu items are added in emacs and here is an example of how it's done:
(define-key-after
  global-map
  [menu-bar file splith]
  '("Split Window Horizontally" . split-window-horizontally)
  'split-window)
I was able to write this, thanks to the help of this page. I've come across Xah Lee's website before and it has always been of great help as it has been this time.

This particular piece of code tells emacs to add a Split Window Horizontally menu item, which should execute the function split-window-horizontally, to the File menu, right after the split-window menu item.
I found out the names of these items by using C-h k and then selecting File->Split Window, which shows to which keys this item is bound, and in this case that was <menu-bar> <file> <split-window>, which was all I needed to figure it out.

Since I have (menu-bar-mode -1) in my .emacs, I'd never have tried this if it wasn't for my girlfriend needing it, so it is a great learning exprience.

Tuesday, June 21, 2011

IE6 JavaScript fragility

I've always considered myself lucky to have very little to do with IE6. This is partly because I'm not a web designer and partly because so far I've worked on projects that either have a great deal of control over which browser is used, or ones that didn't care about IE6.

Now though, I'm working for this company, and a lot of our employees work for other companies as well, and they often don't have any other choice than IE6. So now I need to start minding it.
So far I've only really had to deal with parts of the application that people at our office use, and they all use Chrome there, so I've had an easy ride. Now though I'm entrenched in a part that employees have to use as well and immediately things go wrong.

I was unaware that IE6's JavaScript parser is so picky that it doesn't allow left-over commas in arrays.
So this is ok:
$(".datepicker").datepicker({
  showOn:          "both",
  buttonImage:     "images/calendar.png",
  buttonImageOnly: true,
  changeMonth:     true,
  changeYear:      true,
  yearRange:       '1900:+20'
});
But this:
$(".datepicker").datepicker({
  showOn:          "both",
  buttonImage:     "images/calendar.png",
  buttonImageOnly: true,
  changeMonth:     true,
  changeYear:      true,
  yearRange:       '1900:+20',
});
Doesn't actually seem to generate an error in IE6, but it apparently prevents the function from executing, so I only know something's up, because in this case the date pickers didn't show up.

It's not really a big deal, but keeping comma's at the end is nicer when working with diffs since it keeps the line from changing, just to add a comma.

Anyway, I was very surprised by this, lesson (hopefully) learned. So... Note to self, don't use that trailing , in JavaScript.