home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34exe.zip
/
mutt
/
package
/
buf-menu.mut
< prev
next >
Wrap
Lisp/Scheme
|
1995-01-14
|
11KB
|
417 lines
;; Buffer menu main function and support functions.
;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY. No author or distributor accepts responsibility to anyone
;; for the consequences of using it or for whether it serves any particular
;; purpose or works at all, unless he says so in writing. Refer to the GNU
;; Emacs General Public License for full details.
;; Everyone is granted permission to copy, modify and redistribute GNU
;; Emacs, but only under the conditions described in the GNU Emacs General
;; Public License. A copy of this license is supposed to have been given
;; to you along with GNU Emacs so you can know your rights and
;; responsibilities. It should be in a file named COPYING. Among other
;; things, the copyright notice and this notice must be preserved on all
;; copies.
;; Ported to Mutt 11/92 by C Durland
;; Added read-only stuff 7/93
(include me.mh)
; Put buffer *Buffer List* into proper mode right away
; so that from now on even list-buffers is enough to get a buffer menu.
(int Buffer-menu-mode-map)
(defun MAIN
{
(small-int i)
(Buffer-menu-mode-map (create-keymap))
; (suppress-keymap Buffer-menu-mode-map t)
(bind-key Buffer-menu-mode-map
"Buffer-menu-select" "q"
"Buffer-menu-2-window" "2"
"Buffer-menu-1-window" "1"
"Buffer-menu-this-window" "f"
"Buffer-menu-other-window" "o"
"Buffer-menu-save" "s"
"Buffer-menu-delete" "d"
"Buffer-menu-delete" "k"
"Buffer-menu-delete-backwards" "C-d"
"Buffer-menu-delete" "C-k"
"Buffer-menu-execute" "x"
"next-line" " "
"Buffer-menu-backup-unmark" "C-?"
"Buffer-menu-backup-unmark" "C-h"
"Buffer-menu-not-modified" "~"
"Buffer-menu-unmark" "u"
"Buffer-menu-mark" "m"
"Buffer-menu-doc" "?"
"Buffer-menu-toggle-hidden" "h"
"next-line" "j"
"previous-line" "k"
"next-character" "l"
"next-line" "C-m")
})
;; Buffer Menu mode is suitable only for specially formatted data.
;(put 'Buffer-menu-mode 'mode-class 'special)
;; Precisely,{Buffer-menu-mode-map}
(defun Buffer-menu-mode HIDDEN
{
; (setq truncate-lines t)
(buffer-read-only TRUE)
(install-keymap NULL-KEYMAP LOCAL-KEYMAP) ;;!!!???
(clear-modes) ;;!!!???
(install-keymap Buffer-menu-mode-map LOCAL-KEYMAP)
(major-mode "Buffer Menu")
(if (pgm-exists "buffer-menu-mode-hook") (floc "buffer-menu-mode-hook"()))
})
(defun
Buffer-menu-doc
{
(menu-box
">Major mode for editing a list of buffers."
">Each line describes one of the buffers in Emacs."
"Letters do not insert themselves; instead, they are commands."
"m -- Mark buffer to be displayed."
"q -- Select buffer of line point is on."
" Also show buffers marked with m in other windows."
"1 -- Select this buffer in full-screen window."
; "2 -- Select this buffer in one window, together with buffer"
; " selected before this one in another window."
"f -- Select this buffer in place of the buffer menu buffer."
"o -- Put this buffer in another window, so the buffer"
" menu buffer remains visible in its window."
"~ -- Clear modified-flag on this buffer."
"s -- Mark this buffer to be saved and move down."
"d or k -- Mark this buffer to be deleted and move down."
"C-d -- Mark this buffer to be deleted and move up."
"h -- Toggle buffer hidden flag."
"x -- Delete or save marked buffers."
"u -- Remove all kinds of marks from current line."
"Backspace or Delete -- Back up a line and remove marks."
)
}
)
;; Make a menu of buffers so you can save, delete or select them.
;; ???With argument, show only buffers that are visiting files.
;; Type ? after invocation to get help on commands available.
;; ???Type q immediately to make the buffer menu go away.
(defun buffer-menu
{
(current-window (list-buffers))
(Buffer-menu-mode)
(msg
"Commands: d, s, x; 1, m, u, q; backspace, delete; ~, h; ? for help.")
})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; Routines dependent on list-buffers (bstats.mut) ;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(const
Buffer-menu-buffer-column 14 ;; Buffer names column in *buffer-list*
Buffer-menu-mod-column 2 ;; The "M" column
Buffer-menu-hidden-column 5 ;; The "h" column
)
;; Return buffer described by this line of buffer menu.
;; Output:
;; buffer id
;; -2
(defun Buffer-menu-buffer (bool error-if-non-existent-p) HIDDEN
{
(bool match)
(int bid col)
(col (current-column))
(current-column Buffer-menu-buffer-column)
(match (looking-at '\([^ ]+\)\ '))
(current-column col)
(if match
(if (!= -2 (bid (attached-buffer (get-matched '\1'))))
{ bid (done) }))
(if error-if-non-existent-p
{ (msg "No buffer named \"" (if match (get-matched '\1') "") "\"") (halt) })
-2
})
(defun
ding HIDDEN { (beep) }
looking-at-header HIDDEN
{
(bool no-data)
(int col)
(col (current-column))
(no-data FALSE)
(beginning-of-line)
(if (or
(looking-at "Flags")
(looking-at '----- ----')
(looking-at '\ +\d+')
(looking-at '\ *$'))
(no-data TRUE))
(current-column col)
no-data
}
change-char-in-col (int col) (string to) HIDDEN
{
(int ccol)
(ccol (current-column))
(current-column col)
(buffer-read-only FALSE)
(delete-character)
(insert-text to)
(buffer-read-only TRUE)
(current-column ccol)
}
change-to (string to) HIDDEN { (change-char-in-col 1 to) }
change-mod (string to) HIDDEN
{ (change-char-in-col Buffer-menu-mod-column to) }
find-selected (string what) HIDDEN
{
(search-forward (concat "^J" what))
}
restore-mod (int bid) HIDDEN
{
(change-mod
(if (!= 0 (bit-and BFNoCare (buffer-flags bid)))
"."
(if (buffer-modified bid) "M" "-")))
}
)
;; Toggle hidden bit on the buffer on this line
(defun Buffer-menu-toggle-hidden
{
(bool hidden)
(int bid)
(hidden (!= 0
(bit-and BFHidden2 (buffer-flags (bid (Buffer-menu-buffer TRUE))))))
(if hidden
(unhide-buffer (buffer-name bid))
(buffer-flags bid (bit-or BFHidden2 (buffer-flags bid))))
(change-char-in-col Buffer-menu-hidden-column (if hidden "-" "h"))
(next-line)
})
;; Mark buffer on this line for being displayed by [Buffer-menu-select]
;; command.
(defun Buffer-menu-mark
{
(if (looking-at-header)
(ding)
{
(change-to ">")
(next-line)
})
})
;; Cancel all requested operations on buffer on this line.
(defun Buffer-menu-unmark
{
(int buf)
(if (looking-at-header)
(ding)
{
(restore-mod (Buffer-menu-buffer TRUE))
(change-to " ")
})
(next-line)
})
;; Move up and cancel all requested operations on buffer on line above.
(defun Buffer-menu-backup-unmark
{
(previous-line)
(Buffer-menu-unmark)
(previous-line)
})
;; Mark buffer on this line to be deleted by \\[Buffer-menu-execute] command.
(defun Buffer-menu-delete
{
(if (looking-at-header)
(ding)
{
(change-to "D")
(next-line)
})
})
;; Mark buffer on this line to be deleted by [Buffer-menu-execute]
;; command and then move up one line
(defun Buffer-menu-delete-backwards
{
(Buffer-menu-delete)
(arg-prefix -2)(next-line)
(if (looking-at-header) (next-line))
})
;; Mark buffer on this line to be saved by [Buffer-menu-execute] command.
(defun Buffer-menu-save
{
(if (looking-at-header)
(ding)
{
(change-mod "S")
(next-line)
})
})
;; Mark buffer on this line as unmodified (no changes to save).
(defun Buffer-menu-not-modified
{
(int buf)
(buffer-modified (buf (Buffer-menu-buffer TRUE)) FALSE)
(restore-mod buf)
})
;; Save and/or delete buffers marked with [Buffer-menu-save] or
;; [Buffer-menu-delete] commands.
(defun Buffer-menu-execute
{
(bool modp)
(int buff-menu-buffer buf cb mark)
(set-mark (mark (create-mark)))
(buff-menu-buffer (current-buffer))
(beginning-of-buffer)
(forward-line 2)
(while (re-search-forward '^.S') ;;!!!
{
(current-buffer (buf (Buffer-menu-buffer TRUE)))
(save-buffer)
(modp (buffer-modified -1)) ;; in case save didn't (eg no file name)
(current-buffer buff-menu-buffer)
(restore-mod buf)
})
(beginning-of-buffer)
(forward-line 1)
(while (find-selected "D")
{
(buf (Buffer-menu-buffer FALSE))
(if (and (!= buf -2)(!= buf buff-menu-buffer))
(delete-buffer (buffer-name buf)))
(if (!= -2 (Buffer-menu-buffer FALSE)) ;; wasn't able to delete buffer
(change-to " ")
{
(beginning-of-line)(set-mark)(forward-line 1)
(buffer-read-only FALSE)(delete-region)(buffer-read-only TRUE)
(forward-char -1) ;; backup for (find-selected)
})
})
(goto-mark mark)
})
;; Select this line's buffer; also display buffers marked with ">". You
;; can mark buffers with the [Buffer-menu-mark] command.
(defun Buffer-menu-select
{
(int buff tem n)
(list others)
(buff (Buffer-menu-buffer TRUE))
(beginning-of-buffer)
(while (find-selected ">")
{
(tem (Buffer-menu-buffer TRUE))
(change-to " ")
(if (!= tem buff) (insert-object others 1000 tem))
})
(tem (/ (- (screen-length) 2) (+ 1 (length-of others))))
(delete-other-windows)
(current-buffer buff TRUE)
(n 0)
(while (!= 0 (length-of others))
{
(split-window)
(window-height n tem)
(current-window (+= n 1)) ;; because split-window can be weird pre ME3
(current-buffer (extract-element others 0) TRUE)
(remove-elements others 0 1)
})
(current-window 0) ; back to the beginning!
})
;; Select this line's buffer, alone, in full screen.
(defun Buffer-menu-1-window
{
(current-buffer (Buffer-menu-buffer TRUE) TRUE)
(delete-other-windows)
})
;; Select this line's buffer in this window.
(defun Buffer-menu-this-window
{
(current-buffer (Buffer-menu-buffer TRUE) TRUE)
})
;; Select this line's buffer in other window, leaving buffer menu visible.
(defun Buffer-menu-other-window
{
(current-window (popup-buffer (Buffer-menu-buffer TRUE)))
})
;; Select this line's buffer, with previous buffer in second window.
(defun Buffer-menu-2-window
{
(msg "Not implemented")
; (int buff menu)
;
; (buff (Buffer-menu-buffer TRUE))
; (menu (current-buffer))
; (pop-up-windows t))
; (switch-to-buffer (other-buffer))
; (pop-to-buffer buff)
; (bury-buffer menu))
})