]> code.delx.au - gnu-emacs/blobdiff - lisp/menu-bar.el
* lisp/macros.el (name-last-kbd-macro, kbd-macro-query)
[gnu-emacs] / lisp / menu-bar.el
index cd1a4d05b5595a4f58175a6c0ea9b4377f54cee8..a1b6d95ec0b3bc36a0433dab6702ede9f6952ace 100644 (file)
                   :enable (and (cdr yank-menu) (not buffer-read-only))
                   :help "Choose a string from the kill ring and paste it"))
     (bindings--define-key menu [paste]
-      '(menu-item "Paste" yank
-                  :enable (and (or
-                                (gui-call gui-selection-exists-p 'CLIPBOARD)
-                                (if (featurep 'ns) ; like paste-from-menu
-                                    (cdr yank-menu)
-                                  kill-ring))
-                               (not buffer-read-only))
+      `(menu-item "Paste" yank
+                  :enable (funcall
+                           ',(lambda ()
+                               (and (or
+                                     (gui-backend-selection-exists-p 'CLIPBOARD)
+                                     (if (featurep 'ns) ; like paste-from-menu
+                                         (cdr yank-menu)
+                                       kill-ring))
+                                    (not buffer-read-only))))
                   :help "Paste (yank) text most recently cut/copied"))
     (bindings--define-key menu [copy]
       ;; ns-win.el said: Substitute a Copy function that works better
      '(and mark-active (not buffer-read-only)))
 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
 (put 'clipboard-yank 'menu-enable
-     '(and (or (gui-call gui-selection-exists-p 'PRIMARY)
-              (gui-call gui-selection-exists-p 'CLIPBOARD))
-          (not buffer-read-only)))
+     `(funcall ',(lambda ()
+                   (and (or (gui-backend-selection-exists-p 'PRIMARY)
+                            (gui-backend-selection-exists-p 'CLIPBOARD))
+                        (not buffer-read-only)))))
+
+(defvar gui-select-enable-clipboard)
 
 (defun clipboard-yank ()
   "Insert the clipboard contents, or the last stretch of killed text."
@@ -1747,12 +1752,14 @@ The menu frame is the frame for which we are updating the menu."
         (frame-visible-p menu-frame))))
 
 (defun menu-bar-non-minibuffer-window-p ()
-  "Return non-nil if selected window of the menu frame is not a minibuf window.
-
-See the documentation of `menu-bar-menu-frame-live-and-visible-p'
-for the definition of the menu frame."
+  "Return non-nil if the menu frame's selected window is no minibuffer window.
+Return nil if the menu frame is dead or its selected window is a
+minibuffer window.  The menu frame is the frame for which we are
+updating the menu."
   (let ((menu-frame (or menu-updating-frame (selected-frame))))
-    (not (window-minibuffer-p (frame-selected-window menu-frame)))))
+    (and (frame-live-p menu-frame)
+        (not (window-minibuffer-p
+              (frame-selected-window menu-frame))))))
 
 (defun kill-this-buffer ()     ; for the menu bar
   "Kill the current buffer.
@@ -1947,20 +1954,20 @@ It must accept a buffer as its only required argument.")
        (let ((buffers (buffer-list))
             (frames (frame-list))
             buffers-menu)
-        ;; If requested, list only the N most recently selected buffers.
-        (if (and (integerp buffers-menu-max-size)
-                 (> buffers-menu-max-size 1))
-            (if (> (length buffers) buffers-menu-max-size)
-                (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
 
         ;; Make the menu of buffers proper.
         (setq buffers-menu
-              (let (alist)
+               (let ((i 0)
+                     (limit (if (and (integerp buffers-menu-max-size)
+                                     (> buffers-menu-max-size 1))
+                                buffers-menu-max-size most-positive-fixnum))
+                     alist)
                 ;; Put into each element of buffer-list
                 ;; the name for actual display,
                 ;; perhaps truncated in the middle.
-                (dolist (buf buffers)
-                  (let ((name (buffer-name buf)))
+                 (while buffers
+                   (let* ((buf (pop buffers))
+                          (name (buffer-name buf)))
                      (unless (eq ?\s (aref name 0))
                        (push (menu-bar-update-buffers-1
                               (cons buf
@@ -1974,7 +1981,11 @@ It must accept a buffer as its only required argument.")
                                          name (- (/ buffers-menu-buffer-name-length 2))))
                                      name)
                                     ))
-                             alist))))
+                             alist)
+                       ;; If requested, list only the N most recently
+                       ;; selected buffers.
+                       (when (= limit (setq i (1+ i)))
+                         (setq buffers nil)))))
                 (list (menu-bar-buffer-vector alist))))
 
         ;; Make a Frames menu if we have more than one frame.