views:

323

answers:

4

So I just downloaded emacs 23.1 for my new snow leopard macbook pro from http://emacsformacosx.com/ and it works like a charm, except...

I have visual customizations in my .emacs, a few lines are extracted here:

(set-background-color "black")
(set-cursor-color "green") (set-default-font "--Lucida Console-normal-r-normal-normal-18--96-96-c-*-iso10646-1")

I also have some key bindings set up, here are a few lines of those

(global-set-key "\C-l" `goto-line)

(global-set-key [(control ?%)] `query-replace-regexp)

The first time I start emacs or open a document with emacs, everything loads perfectly. When I issue a command-N or open another file through finder, a new window opens with the key binding customizations loaded but without the visual customizations (including window size, etc)

I think this has something to do with how emacsclient is being invoked and the emacs server, but despite my avid usage of emacs for development, I'm pretty clueless when it comes to setting up the editor itself outside of .emacs level customization

Here are potential behaviors I would like to achieve when a new window is opened (via command-n or opening a document in finder), in order of preference:

  1. Have the new window create a new emacs process (not just a new buffer) so that I can manage and navigate multiple projects similar to how textmate does it, using one emacs process for each project.

  2. Have those visual customizations be persistent so that each new window loads with the correct sizing, fonts, and colors.

  3. Have each new document open as a buffer within the current active emacs window.

Let me know if you guys can help, thanks!

A: 

I'm on linux, but I've got this sort of working. Basically, what I do in my .emacs (which see for details), is use the after-make-frame-functions hook:

(add-hook 'after-make-frame-functions
  (lambda (frame)
    (set-variable 'color-theme-is-global nil)
    (select-frame frame)
    ;;; set color theme and other visual things, like fonts
    ))

one thing is that I set-variable 'color-theme-is-global because I like to have different themes for terminals versus windowing. Theoretically you should be able to just do a (set-variable 'color-theme-is-global t) somehwere before you set your colors to make it work.

One problem that I've been unable to solve is that changing my font size doesn't reflow the style, so I get weird picture-in-picture effects that are hideous and force me to unmaximize/remaximize my frame, which kind of defeats the point.

I'm pretty sure that adding the hooks/designing the functions in the correct order should get rid of that, but I haven't managed to get it working well for awhile.

quodlibetor
+1  A: 

For customizing the colors, you need to make the changes for the frames like so:

(setq default-frame-alist
    `((background-color . ,background)
      (foreground-color . "lightcyan")
      (border-color . "lightskyblue1")
      (cursor-color . "palegoldenrod")
      (mouse-color . "azure")))

As far as spawning a new Emacs process when opening a document in Finder, to do that, you just need to disable your emacs server, and/or not use emacsclient. Just set it up so that emacs is called directly to open files. I don't know how to customize finder actions...

Trey Jackson
yeah that makes sense and takes care of the color stuff...looks like it's not picking up the window sizing or font but I'm sure I could look through the emacswiki to figure that part out, so I think this takes care of #2.I'm going to leave this open for a day or so though, I'd love to know a solution for #1 if anybody knows one.
Neil Sarkar
A: 

As for #1, starting a new emacs process, you could probably accomplish this by writing scripts to override the default behavior. This would entail capturing the file path and using Emacs's system interface to invoke a new instance. But you might want to try a single Emacs solution for a while and see if it doesn't cause you too much pain.

pajato0
+2  A: 

OK I figured out how to do this (start a new emacs server for each new project) from the terminal, I'm sure it would be trivial to get it working from the finder too but since I'm usually in terminal anyway it works for me. I just added this to my ~/.profile

function emacs-open() {
    /Applications/Emacs.app/Contents/MacOS/Emacs $1 &
}

then when you want to open a file in a new project (emacs server) with all ur frame customizations and .emacs loaded correctly, it's just

$ emacs-open index.php

I know this may seem really obvious to some, but as far as i could tell it's not done for you anywhere when u dl the package from http://emacsformacosx.com/ so hopefully this helps somebody

Neil Sarkar