(file-remote-p): Docstring fix.
[bpt/emacs.git] / lisp / mouse.el
index 82d12cc..40debbd 100644 (file)
@@ -1,7 +1,7 @@
 ;;; mouse.el --- window system-independent mouse support
 
 ;; Copyright (C) 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: hardware, mouse
@@ -192,12 +192,24 @@ Default to the Edit menu if the major mode doesn't define a menu."
         ;; Make a keymap in which our last command leads to a menu or
         ;; default to the edit menu.
         (newmap (if ancestor
-                    (make-sparse-keymap (concat mode-name " Mode"))
-                  menu-bar-edit-menu)))
+                    (make-sparse-keymap (concat (format-mode-line mode-name)
+                                                 " Mode"))
+                  menu-bar-edit-menu))
+        uniq)
     (if ancestor
        ;; Make our menu inherit from the desired keymap which we want
        ;; to display as the menu now.
-       (set-keymap-parent newmap ancestor))
+       ;; Sometimes keymaps contain duplicate menu code, leading to
+       ;; duplicates in the popped-up menu. Avoid this by simply
+       ;; taking the first of any identically-named menus.
+       ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg00469.html
+       (set-keymap-parent newmap
+                          (progn
+                            (dolist (e ancestor)
+                              (unless (and (listp e)
+                                           (assoc (car e) uniq))
+                                (setq uniq (append uniq (list e)))))
+                            uniq)))
     (popup-menu newmap event prefix)))
 
 
@@ -272,7 +284,8 @@ not it is actually displayed."
     (or (null local-menu)
        (stringp local-title-or-map)
        (setq local-menu (cons 'keymap
-                              (cons (concat mode-name " Mode Menu")
+                              (cons (concat (format-mode-line mode-name)
+                                             " Mode Menu")
                                     (cdr local-menu)))))
     (or (stringp global-title-or-map)
        (setq global-menu (cons 'keymap
@@ -1358,6 +1371,20 @@ regardless of where you click."
   (setq mouse-selection-click-count 0)
   (yank arg))
 
+(defun mouse-yank-primary (click)
+  "Insert the primary selection at the position clicked on.
+Move point to the end of the inserted text.
+If `mouse-yank-at-point' is non-nil, insert at point
+regardless of where you click."
+  (interactive "e")
+  ;; Give temporary modes such as isearch a chance to turn off.
+  (run-hooks 'mouse-leave-buffer-hook)
+  (or mouse-yank-at-point (mouse-set-point click))
+  (let ((primary (x-get-selection 'PRIMARY)))
+    (if primary
+        (insert (x-get-selection 'PRIMARY))
+      (error "No primary selection"))))
+
 (defun mouse-kill-ring-save (click)
   "Copy the region between point and the mouse click in the kill ring.
 This does not delete the region; it acts like \\[kill-ring-save]."
@@ -1847,7 +1874,7 @@ and selects that window."
             (setq elt (list adjusted-major-mode
                             (if (stringp adjusted-major-mode)
                                 adjusted-major-mode
-                                mode-name))
+                              (format-mode-line mode-name nil nil buf)))
                   split-by-major-mode (cons elt split-by-major-mode)))
           (or (memq buf (cdr (cdr elt)))
               (setcdr (cdr elt) (cons buf (cdr (cdr elt))))))))
@@ -1933,7 +1960,7 @@ and selects that window."
                  (cons
                   (cons
                    (format
-                    (format "%%%ds  %%s%%s  %%s" maxlen)
+                    (format "%%-%ds  %%s%%s  %%s" maxlen)
                     (buffer-name elt)
                     (if (buffer-modified-p elt) "*" " ")
                     (save-excursion