Re: List Buffers command in MacOS X editor
On Oct 9, 2007, at 2:52 PM, Denis Mashkevich wrote:
> When in buffers list pane after executing "List Buffers" command
> in the editor (macosx only, on windows it works), i can navigate
> with keyboard arrow keys, but cannot switch to the selected buffer
> by pressing a key (tried Enter, Return, Space, Hyper-o, Control-o
> and about any other shortcut). I can only switch to a buffer by
> doubleclicking. Do you experience this also? Is there a workaround/
> fix? Does it drive you crazy?
I filed a bug report for this in 2004 (IMPACT: Annoying :).
My solution was to develop an editor function that pops up a menu of
buffers. This supports type-ahead, arrow keys, and return key to select.
John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL
=====
(defun select-buffer-popup-menu (window)
(let* ((bufs (loop for b in *buffer-list*
unless (buffer-flag b)
collect b))
(pane (window-text-pane window))
(owner (capi:top-level-interface pane)))
(setf bufs (delete-if (lambda (x) (eq (elt (buffer-name x) 0) #
\*)) bufs)) ;like *message buffer*
(setf bufs (sort bufs #'string< :key #'buffer-name))
(unless (eq (type-of owner) 'lw-tools:editor) ;so this can be
used by any type of edit area
(setf owner (capi:find-interface 'lw-tools:editor)
pane (capi:editor-pane owner)
window (capi:editor-window pane)))
(capi:execute-with-interface
owner
'capi:display-popup-menu
(make-instance 'capi:menu :items bufs
:print-function (lambda (b) (if (buffer-modified b)
(string-append
(buffer-name b) " *")
(buffer-name b)))
:callback (lambda (x) (process-character (list
'change-to-buffer x window) window))
:callback-type :data)
:owner owner)))
(defcommand "My Select Buffer" (p)
"Select a buffer from a popup menu of active buffers. Use up/down
arrow keys to change items, Return to select, and Escape to cancel."
(declare (ignore p))
(let ((win (or (current-window) (first (buffer-windows (current-
buffer))))))
(if (not win)
(message "Can't find window interface")
(select-buffer-popup-menu win))))
(bind-key "My Select Buffer" #\F3 :global :mac)