lisp service

(format T "Hello World") 

My new favorite emacs command I should have known about ages ago

M-/

Admitting that I wasn't using it before makes me feel like a fake programmer.  I might just stop using tab completion entirely and use this instead.

Loading mentions Retweet
Filed under  //   autocompletion   Emacs   programming  
Posted by Divia 

Comments [1]

Installing CL-SMTP with clbuild

Since it took me a couple of tries to get it right, I thought I'd share the line I added to my clbuild/wnpp-projects file to get "clbuild install cl-smtp" to work.

 
cl-smtp get_cvs_full :pserver:anonymous:anonymous@common-lisp.net:/project/cl-smtp/cvsroot cl-smtp 

Loading mentions Retweet
Filed under  //   cl-smtp   clbuild   how-to   Lisp  
Posted by Divia 

Comments [0]

A simple categorization of client-side web application frameworks

I recently wanted to find a new framework to use to create a very client-heavy web application, and after some searching on the Internet, I was completely overwhelmed by the sheer number of options.  These frameworks differ on a variety of dimensions, but the one I found most useful for me was to categorize them based on their "heaviness."  What I mean by a heavy framework here is one that is used for making very desktop-like applications for the browser - things that make it very simple to do things like undo in your app and end up producing a very fat client type application.  Light frameworks, on the other hand, are not much more than a layer on top of raw Javascript to help you do things like AJAX calls or DOM manipulation more easily.  Although I am looking for a heavy framework, all of these frameworks have their place.

Note that this list, right now, is based solely on what I have been reading over the past weekend and I haven't actually hacked around with any of the frameworks (I plan to once I finish making my shortlist).  Please feel free to let me know in the comments if you think I have miscategorized any of the frameworks.  I also realize that ranking the heaviness of the framework is somewhat simplistic and doesn't take everything about the framework's ability into account (everybody is unique, after all), but it just seemed like a useful heuristic to me (and I feel like it would take me at least a month to really judge all of these frameworks).   I hope, at some point, to write up more detailed reviews of some of these frameworks.  

Anyway, my classifications are below.  

  • Heavyweight (The entire app is pretty much on the client side and the framework is focused very much on making desktop-like applications - these are often used to create what are known as RIAs)
    • Flex
    • Sproutcore
    • Cappuccino
    • Open Laszlo
    • Silverlight
    • Qooxdoo
    • JavascriptMVC
    • Spry
    • OAT
    • JavaFX
    • Tibco GI
  • Light heavyweight (These frameworks still make it possible to make desktop-like applications with huge widget libraries, but seem to be one level of abstraction below the heavyweights)
    • Dojo
    • YUI
    • EXT
  • Middleweight (These frameworks don't differ that much from the light heavyweights, except they seem to have fewer widgets and UI tools)
    • Google web toolkit (GWT)
    • Open Rico
  • Welterweight (These frameworks make writing AJAX and doing DOM manipulation easier, but they seem a bit low on tools to make a full fledged desktop like application)
    • JQuery
    • Prototype/scriptaculous
    • Fork
  • Lightweight (These seem to basically be very light abstractions on top of Javascript/CSS - more like Javascript utility libraries than actual frameworks)
    • Moo Tools
    • X Library
    • Mochikit
    • XUL

Loading mentions Retweet
Filed under  //   Cappuccino   CSS   Dojo   EXT   Flex   Fork   Frameworks   Google web toolkit   GWT   JavaFX   Javascript   JavascriptMVC   JQuery   Mochikit   Moo Tools   OAT   Open Laszlo   Open Rico   Prototype   Qooxdoo   Rich Internet Applications (RIA)   Scriptaculous   Silverlight   Sproutcore   Spry   Tibco GI   X Library   XUL   Yahoo User Interface Library   YUI  

Comments [6]

What PostgreSQL type does CLSQL use for symbol?

I really like that clsql will create database tables for me using create-view-from-class. (For some reason I haven't gotten drop-view-from-class to work--it just returns "No Value" and leaves the table intact--but that doesn't really bother, since it's easy enough to drop tables.
 
I do, however, wish that there were an updated-view-from-class command that I could run when I added a slot to a class. Dropping the table myself, then creating it again certainly works, but then I lose my data, which is rarely what I'm going for. Usually, I don't care much, because I can just log into phpPgAdmin and update the table manually. In the past, it hasn't been too hard for me to figure out how to do so. I'm capable of converting hyphens to underscores, and it was always obvious which type to make the table, integer would be integer, float a double precision, string a character varying. I just had a symbol type slot in my object though, and I wasn't sure what that would be.
 
Annoying as it was, I deleted the table and used create-view-from class.

The answer is: clsql converts the symbol type to a "character varying", just as it does with strings. So now I know, and I won't have to go through that again.

Loading mentions Retweet
Filed under  //   clsql   Lisp   phpPgAdmin   PostgreSQL   programming  
Posted by Divia 

Comments [2]

How to convert a string to a float in Common Lisp

Since it took me more than a few minutes of googling to figure this out, I thought I'd post what I found. I found this parse-float function, which made me think that there wasn't a way to do it otherwise, but that turned out not to be the case. I learned here that all I needed was READ-FROM-STRING. As in:

* (read-from-string "#X23")
35
4
* (read-from-string "4.5")
4.5
3
* (read-from-string "6/8")
3/4
3
* (read-from-string "#C(6/8 1)")
#C(3/4 1)
9
* (read-from-string "1.2e2")
120.00001
5
* (read-from-string "symbol")
SYMBOL
6
* (defparameter *foo* 42)
*FOO*
* (read-from-string "#.(setq *foo* \"gotcha\")")
"gotcha"
23
* *foo*
"gotcha"

Loading mentions Retweet
Filed under  //   how-to   Lisp   programming  
Posted by Divia 

Comments [4]

Code Project Management in Emacs, Part 3

In the Part 1 and Part 2, I talked about getting project management setup using anything and proel to be able to find files within a project and find terms within project files. This time, my topic is a bit more subjective.  The setup described here is probably largely based on my preferences, but since I always like seeing how others interact with their tools, I thought I would post what I do.

This setup was motivated by a lingering lacking feeling I still had when interacting with projects within Emacs.  In Textmate or Aquamacs, it just felt easier to view multiple files at the same time and switch back and forth between them. In Aquamacs, I could do this by just opening a bunch of files and switching amongst the windows (since in Aquamacs I could pin buffers to windows, where I mean window in the operating system sense, not the Emacs sense). My general modus operandi was to have a bunch of files open that I switched between using the normal Emacs buffer switching method ("C-x b"). In Textmate, I would have multiple files open in tabs or in new windows, but again, I would just switch between the windows using Apple-`.

In Carbon Emacs, however, I soon realized that because frames and buffers are decoupled, this method would not really work. After some thinking, I realized that what I really wanted was to have two frames open, each with two windows within them (split horizontally), at all times, and then a way to easily switch amongst those spaces and open the buffer I want in each space. This way, not only would I be able to view multiple files at the same time (I don't think I ever need to view more than 4 at a time), but I could finally do that which I was never really able to do well in Textmate or in Aquamacs - have the spaces taken up by each file be completely distinct and not overlap with each other. I realized that in both Aquamacs and Textmate, I would spend a lot of time moving windows around manually so that they would not overlap with each other so that I could view the files in each window fully at the same time. This manual moving of windows, however, quickly became cumbersome when I had more than 4 or 5 files open. With Carbon Emacs, I have changed the way I think to basically have 4 "spaces" on my screen (where a space is a window within a frame), and in each space, I can have any buffer I want open (which makes it significantly easier to work with lots of buffers).

In addition to what I said above, I wanted to start each frame on a separate monitor in full screen mode (to both try distraction-free coding and also to quell any temptations I might have to use the Finder or Textmate - I am experimenting with existing entirely in Emacs so until I get used to it I don't want to judge if this is actually a better mode of existing). It was definitely non-trivial to get full screen working on a dual-monitor setup, but adding the following to my .emacs worked for me (note that my first monitor is 1400 px wide - you should change the value of left in (setq default-frame-alist '((top . 1) (left . 1450) (width . 80) (height . 53))) so that the second frame opens up in your second monitor):

;; New frames use this size 
(setq default-frame-alist '((top . 1) (left . 1450) (width . 80) 
(height . 53))) 
(setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 53))) 
 
;; Allow toggling fullscreen 
(defun fullscreen () 
 "toggles whether the currently selected frame consumes the entire 
display or is decorated with a window border" 
 (interactive) 
 (let ((f (selected-frame))) 
  (modify-frame-parameters f `((fullscreen . ,(if (eq nil 
(frame-parameter f 'fullscreen)) 'fullboth nil)))))) 
 
(split-window-horizontally) 
(fullscreen) 
(make-frame-command) 
(other-frame 1) 
(split-window-horizontally) 
(fullscreen) 

Note that the above will also let you get out of full-screen mode with "M-x fullscreen".  Setting up the above makes my Emacs look like the screenshot below when I start up:


Finally, I wanted to change up keybindings to make it easier to switch between frames and between windows within the frames. So I added the following to my .emacs: 

(global-set-key [C-tab] 'other-frame)
(global-set-key "\C-o" 'other-window)
(global-set-key "\C-xo" 'mode-line-other-buffer)

This makes control-tab switch between the two frames and C-o switch between the two windows in each frame. Also, C-x o will now switch between the last two buffers I had open.  

Now, the way I tend to work is have the file I am currently working on in my left-most space. Then, when I need to open a different file to compare (or do a grep within my project), I will switch to the second window in my first frame and do it here. In my second frame, I usually have the repl open in the first window, and the last window I leave open for whatever else comes to mind.

I haven't used this setup for that long, and it is taking a bit of getting used to to think of buffers and windows this way, but so far, I think I like this setup better. There are still a few things I wish I could do (and might take the time to set them up) like making a tag search automatically open in a different one of my spaces, or have an option in anything to open a file in a specified space, but for now, I think I am satisfied.

Loading mentions Retweet
Filed under  //   Carbon Emacs   dual monitor   Emacs   full screen   how-to   Lisp   programming   two monitor  

Comments [3]

Code Project Management in Emacs, Part 2

In the last post, I talked a bit about setting up file finding in projects with Anything.  Since then, I've done a couple more things to make my life inside an Emacs project a bit better.  First, I set up regular expression matching for anything objects using the anything-match plugin.  This worked very easily - I just installed the package, and Anything immediately began accepting my regular expressions (and highlighting results).

Next, I decided to set up proel.  After installing the package, I needed to set the projects directory in proel.el.  To do this, I set the "proel-dir-with-projects" variable as follows:

In proel.el, line 37:

(defvar proel-dirs-with-projects (list (expand-file-name "~/Development/Source/clbuild/source"))
  "The list of directories one stores projects in.")

Note that I wasn't able to simply setq this variable in my .emacs file since if this directory is not set to something that exists on your computer at emacs startup time, requiring proel in your .emacs file fails. Next, I added "proel-anything-projects" to my list of anything sources, making my sources in my .emacs file look like the following:

;; anything setup
(require 'anything-config)
(require 'anything-match-plugin)
(global-set-key "\C-u" 'anything)
(setq anything-sources '(anything-c-source-buffers+
			 anything-weblocks-saikat-c-source-file-search
			 anything-contentrees-c-source-file-search
			 anything-c-source-locate
			 anything-c-source-recentf
			 proel-anything-projects
			 anything-c-source-org-headline
 			 anything-c-source-buffer-not-found))

Finally, the tricky part. The main reason I wanted proel was for the grepping in project ability. But the first time I tried it, it kept failing for me, giving me the error "Wrong type argument: stringp, nil". After some digging, it turned out that some defaults had to be set for grep before I could use this command by calling (grep-compute-defaults). So, in my .emacs file, I did the following to setup proel:

;; proel setup
(require 'proel)
(grep-compute-defaults)
(global-set-key "\C-c\C-g" 'proel-grep-in-project)

This is working great.  The one change I am thinking of making is editing the proel project searching function to use ack instead of grep, as suggested by Mikhail in a comment to my last post.

Loading mentions Retweet

Comments [0]

ParEdit in the SLIME REPL

I mentioned before that I made ParEdit work in the SLIME REPL. Here's what I added to my .emacs file to activate it:

 
(autoload 'paredit-mode "paredit" 
  "Minor mode for pseudo-structurally editing Lisp code." 
  t) 
;(add-hook 'lisp-mode-hook (lambda () (paredit-mode +1))) 
(mapc (lambda (mode) 
     (let ((hook (intern (concat (symbol-name mode) 
                   "-mode-hook")))) 
      (add-hook hook (lambda () (paredit-mode +1))))) 
    '(emacs-lisp lisp inferior-lisp slime slime-repl)) 

Taken from http://coding.derkeiler.com/Archive/Lisp/comp.lang.lisp/2007-07/msg01505.html.

Loading mentions Retweet
Filed under  //   Emacs   how-to   ParEdit   SLIME  
Posted by Divia 

Comments [0]

Code Project Management in Emacs, Part 1

I have mostly converted entirely to using Emacs as my primary text/code editor, but one of the few things I always found a bit lacking was Emacs' ability to manage code projects (or at least, my knowledge of whatever ability Emacs has). Though Emacs is great with tags (and if you are using Slime, finding function definitons and usages is fairly easy), I would find myself constantly going back to Textmate to do things like see a listing of all my files or search for certain bits of code in my project. 

I finally decided this must stop.

I started with trying to make it easier to find files in Emacs. This is not directly related to project management in Emacs, but it seemed like something that could be tied in (and plus, I've wanted to do this for a while). I toyed around with a few things (icicles and ido - Divia settled on icicles), but finally decided on anything.  Anything is, as many others have mentioned, like Quicksilver for Emacs. Essentially, it lets you operate by first picking an "object" (where an object can pretty much be anything - some examples are files, buffers, or Emacs commands) and then commit and action on that object (like open in new frame for a file). Bill Clementson has a great writeup of how anything works here.

Installing anything isn't too difficult (if only I could mean that sentence literally for Lisp). Configuring it, however, can take some time - not because it is hard, but because there are so many things you can do with it. There are a variety of "sources" that anything uses which describe different actions/objects you can do when you invoke anything. These sources can be set up in your .emacs file.

So, at first, my .emacs file looked as follows:

 
;; anything setup 
(require 'anything-config) 
(global-set-key "\C-u" 'anything)
(global-set-key "\C-c\C-u" 'universal-argument) 
(setq anything-sources '(anything-c-source-buffers+ 
       anything-c-source-locate 
       anything-c-source-recentf 
       anything-c-source-org-headline 
 			 anything-c-source-buffer-not-found)) 

 
As you can see above, I set control-U to invoke anything easily. This worked great - I could now type in the first part of any file I wanted, and it would search for it very fast anywhere in my directory (the anything-c-source-locate source does this). The problem now was that I was getting too many results for a given file name candidate. What I realized I do about 80% of the time is look for files in one of two project directories. So, I added two custom sources in anything-config.el:
 
 
(defvar anything-contentrees-c-source-file-search 
 '((name . "Contentrees Search") 
  (candidates . (lambda () 
          (let ((args 
              (format "'%s' \\( -path \\*/.svn \\) -prune 
-o -iregex '.*%s.*' -print" 
                  (get-source-directory "contentrees") 
                  anything-pattern))) 
          (start-process-shell-command "file-search-process" nil 
                  "find" args)))) 
  (type . file) 
  (requires-pattern . 4) 
  (delayed)) 
 "Source for searching matching files in contentrees recursively.") 
 
(defvar anything-weblocks-saikat-c-source-file-search 
 '((name . "Weblocks-saikat Search") 
  (candidates . (lambda () 
          (let ((args 
              (format "'%s' \\( -path \\*/.svn \\) -prune 
-o -iregex '.*%s.*' -print" 
                  (get-source-directory "weblocks-saikat") 
                  anything-pattern))) 
          (start-process-shell-command "file-search-process" nil 
                  "find" args)))) 
  (type . file) 
  (requires-pattern . 4) 
  (delayed)) 
 "Source for searching matching files in weblocks-saikat recursively.") 

Then, in my .emacs, I changed my anything setup to:

 
;; anything setup 
(require 'anything-config) 
(global-set-key "\C-u" 'anything) 
(setq anything-sources '(anything-c-source-buffers+ 
       anything-weblocks-saikat-c-source-file-search 
       anything-contentrees-c-source-file-search 
       anything-c-source-locate 
       anything-c-source-recentf 
       anything-c-source-org-headline 
 			 anything-c-source-buffer-not-found)) 

Now, when I invoke anything and start typing in a word, I first get a list of possible buffers with that name followed by files in my two project directories, followed by a locate on my entire home directory, which is pretty much exactly what I wanted (and I got the added benefit of anything actions on these files, making it easier to do things like open the file in a new frame when I want). Note that I had to remap the command to make prefix arguments to C-c C-u.

One BIG caveat to using anything: I was using anything in Aquamacs at first, but it would constantly move my current window to the top right corner of my screen and resize it. After some research, it seemed like Aquamacs just doesn't really work with anything, so I had to switch to Carbon Emacs. Carbon Emacs is fine, although it handles frames and buffers the "true Emacs" way (whereas Aquamacs attaches buffers to frames), and this has taken some getting used to. 

Next, I want to get fuzzy matching working with anything, start using proel, and get Mercurial working from within Emacs.

Loading mentions Retweet
Filed under  //   Anything   Aquamacs   Carbon Emacs   Emacs   how-to   Icicles   Mercurial   programming  

Comments [6]

How to bind C-backspace in Aquamacs

A little while back, as part of my ongoing effort to get better at using emacs, I added the following lines to my .emacs file, as recommended by Editing Lisp Code with Emacs 

 
(define-key slime-mode-map (kbd "C-t") 'transpose-sexps) 
(define-key slime-mode-map (kbd "C-M-t") 'transpose-chars) 
(define-key slime-mode-map (kbd "C-b") 'backward-sexp) 
(define-key slime-mode-map (kbd "C-M-b") 'backward-char) 
(define-key slime-mode-map (kbd "C-f") 'forward-sexp) 
(define-key slime-mode-map (kbd "C-M-f") 'forward-char) 

The idea is to make navigating by s-expressions the default, which makes sense to me. I can see how once I get used to it, that will be faster. In the same spirit, I wanted to bind C-backspace to backward-kill-sexp. I tried doing:
 
(define-key slime-mode-map (kbd "C-backspace") 'backward-kill-sexp) 

but that didn't work, giving me this error message:

An error has occurred while loading `/Users/divia/.emacs':
 
error: C- must prefix a single character, not backspace

I figured there must be someway to bind Control-backspace, and Saikat had helpfully just informed me last night that the default Emacs key bindings were stored in /Applications/Aquamacs Emacs/Contents/Resources/lisp/bindings.el.gz, so I decompressed the file and looked inside. Sure enough, I copied the binding style from there, and it worked:

 
(define-key slime-mode-map [C-backspace] 'backward-kill-sexp) 

I don't know enough about elisp to know why one is okay and the other isn't, but for now I'm just happy to have found a solution.

Loading mentions Retweet
Filed under  //   Aquamacs   Emacs   errors   how-to   Lisp  
Posted by Divia 

Comments [0]