Tom Pierce's Blog : Let the geek times roll.
Updated: 6/20/04; 3:16:13 PM.

 

Subscribe to "Tom Pierce's Blog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Monday, July 28, 2003

Today I created a simple Elisp function that will convert the text in a specified region from camel case (e.g. myFunction) to underscore separated format (e.g. my_Function). Glasses mode will do a similar thing in a non-destructive way using overlays. However, this function actually modifies the text.

I used this function to convert between a JDO JOQL filter string and a SQL where clause. The JDO reverse mapping tool we used took SQL table names like "mth_dim" and converted them to Java class names like "mthDim". I had to convert back.

(defun convert-camel-to-underscore (beg end)
  "Converts the camel cased text in the specified region into
underscore separated text."
  (interactive "r")
  (save-excursion
    (goto-char end)

(let ((case-fold-search nil) (end-marker (point-marker))) (goto-char beg) (while (re-search-forward "\([a-z]\)\([A-Z]\)" end-marker t) (replace-match (concat (match-string 1) "_" (match-string 2)))))))


6:37:19 PM    comment []

Today I stumbled across some Elisp code that will take a list and return a list containing the unique elements from the original. Very handy if you don't want to implement your own. You can find it here


6:26:22 PM    comment []

© Copyright 2004 Tom Pierce.



Click here to visit the Radio UserLand website.

 


July 2003
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Jun   Aug

Search

[sgl dagger]
How this works

Emacs Sources
 tsql-indent.el
 user-add-sql-folding-marks
 remove-line-boundary-in-region
 convert-camel-to-underscore

My Subscriptions
 Funny
 KM