sexta-feira, setembro 05, 2003

XEmacs: Setting ctrl-meta-tab and ctrl-meta-shift-tab (argh!) to next and prev buffer


;first taking care of weird iso-left-tab define by X
(global-set-key 'iso-left-tab [(shift tab)])

;key binding
; tab with others modifiers are already taken by KDE
(global-set-key '(control meta tab) 'yic-next-buffer) ;forward reference
(global-set-key '(control meta shift tab) 'yic-prev-buffer) ;forward reference

; here goes the buffer switching methods
;stolen from http://opensource.cis.ohio-state.edu/~hurley
(require 'browse-kill-ring)

(defun yic-ignore (str)
(or
;;buffers I don't want to switch to
(string-match "^TAGS" str)
(string-match "^\\*.*\\*$" str) ;;anyone with a couple of *, usually command buffers
(string-match "^ " str)

;;Test to see if the window is visible on an existing visible frame.
;;Because I can always ALT-TAB to that visible frame, I never want to
;;Ctrl-TAB to that buffer in the current frame. That would cause
;;a duplicate top-level buffer inside two frames.
(memq str
(mapcar
(lambda (x)
(buffer-name
(window-buffer
(frame-selected-window x))))
(visible-frame-list)))
))

(defun yic-next (ls)
"Switch to next buffer in ls skipping unwanted ones."
(let* ((ptr ls)
bf bn go
)
(while (and ptr (null go))
(setq bf (car ptr) bn (buffer-name bf))
(if (null (yic-ignore bn)) ;skip over
(setq go bf)
(setq ptr (cdr ptr))
)
)
(if go
(switch-to-buffer go))))

(defun yic-prev-buffer ()
"Switch to previous buffer in current window."
(interactive)
(yic-next (reverse (buffer-list))))

(defun yic-next-buffer ()
"Switch to the other buffer (2nd in list-buffer) in current window."
(interactive)
(bury-buffer (current-buffer))
(yic-next (buffer-list)))