[OS X Emacs] Re: Aquamacs mucks up my key-bindings in one-buffer-one-frame-mode

cytan cytan299 at netzero.net
Sun Jan 17 17:59:59 EST 2010


OK, since no one seems to have an answer to my question, I've decided to work it
out myself and have at least a hack to make my keybindings work in
one-buffer-one frame-mode. Also I've also hacked Preferences.el so that Aquamacs
will open up a new frame when invoked from the command-line but when find-file
is executed within Aquamacs, the file is put in the current buffer and not in a
new frame.

Here's the part of my preferences.el file which fixes my problem plus the extra
functionality I wrote above. Comments welcome.

cytan

;;
;; This function is required to allow the ability to open a file in the
;; current frame rather than a new frame when one-buffer-one-frame-mode
;; is true.
;;
(defun my-find-file (filename)
   "Edit file FILENAME.
   Switch to a buffer visiting file FILENAME,
   creating one if none already exists."
   (interactive "FFind file: ")
   (switch-to-buffer-here (find-file-noselect filename)
))

(global-set-key (kbd "C-k C-f") 'my-find-file)

;;
;; one-buffer-one-frame-mode messes up my keybindings
;; Here's the code which fixes the problem in the various
;; modes and rebinds them to where I want them. 
;;
;; From experimentation, I discovered that much fewer key bindings
;; are messed up *IF* one-buffer-one-frame-mode is set AFTER
;; the Preferences.el file has been read. 
;;
;; Therefore, one-buffer-one-frame-mode must be set in the emacs-startup-hook
;; so that fewer keys get remapped.
;;
;; I also want to have the ability to start
;; a new frame on the commandline while keeping the ability to open 
;; a new file in the current frame/buffer without opening a new frame.
;; This ability also required a new function called my-find-file defined
;; above. But one-buffer-one-frame-mode MUST be unset on Aquamacs exit
;; to keep this ability.
;;
;; OK, here's all the code required for what I want.
;;
;; First, override one-buffer-one-frame-mode keybindings which screw up the
;; global key bindings

(add-hook 'one-buffer-one-frame-mode-hook
 (lambda ()
 (define-key one-buffer-one-frame-mode-map (kbd "C-x") 'next-line)
 (define-key one-buffer-one-frame-mode-map (kbd "C-e") 'previous-line)
 )
)

;; override the c-mode keymappings with mine

(add-hook 'c-mode-common-hook
 (lambda ()
 (define-key c-mode-base-map (kbd "C-d") 'forward-char)
 (define-key c-mode-base-map (kbd "C-k C-k") 'copy-region-as-kill)  
 )
;;
;; On Aquamacs exit, I unset one-buffer-one-frame-mode
;; because on startup I need this to be false in order
;; for all the stuff which I want to work!

(defun my-kill-emacs ()
 (interactive)
 (setq one-buffer-one-frame-mode nil)
 (kill-emacs)
) 
 
(define-key osx-key-mode-map (kbd "A-q") 'my-kill-emacs)







More information about the MacOSX-Emacs mailing list