Emacs Japanese Input

If you ever find yourself stuck relying on the IME built-into Emacs (rather than the IME native to your OS), here are the essential key strokes you’ll need to know.

  • C-\:  toggle input mode (ime on or off)
  • C-h:  shows conversion options if used when in conversion mode
  • SPC: transform input to kanji, or show the next conversion candidate
  • DEL:  abort conversion
  • C-n: show the next conversion candidate
  • C-p: show the previous conversion candidate
  • C-o: lengthen conversion bunsetsu
  • C-i, TAB: shorten conversion bunsetsu
  • Shift-k:  toggle between hiragana and katakana
  • qq:  toggle between alphabet and kanji modes
  • qz:  turn on zenkaku alphabet mode
  • qh:  turn off zenkaku alphabet mode

Also useful:

  • C-x RET l:  set the buffer language environment
  • C-x RET f: select the encoding
  • C-x RET C-\:  select the input method

How to automatically carbon copy all of your email to George W. Bush

Now that the Senate has decided to grant retroactive immunity to the telecoms (video), it probably won’t be long before the Bush Administration starts routinely tracking your search habits, mining your email, and monitoring your phone calls.  This kind of automated profiling will allow the NSA to determine, among other things, your propensity for terror.  Yes, soon the Bush Administration will be protecting us all from ourselves.

But I say, why wait?! I want the Bush Administration to protect me from myself right now!  Am I a subversive?  Could I be a terrorist?  I need to know!  And I’m sure you do as well.

That’s why I have started automatically carbon copying all of my email to George W. Bush.  Okay, well, technically I’m carbon copying them all to Dick Cheney because it would appear that Cheney reads Bush’s email for him.  But I have every confidence that Mr. Cheney will keep the president abreast of my goings on.

If you’re a Microsoft Outlook user, here’s how you too can automatically carbon copy all of your email to the White House.

  1. In Mail, on the Tools menu, click Rules and Alerts.
  2. On the E-mail Rules tab, click New Rule.
  3. In the Rules Wizard dialog box, under Start from a blank rule, click Check messages after sending, and then click Next.
  4. Click Next.
  5. A confirmation will appear, notifying you that this rule will apply to every message that you send. Click Yes.
  6. Under Step 1: Select action(s), select the Cc the message to people or distribution list check box.
  7. Under Step 2: Edit the rule description (click an underlined value), click people or distribution list.
  8. In the Rule Address dialog box, click a name or distribution list, and then click To. Repeat this step until all names or distribution lists you want to add are included in the To box.
  9. Click OK.
  10. In the Rules Wizard dialog box, click Next.
  11. Click Next.
  12. Under Step 1: Specify a name for this rule, enter a name that you will recognize for this rule.
  13. Click Finish.

That’s it!  Now all of your email will be automatically carbon copied to Dick Cheney at the White House, who will update President George W. Bush, who will work with the NSA to figure out if you are a terrorist or not.  Because, let’s face it, who knows what you’re capable of?  Act now before it’s too late!

Remote PHP Debugging with Emacs

It’s an Emacs weekend here at blog.arithm.

I was recently asked if it was possible to do remote PHP debugging with Emacs. We’re talking about Emacs, so the answer is:  Of course!  How to do it:

  1. Grab Tohru Fujinaka’s GEBEN library.  It’s an aging alpha release, but works fairly well.
  2. Make sure you also have CEDET installed.  I’m using the 1.0 pre4 release.
  3. Drop debugclient somewhere in your path.  (Here Emacs is running on Windows, so I just threw it into the C:\WINDOWS\ directory.)  Make sure the executable is named “debugclient” and not “debugclient-0.9.0” or whatever.
  4. If you’re using the standard xdebug port 9,000 (recommended), make sure that port is open on your firewall.  For most folks these days that means opening up the default OS firewall as well as forwarding a port from the router.  See the exceptional portforward.com for more information on router port forwarding specifics.

Now, assuming you already have xdebug plugged into PHP, modify php.ini or an .htaccess file with the following settings:

  • xdebug.remote_enable = true
  • xdebug.remote_handler = dbgp
  • xdebug.remote_host = your_client_ip

For security reasons it’s wiser to do this via .htaccess on directories that permit only authenticated access.

To debug, ask Emacs to listen for connections by going into GEBEN Mode with Meta-x geben. You should see “xdebug started.” in the status row at the bottom of the Emacs window.

Run your PHP script with the xdebug switch on, eg.

http://www.example.com/script.php?XDEBUG_SESSION_START

If everything is setup correctly, Emacs will load the source of script.php (be wary of security!) and allow you to step through the code.

Available commands are:

spc step into/step over
i   step into
o   step over
r   step out
b   set a breakpoint at a line
u   unset a breakpoint at a line
g   run
q   stop

Some gotchas: I’ve noticed the GEBEN expects the first keystroke to be “space”; often it will freeze otherwise.  GEBEN may also run into problems on certain session-related PHP commands.

Happy debugging!

Set Emacs’ HOME directory in Vista

Rather than allow Emacs to assume HOME is c:\ (which will cause Vista to winge every time you want to modify your .emacs file), try the following:

setx HOME "%USERPROFILE%"

This will make home something like c:\Users\username.

Now you can keep your .emacs in a far more rational place and not have to wake up the Vista security troll whenever you want to do some tweaking.

Undo in Emacs

There are a variety of ways to “undo” something in Emacs.  Unfortunately some of the keystrokes work in some environments, while others do not.  Here’s a quick rundown:

  1. Meta-x undo — Will undo only the most recent changes.  Cannot be used multiple times.
  2. Ctrl-x u — Undo.  Consecutive repetitions will undo earlier and earlier changes.
  3. Ctrl-_ or Ctrl-/ — Same as Ctrl-x u, however does not work in some envrionments.
  4. Ctrl-Shift-Minus — Same as Ctrl-x u, however does not work in some environments.

For whatever reason I can never remember the Ctrl-Shift-Minus sequence when I find myself in an environment where Ctrl-_ and Ctrl-/ don’t work.

Keep in mind that Emacs undo is a bit different from traditional undo:  Undo actions themselves are recorded as actions.  This can be confusing.

In some environments, Ctrl-x Ctrl-_ will reverse the order of undo.  I avoid this out of fear that it will cause the universe to implode.

See the Emacs info node for more good undo lore, such as how to use “selective undo” which restricts undo actions to changes performed in the current active region.  (Very useful.)

Portage Logging

Something else I should have known about long ago.   To turn on logging in portage, simply add the following to /etc/make.conf:

PORTAGE_ELOG_CLASSES="warn error log"
PORTAGE_ELOG_SYSTEM="save"

The will add log files for each package to /var/log/portage/elog/:

# ls -lah
total 108K
drwxrws--- 2 portage portage 4.0K 2008-06-06 01:13 .
drwxr-xr-x 3 root    root    4.0K 2007-10-04 12:29 ..
-rw-r--r-- 1 root    portage  200 2008-06-06 00:58 dev-db:postgresql-8.0.15:20080605-155810.log
-rw-rw-r-- 1 root    portage  72K 2008-06-06 00:44 summary.log
-rw-r--r-- 1 root    portage   67 2008-06-06 01:06 sys-apps:coreutils-6.10-r2:20080605-160624.log
-rw-r--r-- 1 root    portage  108 2008-06-06 01:08 sys-apps:shadow-4.0.18.2:20080605-160842.log

Useful to have around when you miss a barrage of announcements after a large emerge.

Scratch that WordPress Etch

This post comes via notes taken from another blog… seemingly gone awol.   Here for posterity.

Etch naturally has an older version of WordPress.  To upgrade to a more recent, possibly though unlikely more secure version,  the easiest way is to change your tracking to testing, install WordPress and then change back.  How to do it:

1.  Edit your /etc/apt/sources.list to track testing. If your sources.list says etch or stable, change that to testing.  For example if your source.list has:

deb http://debian.lcs.mit.edu/debian etch main contrib non-free
deb-src http://debian.lcs.mit.edu/debian etch main contrib non-free

change those to:

deb http://debian.lcs.mit.edu/debian testing main contrib non-free
deb-src http://debian.lcs.mit.edu/debian testing main contrib non-free

2.  After you change your tracking to testing do an apt-get update.

apt-get update

3.  Install WordPress

apt-get install wordpress

this may pull in a few new php libraries, such as libphp-phpmailer.  Let it.

(Note that you do not want to do an “upgrade”, but rather “install” as listed above.   “upgrade” will try to upgrade a ridiculous number of packages, whereas install will focus only on packages required for installing and/or upgrading WordPress.)

4.  Change your tracking back to Etch. just reverse what you did in step 1. that is change testing back to etch.

5.  Clean everything up.

apt-get clean && apt-get update

After all this is done, login back in as admin to WordPress, and it will tell you that you have to update your WordPress database tables.  Do that and you’re done.

WordPress Category Intersections Revisited

WordPress has included native support for intersections since (I think) version 2.3. Unfortunately, however, robust post retrieval support is only available for tags (eg. tag=A,B retrieves the union of “A” and “B”; tag=A+B retrieves the intersection of “A” and “B”).

Categories still require a hack, and the old plugins for this of course now no longer work.

To get intersection working, try adding the following line before the loop:

<?php <span style="color: #ff0000;">if ($_GET['cat']) query_posts(array('category__and'=>preg_split('/[\s,]+/',$_GET['cat'])));</span> ?>
<?php while( have_posts()) : the_post(); ?>

This applies an intersection to any list of categories separated by space, comma, or “plus” signs in the request.

See Ryan Boren’s post on WordPress intersection and union taxonomies for details on the various forms of post retrieval queries now available.

Line number column in Emacs

emacs-linum-mode.PNG

This is something I’d always wished Emacs did; finally got around to finding a minor mode for it.

While the built-in line-number and column-number modes are fine, linum-mode makes it much easier to see where you are in the code at a glance.

To apply it to all buffers by default, throw the following in your .emacs:

(require 'linum)
(global-linum-mode)

Update: Now baked-in to version 23+ of Emacs!