[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: swtching between buffers?

From: Yan Tang
Subject: Re: swtching between buffers?
Date: Sun, 11 May 2003 08:53:11 +0800

I have another trick for cycle buffer, stolen from the famous cycle
buffer and modified by myself.

The following are my codes.
When you press C-o to cycle buffer, buffer list will be appeared in
mini-buffer, and cycle right, just like alt-tab in M$ windows.
The first one in mini-buffer will be the next main buffer.
;; C-<TAB> only work in XWindow, so I have to define C-o, but why?
(global-set-key "\C-o" 'next-buffer)
;(global-set-key [\C-tab] 'next-buffer) ;forward reference
;(global-set-key [\C-\S-tab] 'prev-buffer) ;forward reference

;; Dired mode has its own ctrl-o, I have to do local key rebinding.
(add-hook 'dired-mode-hook
          '(lambda ()
             (define-key dired-mode-map "\C-o" 'next-buffer)))

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

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

(defun cycle-buffer (ls)
  (let* ((ptr ls) bf bn)
    (setq ptr (append ptr (list '<BUFFER-FLAG>)))
    (while (not (equal (car ptr) '<BUFFER-FLAG>))
      (setq bf (car ptr)
            bn (buffer-name bf))
      (if (null (ignore-buffer bn))
          (setq ptr (append (cdr ptr) (list (car ptr))))
        (setq ptr (cdr ptr))))
    (setq ptr (cdr ptr))
    (setq bf (car ptr))
    (setq ptr (append (cdr ptr) (list (car ptr))))
    (message "%s" ptr)
    (if bf
        (switch-to-buffer bf))))

(defun ignore-buffer (str)
    ;;buffers I don't want to switch to 
   (string-match "\\*Buffer List\\*" str)
   (string-match "\\*Compilation\\*" str)
   (string-match "^TAGS" str)
   (string-match "^\\*Messages\\*$" str)
   (string-match "^\\*Completions\\*$" str)
   (string-match "output\\*$" str)
   (string-match "^ " str)
   ;(memq str (mapcar 
   ;   (lambda (x) (buffer-name (window-buffer (frame-selected-window
   ;   (visible-frame-list)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]