Posts Tagged ‘Emacs’

Web-based Emacs

Thursday, November 26th, 2009

Ymacs: http://www.ymacs.org/

I just spent a few minutes playing around with it. Missing a ton of key bindings, and the all-important butterfly-mode, but it definitely feels like you’re in Emacs.

It’s kind of an eerie feeling.

Interesting minor modes discovered in the Emacs guided tour

Tuesday, August 19th, 2008

I was looking for a good introduction to Emacs for some friends and stumbled upon the truly excellent Guided Tour of Emacs on gnu.org.  And unsurprisingly it contained a few useful minor modes of which I had never heard.

icomplete-mode

icomplete-mode shows completions in the minibuffer as you type.  If you’re too impatient to hit tab, then this is the minor mode for you.

iswitchb-mode

This global minor mode solves an inconvenience that had always bothered me.  Typically, to see a list of buffers without resorting to the mouse, one has to C-x b TAB to see the list of buffers, or C-x C-b and then toggle over to the other window (Ctl-o) to use dired to select a buffer. Too many keystrokes.

iswitchb mode Interesting minor modes discovered in the Emacs guided tour

With iswitchb-mode turned on, C-x b shows a list of avaialble buffers in the mini buffer, narrowing them down as you type.  A much easier way to jump between dozens (hundreds?) of open files.

Update: Looks like iswitchb-mode has been replaced with the far superior ido-mode as of Emacs 22.

Emacs Japanese Input

Saturday, July 12th, 2008

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

Remote PHP Debugging with Emacs

Saturday, June 21st, 2008

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

Saturday, June 21st, 2008

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

Friday, June 20th, 2008

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.)

Line number column in Emacs

Wednesday, May 7th, 2008

 Line number column in Emacs

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!

Highlight Tail for Emacs

Saturday, April 12th, 2008

highlight tail for emacs Highlight Tail for EmacsThis is a cool little minor mode hack for Emacs. It’s like a last-typed heat map.

Onlookers will be amazed as you burn up the screen with your brilliant code.

Update: Rafal Jedruszek’s site above has gone AWOL, so I am preserving a copy here:

Highlight Tail version 1.3.9 (02 Apr 2007).

Prevent Emacs from whining about excess backup versions

Friday, April 11th, 2008

This Emacs prompt gets old after awhile:

Delete excess backup versions of SomeCode.php (y or n)

Emacs is trying to preserve space and clean up after itself.  And, always willing to please, it wants to make sure you’re cool with that.  The prompt is nice, but a tad overprotective.

Adding (setq delete-old-versions t) to .emacs will instruct Emacs to silently delete the older backups. This makes toggle testing between the editor and app much more pleasant.  (Or, for that matter, much less painful.)

Oh, and speaking of overprotective.. Remember to always practice safe emacs.

The easiest way to get Emacs Tramp Mode to play nicely with Windows and secure ssh connections

Saturday, March 1st, 2008

The easiest way is to go “under” Emac’s head and not bother with Tramp at all..

The currently distributed version of Tramp (2.0.x) has a design flaw wherein it assumes that ports are designated with a “-p” switch.  If you’re running Emacs on Windows, however, you will probably want to use Putty’s <code>plink</code> command instead of an command line ssh client.  Problem is plink uses a capitalized “-P” to indicate the port.  Urgh.  (Supposedly this is fixed in Tramp 2.1.x..)

Rather than muck around with this, consider tools that map the remote connection such that it appears local.  The well done open source app WinSCP does a pretty good job of this, though is a bit clunky in the way it syncs up its temporary cache.  South River Technologies’ WedDrive, however, is practically seamless.  Well worth the $60 for a one year license.