diff options
| author | Richard M. Stallman | 1993-05-12 21:41:56 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-05-12 21:41:56 +0000 |
| commit | 8b86c9ebbffd33f158d64ea4402ddbfddacc493a (patch) | |
| tree | 22f44e705b0ded5154469de8474056f8038c283a | |
| parent | 34291cd2f705f6b50838fcb4e6429cb5441d0610 (diff) | |
| download | emacs-8b86c9ebbffd33f158d64ea4402ddbfddacc493a.tar.gz emacs-8b86c9ebbffd33f158d64ea4402ddbfddacc493a.zip | |
(default-menubar): Make initial value nil.
(kill-this-buffer, x-new-frame)
(sensitize-file-and-edit-menus-hook, format-buffers-menu-line)
(buffers-menu-max-size, complex-buffers-menu-p)
(buffers-menu-switch-to-buffer-function, buffer-menu-save-buffer)
(buffer-menu-write-file, build-buffers-menu-internal)
(build-buffers-menu-hook): Functions and variables deleted.
| -rw-r--r-- | lisp/emacs-lisp/lmenu.el | 261 |
1 files changed, 4 insertions, 257 deletions
diff --git a/lisp/emacs-lisp/lmenu.el b/lisp/emacs-lisp/lmenu.el index 8d41d541ff6..dc108c14b00 100644 --- a/lisp/emacs-lisp/lmenu.el +++ b/lisp/emacs-lisp/lmenu.el | |||
| @@ -138,60 +138,10 @@ The syntax, more precisely: | |||
| 138 | (setq cmd (lookup-key menu (vector answer))) | 138 | (setq cmd (lookup-key menu (vector answer))) |
| 139 | (if cmd (call-interactively cmd)))) | 139 | (if cmd (call-interactively cmd)))) |
| 140 | 140 | ||
| 141 | (defconst default-menubar | 141 | ;; This is empty because the usual elements of the menu bar |
| 142 | '(("File" ["New Frame" x-new-frame t] | 142 | ;; are provided by menu-bar.el instead. |
| 143 | ["Open File..." find-file t] | 143 | ;; It would not make sense to duplicate them here. |
| 144 | ["Save Buffer" save-buffer t nil] | 144 | (defconst default-menubar nil) |
| 145 | ["Save Buffer As..." write-file t] | ||
| 146 | ["Revert Buffer" revert-buffer t nil] | ||
| 147 | "-----" | ||
| 148 | ["Print Buffer" lpr-buffer t nil] | ||
| 149 | "-----" | ||
| 150 | ["Delete Frame" delete-frame t] | ||
| 151 | ;; ["Kill Buffer..." kill-buffer t] | ||
| 152 | ["Kill Buffer" kill-this-buffer t nil] | ||
| 153 | ["Exit Emacs" save-buffers-kill-emacs t] | ||
| 154 | ) | ||
| 155 | ("Edit" ["Undo" advertised-undo t] | ||
| 156 | ["Cut" x-kill-primary-selection t] | ||
| 157 | ["Copy" x-copy-primary-selection t] | ||
| 158 | ["Paste" x-yank-clipboard-selection t] | ||
| 159 | ["Clear" x-delete-primary-selection t] | ||
| 160 | ) | ||
| 161 | ("Buffers" "") | ||
| 162 | |||
| 163 | nil ; the partition: menus after this are flushright | ||
| 164 | |||
| 165 | ("Help" ["Info" info t] | ||
| 166 | ["Describe Mode" describe-mode t] | ||
| 167 | ["Command Apropos..." command-apropos t] | ||
| 168 | ["List Keybindings" describe-bindings t] | ||
| 169 | ["Describe Key..." describe-key t] | ||
| 170 | ["Describe Function..." describe-function t] | ||
| 171 | ["Describe Variable..." describe-variable t] | ||
| 172 | "-----" | ||
| 173 | ["Man..." manual-entry t] | ||
| 174 | ["Emacs Tutorial" help-with-tutorial t] | ||
| 175 | ["Emacs News" view-emacs-news t] | ||
| 176 | ) | ||
| 177 | )) | ||
| 178 | |||
| 179 | |||
| 180 | (defun kill-this-buffer () ; for the menubar | ||
| 181 | "Kills the current buffer." | ||
| 182 | (interactive) | ||
| 183 | (kill-buffer (current-buffer))) | ||
| 184 | |||
| 185 | (defun x-new-frame (&optional frame-name) | ||
| 186 | "Creates a new Emacs frame (that is, a new X window.)" | ||
| 187 | (interactive) | ||
| 188 | (select-frame (x-create-frame | ||
| 189 | (append (if frame-name | ||
| 190 | (list (cons 'name frame-name)) | ||
| 191 | nil) | ||
| 192 | frame-default-alist))) | ||
| 193 | (switch-to-buffer (get-buffer-create "*scratch*")) | ||
| 194 | ) | ||
| 195 | 145 | ||
| 196 | (defun set-menubar (menubar) | 146 | (defun set-menubar (menubar) |
| 197 | "Set the default menubar to be menubar." | 147 | "Set the default menubar to be menubar." |
| @@ -422,209 +372,6 @@ BEFORE, if provided, is the name of a menu before which this menu should | |||
| 422 | 372 | ||
| 423 | (defvar put-buffer-names-in-file-menu t) | 373 | (defvar put-buffer-names-in-file-menu t) |
| 424 | 374 | ||
| 425 | (defun sensitize-file-and-edit-menus-hook () | ||
| 426 | "For use as a value of activate-menubar-hook. | ||
| 427 | This function changes the sensitivity of these File and Edit menu items: | ||
| 428 | |||
| 429 | Cut sensitive only when emacs owns the primary X Selection. | ||
| 430 | Copy sensitive only when emacs owns the primary X Selection. | ||
| 431 | Clear sensitive only when emacs owns the primary X Selection. | ||
| 432 | Paste sensitive only when there is an owner for the X Clipboard Selection. | ||
| 433 | Undo sensitive only when there is undo information. | ||
| 434 | While in the midst of an undo, this is changed to \"Undo More\". | ||
| 435 | |||
| 436 | Kill Buffer has the name of the current buffer appended to it. | ||
| 437 | Print Buffer has the name of the current buffer appended to it. | ||
| 438 | Save Buffer has the name of the current buffer appended to it, and is | ||
| 439 | sensitive only when the current buffer is modified. | ||
| 440 | Revert Buffer has the name of the current buffer appended to it, and is | ||
| 441 | sensitive only when the current buffer has a file. | ||
| 442 | Delete Frame sensitive only when there is more than one visible frame." | ||
| 443 | ;; | ||
| 444 | ;; the hair in here to not update the menubar unless something has changed | ||
| 445 | ;; isn't really necessary (the menubar code is fast enough) but it makes | ||
| 446 | ;; me feel better (and creates marginally less list garbage.) | ||
| 447 | (let* ((file-menu (cdr (car (find-menu-item current-menubar '("File"))))) | ||
| 448 | (edit-menu (cdr (car (find-menu-item current-menubar '("Edit"))))) | ||
| 449 | (save (car (find-menu-item file-menu '("Save Buffer")))) | ||
| 450 | (rvt (car (find-menu-item file-menu '("Revert Buffer")))) | ||
| 451 | (del (car (find-menu-item file-menu '("Delete Frame")))) | ||
| 452 | (print (car (find-menu-item file-menu '("Print Buffer")))) | ||
| 453 | (kill (car (find-menu-item file-menu '("Kill Buffer")))) | ||
| 454 | (cut (car (find-menu-item edit-menu '("Cut")))) | ||
| 455 | (copy (car (find-menu-item edit-menu '("Copy")))) | ||
| 456 | (paste (car (find-menu-item edit-menu '("Paste")))) | ||
| 457 | (clear (car (find-menu-item edit-menu '("Clear")))) | ||
| 458 | (undo (or (car (find-menu-item edit-menu '("Undo"))) | ||
| 459 | (car (find-menu-item edit-menu '("Undo More"))))) | ||
| 460 | (name (buffer-name)) | ||
| 461 | (emacs-owns-selection-p (x-selection-owner-p)) | ||
| 462 | (clipboard-exists-p (x-selection-exists-p 'CLIPBOARD)) | ||
| 463 | undo-available undoing-more | ||
| 464 | (undo-info-available (not (null (and (not (eq t buffer-undo-list)) | ||
| 465 | (if (eq last-command 'undo) | ||
| 466 | (setq undoing-more | ||
| 467 | (and (boundp 'pending-undo-list) | ||
| 468 | pending-undo-list) | ||
| 469 | buffer-undo-list)))))) | ||
| 470 | undo-name undo-state | ||
| 471 | (change-p | ||
| 472 | (or (and cut (not (eq emacs-owns-selection-p (aref cut 2)))) | ||
| 473 | (and copy (not (eq emacs-owns-selection-p (aref copy 2)))) | ||
| 474 | (and clear (not (eq emacs-owns-selection-p (aref clear 2)))) | ||
| 475 | (and paste (not (eq clipboard-exists-p (aref paste 2)))) | ||
| 476 | (and save (not (eq (buffer-modified-p) (aref save 2)))) | ||
| 477 | (and rvt (not (eq (not (not buffer-file-name)) (aref rvt 2)))) | ||
| 478 | (and del (not (eq (null (cdr (visible-frame-list))) (aref del 2)))) | ||
| 479 | ))) | ||
| 480 | (if (not put-buffer-names-in-file-menu) | ||
| 481 | nil | ||
| 482 | (if (= (length save) 4) (progn (aset save 3 name) (setq change-p t))) | ||
| 483 | (if (= (length rvt) 4) (progn (aset rvt 3 name) (setq change-p t))) | ||
| 484 | (if (= (length print) 4) (progn (aset print 3 name) (setq change-p t))) | ||
| 485 | (if (= (length kill) 4) (progn (aset kill 3 name) (setq change-p t)))) | ||
| 486 | (if save (aset save 2 (buffer-modified-p))) | ||
| 487 | (if rvt (aset rvt 2 (not (not buffer-file-name)))) | ||
| 488 | (if del (aset del 2 (null (cdr (visible-frame-list))))) | ||
| 489 | (if cut (aset cut 2 emacs-owns-selection-p)) | ||
| 490 | (if copy (aset copy 2 emacs-owns-selection-p)) | ||
| 491 | (if clear (aset clear 2 emacs-owns-selection-p)) | ||
| 492 | (if paste (aset paste 2 clipboard-exists-p)) | ||
| 493 | |||
| 494 | ;; we could also do this with the third field of the item. | ||
| 495 | (if (eq last-command 'undo) | ||
| 496 | (setq undo-name "Undo More" | ||
| 497 | undo-state (not (null (and (boundp 'pending-undo-list) | ||
| 498 | pending-undo-list)))) | ||
| 499 | (setq undo-name "Undo" | ||
| 500 | undo-state (and (not (eq buffer-undo-list t)) | ||
| 501 | (not (null | ||
| 502 | (or buffer-undo-list | ||
| 503 | (and (boundp 'pending-undo-list) | ||
| 504 | pending-undo-list))))))) | ||
| 505 | (if buffer-read-only (setq undo-state nil)) | ||
| 506 | (if (and undo | ||
| 507 | (or (not (equal undo-name (aref undo 0))) | ||
| 508 | (not (eq undo-state (aref undo 2))))) | ||
| 509 | (progn (aset undo 0 undo-name) | ||
| 510 | (aset undo 2 undo-state) | ||
| 511 | (setq change-p t))) | ||
| 512 | ;; if we made any changes, return nil | ||
| 513 | ;; otherwise return t to indicate that we haven't done anything. | ||
| 514 | (not change-p))) | ||
| 515 | |||
| 516 | ;; this version is too slow | ||
| 517 | (defun format-buffers-menu-line (buffer) | ||
| 518 | "Returns a string to represent the given buffer in the Buffer menu. | ||
| 519 | nil means the buffer shouldn't be listed. You can redefine this." | ||
| 520 | (if (string-match "\\` " (buffer-name buffer)) | ||
| 521 | nil | ||
| 522 | (save-excursion | ||
| 523 | (set-buffer buffer) | ||
| 524 | (let ((size (buffer-size))) | ||
| 525 | (format "%s%s %-19s %6s %-15s %s" | ||
| 526 | (if (buffer-modified-p) "*" " ") | ||
| 527 | (if buffer-read-only "%" " ") | ||
| 528 | (buffer-name) | ||
| 529 | size | ||
| 530 | mode-name | ||
| 531 | (or (buffer-file-name) "")))))) | ||
| 532 | |||
| 533 | (defun format-buffers-menu-line (buffer) | ||
| 534 | (if (string-match "\\` " (setq buffer (buffer-name buffer))) | ||
| 535 | nil | ||
| 536 | buffer)) | ||
| 537 | |||
| 538 | (defvar buffers-menu-max-size 10 | ||
| 539 | "*Maximum number of entries which may appear on the \"Buffers\" menu. | ||
| 540 | If this is 10, then only the ten most-recently-selected buffers will be | ||
| 541 | shown. If this is nil, then all buffers will be shown. Setting this to | ||
| 542 | a large number or nil will slow down menu responsiveness.") | ||
| 543 | |||
| 544 | (defvar complex-buffers-menu-p nil | ||
| 545 | "*If true, the buffers menu will contain several commands, as submenus | ||
| 546 | of each buffer line. If this is false, then there will be only one command: | ||
| 547 | select that buffer.") | ||
| 548 | |||
| 549 | (defvar buffers-menu-switch-to-buffer-function 'switch-to-buffer | ||
| 550 | "*The function to call to select a buffer from the buffers menu. | ||
| 551 | `switch-to-buffer' is a good choice, as is `pop-to-buffer'.") | ||
| 552 | |||
| 553 | |||
| 554 | (defun buffer-menu-save-buffer (buffer) | ||
| 555 | (save-excursion | ||
| 556 | (set-buffer buffer) | ||
| 557 | (save-buffer))) | ||
| 558 | |||
| 559 | (defun buffer-menu-write-file (buffer) | ||
| 560 | (save-excursion | ||
| 561 | (set-buffer buffer) | ||
| 562 | (write-file (read-file-name | ||
| 563 | (concat "Write " (buffer-name (current-buffer)) | ||
| 564 | " to file: "))))) | ||
| 565 | |||
| 566 | |||
| 567 | (defsubst build-buffers-menu-internal (buffers) | ||
| 568 | (let (name line) | ||
| 569 | (mapcar | ||
| 570 | (if complex-buffers-menu-p | ||
| 571 | (function | ||
| 572 | (lambda (buffer) | ||
| 573 | (if (setq line (format-buffers-menu-line buffer)) | ||
| 574 | (list line | ||
| 575 | (vector "Switch to Buffer" | ||
| 576 | (list buffers-menu-switch-to-buffer-function | ||
| 577 | (setq name (buffer-name buffer))) | ||
| 578 | t) | ||
| 579 | (if (and (buffer-modified-p buffer) | ||
| 580 | (buffer-file-name buffer)) | ||
| 581 | (vector "Save Buffer" | ||
| 582 | (list 'buffer-menu-save-buffer name) t) | ||
| 583 | ["Save Buffer" nil nil]) | ||
| 584 | (vector "Save Buffer As..." | ||
| 585 | (list 'buffer-menu-write-file name) t) | ||
| 586 | (vector "Kill Buffer" (list 'kill-buffer name) t))))) | ||
| 587 | (function (lambda (buffer) | ||
| 588 | (if (setq line (format-buffers-menu-line buffer)) | ||
| 589 | (vector line | ||
| 590 | (list buffers-menu-switch-to-buffer-function | ||
| 591 | (buffer-name buffer)) | ||
| 592 | t))))) | ||
| 593 | buffers))) | ||
| 594 | |||
| 595 | (defun build-buffers-menu-hook () | ||
| 596 | "For use as a value of activate-menubar-hook. | ||
| 597 | This function changes the contents of the \"Buffers\" menu to correspond | ||
| 598 | to the current set of buffers. Only the most-recently-used few buffers | ||
| 599 | will be listed on the menu, for efficiency reasons. You can control how | ||
| 600 | many buffers will be shown by setting `buffers-menu-max-size'. | ||
| 601 | You can control the text of the menu items by redefining the function | ||
| 602 | `format-buffers-menu-line'." | ||
| 603 | (let ((buffer-menu (car (find-menu-item current-menubar '("Buffers")))) | ||
| 604 | name | ||
| 605 | buffers) | ||
| 606 | (if (not buffer-menu) | ||
| 607 | nil | ||
| 608 | (setq buffers (buffer-list)) | ||
| 609 | |||
| 610 | (if (and (integerp buffers-menu-max-size) | ||
| 611 | (> buffers-menu-max-size 1)) | ||
| 612 | (if (> (length buffers) buffers-menu-max-size) | ||
| 613 | (setcdr (nthcdr buffers-menu-max-size buffers) nil))) | ||
| 614 | |||
| 615 | (setq buffers (build-buffers-menu-internal buffers)) | ||
| 616 | (setq buffers (nconc (delq nil buffers) | ||
| 617 | '("----" ["List All Buffers" list-buffers t]))) | ||
| 618 | ;; slightly (only slightly) more efficient to not install the menubar | ||
| 619 | ;; if it hasn't visibly changed. | ||
| 620 | (if (equal buffers (cdr buffer-menu)) | ||
| 621 | t ; return t meaning "no change" | ||
| 622 | (setcdr buffer-menu buffers) | ||
| 623 | (set-menubar-dirty-flag) | ||
| 624 | nil)))) | ||
| 625 | |||
| 626 | (add-hook 'activate-menubar-hook 'build-buffers-menu-hook) | ||
| 627 | (add-hook 'activate-menubar-hook 'sensitize-file-and-edit-menus-hook) | ||
| 628 | 375 | ||
| 629 | (let ((frames (frame-list))) | 376 | (let ((frames (frame-list))) |
| 630 | (while frames | 377 | (while frames |