2008-08-21 Monkey Encoding and SQL
Another snippet from my .emacs on the Windows machine. I think Iām going to focus on simple pieces of code, rambling style, and lazy Emacs geek culture (unlike SachaChuaās impressive collection of Emacs posts, hehe).
impressive collection of Emacs posts
Generally I donāt want to mess with my machineās locale because everything else seems to work so well. But inside Emacs, I want UTF-8. Easy! The only problem is that filenames need to be compatible between Emacs and the rest of the system. Hereās how to solve that.
Remember last time (ā 2008-08-19 Emacs on Windows) I talked about liking C-z to toggle two tasks ā usually editing and the shell (and Eshell in particular). Well, I want the same thing in SQL modes. I want to use C-z to toggle between the āSQL command lineā and my SQL code buffer.
Notice that last line mentioning some encoding issues? Back to the main point of this article: SQL*Plus expects me to send and read Latin-1. I guess I could fix this by setting the NLS_LANG environment variable (but only within Emacs since it works just fine outside of Emacs).
That reminds me of another SQL mode problem. When you create a new SQL buffer, it will adopt the current SQLi (the interactive buffer where your interpreter is running) as its own target buffer (to send commands to, for example). If you then kill the SQLi buffer, the original SQL buffer is using a killed buffer as its target. Bad. If you then create a new SQLi buffer, the buffer local sql-buffer variable isnāt fixed automatically. Hereās some code that does it for you:
Let me go back to encoding problems... Where else do they pop up?
Strangely enough, the month names in calendar-month-name-array need to be in Latin-1. I donāt know why. Thatās just what I found in my .emacs. Here goes the fix for German speakers trying to localize their calendar:
Notice that my .emacs file has this on the first line:
The coding cookie makes sure that the entire file (and the contents of all string literals) is decoded as UTF-8. Anyway, I think this might be a bug in CalendarMode. But Iām too lazy to follow up.
The SQL example is an example of an external process not using my favorite encoding. The same is true on IRC. I use rcirc as my IRC client, and the following allows Emacs to try and decode any incoming traffic using its own heuristics (MULE).
As for encoding outgoing text, you can do that by setting rcirc-encode-coding-system. But doing that in a hurry sucks. So hereās a new command, `/encoding`. This code is also on rcircEncoding.
Notice how I use eval-after-load to delay the call to defun-rcirc-command until it will be available, avoiding the need to `(require 'rcirc)`.
Feel free to find the *Comments on 2008-08-21 Monkey Encoding and SQL* link below and ask questions or make suggestions. š
ā#Emacs
Comments
(Please contact me if you want to remove your comment.)
ā
I noticed the same issue with the SQLi buffer in SQL mode. Iāve always thought of brewing up patch at some point so that it DTRT.
You really use Emacs at work to crank out PL/SQL code all day? Thatās wild.
ā AaronHawley 2008-08-21 18:40 UTC
---
Haha, not at all. The past few days Iāve been writing a Tutorial for our new development platform (Eclipse stuff), using a simple CRM example with companies, people, meetings, participants. The example uses five or six tables. My most important applications are therefore:
1. Eclipse, obviously
2. Word, which is where I write the stuff
3. [SqlMode sql-mode], in order to test simple SQL statements and insert sample rows
4. Pidgin, to keep in touch with co-workers
5. rcirc, to keep in touch with everybody else
Havenāt written PL/SQL in a year, I think.
ā Alex Schroeder 2008-08-21 20:28 UTC
---
Thatās good. You have your health to thank for that. PL/SQL is pretty mind numbing from my few experiences.
ā AaronHawley 2008-08-28 20:25 UTC
---
Hehe. I actually prefer PL/SQL to Java for stored procedures on the database because it will at least integrate seamlessly. Then again, in my free time I prefer not to use databases in the first place, haha.
ā Alex Schroeder 2008-08-28 20:38 UTC