From a74f9094c42fe38bf1142a698e03bf7f4711451d Mon Sep 17 00:00:00 2001 From: =?utf8?q?K=C3=A1roly=20L=C5=91rentey?= Date: Fri, 16 Dec 2005 11:35:25 +0000 Subject: [PATCH] =?utf8?q?2005-12-16=20=20L=C5=91rentey=20K=C3=A1roly=20?= =?utf8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * bindings.el (last-buffer): Move to simple.el. * simple.el (last-buffer): Move here. (get-next-valid-buffer): New function. (next-buffer): Use frame-local buffer list, maintain buried buffer list. (prev-buffer): Ditto. Rename to `previous-buffer'. * menu-bar.el (menu-bar-update-buffers): Update references to `prev-buffer'. * bindings.el (global-map): Ditto. --- lisp/ChangeLog | 11 ++++++++ lisp/bindings.el | 27 ++---------------- lisp/menu-bar.el | 4 +-- lisp/simple.el | 71 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 72 insertions(+), 41 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9c4bb748bc3..f967252d5c0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2005-12-16 L$,1 q(Brentey K,Aa(Broly + + * bindings.el (last-buffer): Move to simple.el. + * simple.el (last-buffer): Move here. + (get-next-valid-buffer): New function. + (next-buffer): Use frame-local buffer list, maintain buried buffer list. + (prev-buffer): Ditto. Rename to `previous-buffer'. + + * menu-bar.el (menu-bar-update-buffers): Update references to `prev-buffer'. + * bindings.el (global-map): Ditto. + 2005-12-15 Luc Teirlinck * cus-edit.el: Introductory comment change. diff --git a/lisp/bindings.el b/lisp/bindings.el index dbab5f00f0b..7e9467b19c5 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -338,29 +338,6 @@ Keymap to display on minor modes.") (defvar mode-line-buffer-identification-keymap nil "\ Keymap for what is displayed by `mode-line-buffer-identification'.") -(defun last-buffer () "\ -Return the last non-hidden buffer in the buffer list." - ;; This logic is more or less copied from bury-buffer, - ;; except that we reverse the buffer list. - (let ((list (nreverse (buffer-list (selected-frame)))) - (pred (frame-parameter nil 'buffer-predicate)) - found notsogood) - (while (and list (not found)) - (unless (or (eq (aref (buffer-name (car list)) 0) ? ) - ;; If the selected frame has a buffer_predicate, - ;; disregard buffers that don't fit the predicate. - (and pred (not (funcall pred (car list))))) - (if (get-buffer-window (car list) 'visible) - (or notsogood (eq (car list) (current-buffer))) - (setq found (car list)))) - (pop list)) - (or found notsogood - (get-buffer "*scratch*") - (progn - (set-buffer-major-mode - (get-buffer-create "*scratch*")) - (get-buffer "*scratch*"))))) - (defun unbury-buffer () "\ Switch to the last buffer in the buffer list." (interactive) @@ -673,8 +650,8 @@ language you are using." (define-key global-map [?\C-x right] 'next-buffer) (define-key global-map [?\C-x C-right] 'next-buffer) -(define-key global-map [?\C-x left] 'prev-buffer) -(define-key global-map [?\C-x C-left] 'prev-buffer) +(define-key global-map [?\C-x left] 'previous-buffer) +(define-key global-map [?\C-x C-left] 'previous-buffer) (let ((map minibuffer-local-map)) (define-key map "\en" 'next-history-element) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 3d226b9258b..9edd38db86d 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -1662,10 +1662,10 @@ Buffers menu is regenerated." "Next Buffer" 'next-buffer :help "Switch to the \"next\" buffer in a cyclic order") - (list 'prev-buffer + (list 'previous-buffer 'menu-item "Previous Buffer" - 'prev-buffer + 'previous-buffer :help "Switch to the \"previous\" buffer in a cyclic order") (list 'select-named-buffer 'menu-item diff --git a/lisp/simple.el b/lisp/simple.el index 93f6329a255..ec123c73cd8 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -52,25 +52,68 @@ wait this many seconds after Emacs becomes idle before doing an update." "Highlight (un)matching of parens and expressions." :group 'matching) +(defun get-next-valid-buffer (list &optional buffer visible-ok frame) "\ +Search LIST for a valid buffer to display in FRAME. +Return nil when all buffers in LIST are undesirable for display, +otherwise return the first suitable buffer in LIST. + +Buffers not visible in windows are preferred to visible buffers, +unless VISIBLE-OK is non-nil. +If the optional argument FRAME is nil, it defaults to the selected frame. +If BUFFER is non-nil, ignore occurances of that buffer in LIST." + ;; This logic is more or less copied from other-buffer. + (setq frame (or frame (selected-frame))) + (let ((pred (frame-parameter frame 'buffer-predicate)) + found buf) + (while (and (not found) list) + (setq buf (car list)) + (if (and (not (eq buffer buf)) + (buffer-live-p buf) + (or (null pred) (funcall pred buf)) + (not (eq (aref (buffer-name buf) 0) ?\s)) + (or visible-ok (null (get-buffer-window buf 'visible)))) + (setq found buf) + (setq list (cdr list)))) + (car list))) + +(defun last-buffer (&optional buffer visible-ok frame) "\ +Return the last non-hidden displayable buffer in the buffer list. +If BUFFER is non-nil, last-buffer will ignore that buffer. +Buffers not visible in windows are preferred to visible buffers, +unless optional argument VISIBLE-OK is non-nil. +If the optional third argument FRAME is non-nil, use that frame's +buffer list instead of the selected frame's buffer list. +If no other buffer exists, the buffer `*scratch*' is returned." + (setq frame (or frame (selected-frame))) + (or (get-next-valid-buffer (frame-parameter frame 'buried-buffer-list) + buffer visible-ok frame) + (get-next-valid-buffer (nreverse (buffer-list frame)) + buffer visible-ok frame) + (progn + (set-buffer-major-mode (get-buffer-create "*scratch*")) + (get-buffer "*scratch*")))) + (defun next-buffer () "Switch to the next buffer in cyclic order." (interactive) - (let ((buffer (current-buffer))) - (switch-to-buffer (other-buffer buffer)) - (bury-buffer buffer))) - -(defun prev-buffer () + (let ((buffer (current-buffer)) + (bbl (frame-parameter nil 'buried-buffer-list))) + (switch-to-buffer (other-buffer buffer t)) + (bury-buffer buffer) + (set-frame-parameter nil 'buried-buffer-list + (cons buffer (delq buffer bbl))))) + +(defun previous-buffer () "Switch to the previous buffer in cyclic order." (interactive) - (let ((list (nreverse (buffer-list))) - found) - (while (and (not found) list) - (let ((buffer (car list))) - (if (and (not (get-buffer-window buffer)) - (not (string-match "\\` " (buffer-name buffer)))) - (setq found buffer))) - (setq list (cdr list))) - (switch-to-buffer found))) + (let ((buffer (last-buffer (current-buffer) t)) + (bbl (frame-parameter nil 'buried-buffer-list))) + (switch-to-buffer buffer) + ;; Clean up buried-buffer-list up to and including the chosen buffer. + (while (and bbl (not (eq (car bbl) buffer))) + (setq bbl (cdr bbl))) + (set-frame-parameter nil 'buried-buffer-list bbl))) + ;;; next-error support framework -- 2.39.2