<div dir="ltr">Well, I spent a weekend with Aquamacs and I got the opening of new files to behave about as well as I can hope for.  I was interested primarily in three issues, which are closely tied together: removing the scratch buffer, automatically tiling new windows, and closing unmodified untitled windows when they are overwritten by other buffers.  As a caveat before all of this, I should mention that I operate in one-buffer-one-frame mode, and most of my modifications will probably fail miserably outside of this mode.  I should also confess that I am not very confident in these modifications, as they seem like kludges operating on arcane Emacs numerology, but they seem to work as far as I can tell on my Aquamacs distribution on my particular computer.  There is a bit of window strobing as Emacs tries desperately to misbehave and the hooks kill the undesired buffers, but everything seems to work out after the dust settles.  I did all my modifications in tags that are in my .emacs file, which I included at the end of this email.<br>

<br>Before I delve too deeply into this, there is one question that I still have.  I have not been able to figure out how to affect the cursor focus between Aquamacs frames.  When I open a new frame, I want the cursor to move to that frame always, even if the frame was opened by invoking Aquamacs from the command line.  Neither select-frame nor select-frame-set-focus seem to have any effect.  I can access the desired buffer with set-buffer, and even modify that buffer, but I can't put the actual cursor in that buffer.  Any suggestions here?  Does Aquamacs have some other mechanism for handling cursor position?<br>

<br>It turned out that the code path as buffers and frames are created and destroyed is about as intuitive as riding a bicycle... going backwards, blindfolded, and with no hands.  Okay, maybe not that bad, but still, not very clear.  There is also some anomalous behaviour here and there.  Emacs requires that a frame always be open.  If you try to kill all frames, Emacs refuses.  The visibiliy of a frame "on the screen" does not seem to correspond to the "visibility bit" that Emacs maintains for each frame.  In particular, there is one frame that is not visible until selected by the user (it usually appears as the last frame on the list).  This frame doesn't inherit any of the default window properties.  For some reason, Emacs seems to think that this is the only visible frame and will not allow me to close it.<br>

<br>One of the biggest challenges in getting the behaviour I wanted was to prevent Emacs from making this frame visible on the screen.  To do so, I sometimes had to create dummy frames and then delete them later so that Emacs was never left with only one frame (the unkillable default frame with bad window properties) to choose from.<br>

<br>As for the scratch buffer, I agree that if the behaviour of Aquamacs with regards to the scratch buffer should be an option.  If the user wants to maintain the default scratch buffer just as it has always been, that option should be available.  For those who never want to see the thing again, see my code below.<br>

<br>I also implimented a feature that I've been wanting for a while, and which also helps with window management: if an unmodified untitled buffer is open and a user opens another file, the untitled buffer is closed.<br>

<br>Lastly, I moved the window tiling feature to the end of the whole frame-creation routine.  I ended up killing and moving so many frames during frame creation that it made much more sense to clean everything up at the end.<br>

<br>Below is the relevant text from my .emacs file.  If there are any questions about it or why I implimented things the way I did (believe me, I tried many, many other methods), please feel free to comment.  Improvements are definitely welcome!<br>

<br>Adrian<br><br>;; DEFAULT WINDOW CONFIG<br>;; set default window size and position, and tiling parameters<br><br>(setq width_in_chars 80)<br>(setq height_in_chars 77)<br>(setq initial_frame_left 997)<br>(setq n_tiles 2)<br>
(setq frame_left_offset 400)<br><br>(setq initial-frame-alist<br>       `((left . ,initial_frame_left)<br>     (top . 0)<br>     (width . ,width_in_chars)<br>     (height . ,height_in_chars))<br>)<br>(setq default-frame-alist<br>
       `((left . ,initial_frame_left)<br>     (top . 0)<br>     (width . ,width_in_chars)<br>     (height . ,height_in_chars))<br>)<br><br><br>;; HOOKS<br>;; all hook declarations at end of hooks section<br><br>;; initialization hook<br>
;;    closes the scratch buffer and creates a blank buffer<br>(defun my-close-scratch ()<br>  (kill-buffer "*scratch*")<br>  (new-empty-buffer)<br>  (if (< 6 (length (buffer-list)))<br>      (kill-buffer "untitled")<br>
  )<br>)<br><br>(defun my-emacs-startup-hook ()<br>  (my-close-scratch)<br>)<br><br>;; after-make-frame hook<br>;;   if any goofy system buffers have popped, close them<br>;;   then tile remaining windows<br><br>;; if the frame just made does not contain an emacs-owned buffer,<br>
;; close any emacs-owned buffers<br>(setq first_frame t)<br>(defun my-close-system-frames (frame)<br>  (setq real_buff_count (- (length (buffer-list)) 6))<br>  (setq real_frame_count (- (length (frame-list)) 1))<br>  (setq real_count_diff (- real_frame_count real_buff_count))<br>
  (setq i 0)<br>  (if (and (= real_count_diff 2)  (not first_frame))<br>    (delete-frame (nth 1 (frame-list)))<br>  )<br>  (setq first_frame nil)<br>)<br><br>(defun my-shift-frame (frame)<br>  (setq prev_frame (nth 1 (visible-frame-list)))<br>
  (setq prev_frame_params (frame-parameters prev_frame))<br>  (setq prev_frame_left (cdr (nth 6 prev_frame_params)))<br>  (setq prev_shift_count (/ (- initial_frame_left prev_frame_left) frame_left_offset))<br>  (setq new_shift_count (mod (1+ prev_shift_count) n_tiles))<br>
  (setq new_frame_left (- initial_frame_left (* frame_left_offset new_shift_count)))<br>  (set-frame-position frame new_frame_left 0)<br>)<br><br>;; checks to see if there are enough user-owned buffers to warrant tiling<br>
;; called by after-make-frame hook launcher<br>(defun my-tile-windows (frame)<br>  (setq real_frame_count (- (length (visible-frame-list)) 1))<br>  (if (> real_frame_count 0)<br>      (my-shift-frame frame)<br>  )<br>)<br>
<br>(defun my-after-make-frame-functions (frame)<br>  (my-close-system-frames frame)<br>  (my-tile-windows frame)<br>)<br><br>;; find-file hook<br>;;    closes unused "untitled" buffers<br><br>;; if buffer with name buff_name has no unsaved changes, close it<br>
;; called by my-close-untitled<br>(defun my-close-if-clean (buff_name)<br>  (setq buff (get-buffer buff_name))<br>  (if (not (buffer-modified-p buff))<br>     (kill-buffer buff)<br>  )<br>)<br>;; if there is an untitled buffer with no unsaved changes, close it<br>
;; called by my-clean-untitled<br>(defun my-close-untitled ()<br>  (if (get-buffer "untitled")<br>    (my-close-if-clean "untitled")<br>  )<br>)<br><br>(defun my-find-file-hook ()<br>  (my-close-untitled)<br>
)<br><br>; hook declarations<br>;    add functions in hook launch functions<br>(add-hook 'emacs-startup-hook 'my-emacs-startup-hook)<br>(add-hook 'after-make-frame-functions 'my-after-make-frame-functions)<br>
(add-hook 'find-file-hook 'my-find-file-hook)<br><br><div class="gmail_quote">2008/10/11 David Reitter <span dir="ltr"><<a href="mailto:david.reitter@gmail.com" target="_blank">david.reitter@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


<div>On 11 Oct 2008, at 01:21, Adrian wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
me to try to learn a bit of a new language and wade through source code to try to achieve customized window positioning that probably wouldn't apply to any other user, but for the sake of removing the scratch buffer, I'm more game.<br>




</blockquote>
<br></div>
Make sure you know where to find documentation: the Emacs Lisp Reference, the internal docs (C-h f functionname RET, and C-h v variablename RET).<div><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
much agreement.  I've already made some of my case against the *scratch* buffer, but I also feel that the *messages* buffer is better accessed in a separate way than the other, user-created, buffers.  In particular, when I'm switching between the active buffers, I almost never want to see the *messages* buffer in a large frame window; it just gives me an extra key press on my way to buffers I actually want to see.  Maybe others can correct me on this?<br>




</blockquote>
<br></div>
Good idea.  Perhaps we can ensure that *Messages* is always moved to the end of the buffer list so that the cycling commands will not usually bring up a *Messages* buffer.  The same could be done for *scratch*.<div>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
 However, the *scratch* buffer is sneakier than I anticipated: creating a new frame containing the *scratch* buffer does not call the make-frame hooks.<br>
</blockquote>
<br></div>
It shouldn't matter what the frame contains.  Works for me.<br>
Don't forget that the last frame is not deleted, but only hidden, so bringing it back up does not CREATE a frame - it merely makes is visible.<div><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Even when the initial *scratch* frame is created, these hooks are not invoked.<br>
</blockquote>
<br></div>
Where do you add to the hook?  Have you considered the order of execution?<br>
<br>
<br>_____________________________________________________________<br>
MacOSX-Emacs mailing list<br>
<a href="mailto:MacOSX-Emacs@email.esm.psu.edu" target="_blank">MacOSX-Emacs@email.esm.psu.edu</a><br>
<a href="http://email.esm.psu.edu/mailman/listinfo/macosx-emacs" target="_blank">http://email.esm.psu.edu/mailman/listinfo/macosx-emacs</a><br>
List Archives: <a href="http://dir.gmane.org/gmane.emacs.macintosh.osx" target="_blank">http://dir.gmane.org/gmane.emacs.macintosh.osx</a><br>
<br></blockquote></div><br></div>