]> code.delx.au - gnu-emacs/blobdiff - lisp/mouse.el
* term/ns-win.el (ns-alternatives-map, ns-insert-working-text)
[gnu-emacs] / lisp / mouse.el
index 8565e62edfe66a12f2d0dec4d6ce9c3fd6bece73..cdb89caeeca6547df85ba997aee563221fe09fa5 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, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: hardware, mouse
 (put 'track-mouse 'lisp-indent-function 0)
 
 (defcustom mouse-yank-at-point nil
-  "*If non-nil, mouse yank commands yank at point instead of at click."
+  "If non-nil, mouse yank commands yank at point instead of at click."
   :type 'boolean
   :group 'mouse)
 
 (defcustom mouse-drag-copy-region t
-  "*If non-nil, mouse drag copies region to kill-ring."
+  "If non-nil, mouse drag copies region to kill-ring."
   :type 'boolean
   :version "22.1"
   :group 'mouse)
@@ -81,7 +81,7 @@ packages.  See `mouse-on-link-p' for details."
   :group 'mouse)
 
 (defcustom mouse-1-click-in-non-selected-windows t
-  "*If non-nil, a Mouse-1 click also follows links in non-selected windows.
+  "If non-nil, a Mouse-1 click also follows links in non-selected windows.
 
 If nil, a Mouse-1 click on a link in a non-selected window performs
 the normal mouse-1 binding, typically selects the window and sets
@@ -419,6 +419,10 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
         (start-event-window (posn-window start))
         (start-event-frame (window-frame start-event-window))
         (start-nwindows (count-windows t))
+         (on-link (and mouse-1-click-follows-link
+                      (or mouse-1-click-in-non-selected-windows
+                          (eq (posn-window start) (selected-window)))
+                       (mouse-on-link-p start)))
         (minibuffer (frame-parameter nil 'minibuffer))
         should-enlarge-minibuffer event mouse y top bot edges wconfig growth)
     (track-mouse
@@ -491,6 +495,11 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
                            (one-window-p t))
                   (error "Attempt to resize sole window"))
 
+                 ;; If we ever move, make sure we don't mistakenly treat
+                 ;; some unexpected `mouse-1' final event as a sign that
+                 ;; this whole drag was nothing more than a click.
+                 (if (/= growth 0) (setq on-link nil))
+
                 ;; grow/shrink minibuffer?
                 (if should-enlarge-minibuffer
                     (unless resize-mini-windows
@@ -519,7 +528,14 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
                                    (nth 1 (window-edges
                                            ;; Choose right window.
                                            start-event-window)))))
-                  (set-window-configuration wconfig)))))))))
+                  (set-window-configuration wconfig)))))
+
+        ;; Presumably if this was just a click, the last event should
+        ;; be `mouse-1', whereas if this did move the mouse, it should be
+        ;; a `drag-mouse-1'.  In any case `on-link' would have been nulled
+        ;; above if there had been any significant mouse movement.
+        (when (and on-link (eq 'mouse-1 (car-safe event)))
+          (push (cons 'mouse-2 (cdr event)) unread-command-events))))))
 
 (defun mouse-drag-mode-line (start-event)
   "Change the height of a window by dragging on the mode line."
@@ -673,7 +689,7 @@ This should be bound to a mouse drag event."
     ;; If mark is highlighted, no need to bounce the cursor.
     ;; On X, we highlight while dragging, thus once again no need to bounce.
     (or transient-mark-mode
-       (memq (framep (selected-frame)) '(x pc w32 mac))
+       (memq (framep (selected-frame)) '(x pc w32 ns))
        (sit-for 1))
     (push-mark)
     (set-mark (point))
@@ -699,7 +715,7 @@ This should be bound to a mouse drag event."
   (setq mouse-last-region-tick (buffer-modified-tick)))
 
 (defcustom mouse-scroll-delay 0.25
-  "*The pause between scroll steps caused by mouse drags, in seconds.
+  "The pause between scroll steps caused by mouse drags, in seconds.
 If you drag the mouse beyond the edge of a window, Emacs scrolls the
 window to bring the text beyond that edge into view, with a delay of
 this many seconds between scroll steps.  Scrolling stops when you move
@@ -710,7 +726,7 @@ Setting this to zero causes Emacs to scroll as fast as it can."
   :group 'mouse)
 
 (defcustom mouse-scroll-min-lines 1
-  "*The minimum number of lines scrolled by dragging mouse out of window.
+  "The minimum number of lines scrolled by dragging mouse out of window.
 Moving the mouse out the top or bottom edge of the window begins
 scrolling repeatedly.  The number of lines scrolled per repetition
 is normally equal to the number of lines beyond the window edge that
@@ -1110,8 +1126,7 @@ If DIR is positive skip forward; if negative, skip backward."
           ;; Here, we can't use skip-syntax-forward/backward because
           ;; they don't pay attention to word-separating-categories,
           ;; and thus they will skip over a true word boundary.  So,
-          ;; we simularte the original behaviour by using
-          ;; forward-word.
+          ;; we simulate the original behavior by using forward-word.
           (if (< dir 0)
               (if (not (looking-at "\\<"))
                   (forward-word -1))
@@ -1800,14 +1815,14 @@ again.  If you do this twice in the same position, it kills the selection."
                            (overlay-end mouse-secondary-overlay)))))))
 \f
 (defcustom mouse-buffer-menu-maxlen 20
-  "*Number of buffers in one pane (submenu) of the buffer menu.
+  "Number of buffers in one pane (submenu) of the buffer menu.
 If we have lots of buffers, divide them into groups of
 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
   :type 'integer
   :group 'mouse)
 
 (defcustom mouse-buffer-menu-mode-mult 4
-  "*Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
+  "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
 will split the buffer menu by the major modes (see
 `mouse-buffer-menu-mode-groups') or just by menu length.
@@ -1826,7 +1841,7 @@ a large number if you prefer a mixed multitude.  The default is 4."
     ("Text" . "Text")
     ("Outline" . "Text")
     ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
-    ("log\\|diff\\|vc\\|cvs" . "Version Control") ; "Change Management"?
+    ("log\\|diff\\|vc\\|cvs\\|Annotate" . "Version Control") ; "Change Management"?
     ("Lisp" . "Lisp"))
   "How to group various major modes together in \\[mouse-buffer-menu].
 Each element has the form (REGEXP . GROUPNAME).
@@ -2425,17 +2440,22 @@ and selects that window."
     )
   "X fonts suitable for use in Emacs.")
 
+(declare-function generate-fontset-menu "fontset" ())
+
 (defun mouse-select-font ()
   "Prompt for a font name, using `x-popup-menu', and return it."
   (interactive)
   (unless (display-multi-font-p)
     (error "Cannot change fonts on this display"))
-  (x-popup-menu
-   (if (listp last-nonmenu-event)
-       last-nonmenu-event
-     (list '(0 0) (selected-window)))
-   (append x-fixed-font-alist
-          (list (generate-fontset-menu)))))
+  (car
+   (x-popup-menu
+    (if (listp last-nonmenu-event)
+       last-nonmenu-event
+      (list '(0 0) (selected-window)))
+    (append x-fixed-font-alist
+           (list (generate-fontset-menu))))))
+
+(declare-function text-scale-mode "face-remap")
 
 (defun mouse-set-font (&rest fonts)
   "Set the default font for the selected frame.
@@ -2458,13 +2478,78 @@ choose a font."
        (while fonts
          (condition-case nil
              (progn
-               (set-default-font (car fonts))
+               (set-frame-font (car fonts))
                (setq font (car fonts))
                (setq fonts nil))
            (error
             (setq fonts (cdr fonts)))))
        (if (null font)
            (error "Font not found")))))
+
+(defvar mouse-appearance-menu-map nil)
+(declare-function x-select-font "xfns.c" (&optional frame ignored)) ; USE_GTK
+(declare-function buffer-face-mode-invoke "face-remap"
+                  (face arg &optional interactive))
+(declare-function font-face-attributes "font.c" (font &optional frame))
+
+(defun mouse-appearance-menu (event)
+  (interactive "@e")
+  (require 'face-remap)
+  (when (display-multi-font-p)
+    (with-selected-window (car (event-start event))
+      (if mouse-appearance-menu-map
+         nil ; regenerate new fonts
+       ;; Initialize mouse-appearance-menu-map
+       (setq mouse-appearance-menu-map
+             (make-sparse-keymap "Change Default Buffer Face"))
+       (define-key mouse-appearance-menu-map [face-remap-reset-base]
+         '(menu-item "Reset to Default" face-remap-reset-base))
+       (define-key mouse-appearance-menu-map [text-scale-decrease]
+         '(menu-item "Decrease Buffer Text Size" text-scale-decrease))
+       (define-key mouse-appearance-menu-map [text-scale-increase]
+         '(menu-item "Increase Buffer Text Size" text-scale-increase))
+       ;; Font selector
+       (if (functionp 'x-select-font)
+           (define-key mouse-appearance-menu-map [x-select-font]
+             '(menu-item "Change Buffer Font..." x-select-font))
+         ;; If the select-font is unavailable, construct a menu.
+         (let ((font-submenu (make-sparse-keymap "Change Text Font"))
+               (font-alist (cdr (append x-fixed-font-alist
+                                        (list (generate-fontset-menu))))))
+           (dolist (family font-alist)
+             (let* ((submenu-name (car family))
+                    (submenu-map (make-sparse-keymap submenu-name)))
+               (dolist (font (cdr family))
+                 (let ((font-name (car font))
+                       font-symbol)
+                   (if (string= font-name "")
+                       (define-key submenu-map [space]
+                         '("--"))
+                     (setq font-symbol (intern (cadr font)))
+                     (define-key submenu-map (vector font-symbol)
+                       (list 'menu-item (car font) font-symbol)))))
+               (define-key font-submenu (vector (intern submenu-name))
+                 (list 'menu-item submenu-name submenu-map))))
+           (define-key mouse-appearance-menu-map [font-submenu]
+             (list 'menu-item "Change Text Font" font-submenu)))))
+      (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
+       (setq choice (nth (1- (length choice)) choice))
+       (cond ((eq choice 'text-scale-increase)
+              (text-scale-increase 1))
+             ((eq choice 'text-scale-decrease)
+              (text-scale-increase -1))
+             ((eq choice 'face-remap-reset-base)
+              (text-scale-mode 0)
+              (buffer-face-mode 0))
+             (choice
+              ;; Either choice == 'x-select-font, or choice is a
+              ;; symbol whose name is a font.
+              (buffer-face-mode-invoke (font-face-attributes
+                                        (if (eq choice 'x-select-font)
+                                            (x-select-font)
+                                          (symbol-name choice)))
+                                       t (interactive-p))))))))
+
 \f
 ;;; Bindings for mouse commands.
 
@@ -2492,7 +2577,7 @@ choose a font."
 ;; event to make the selection, saving a click.
 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
 (if (not (eq system-type 'ms-dos))
-    (global-set-key [S-down-mouse-1] 'mouse-set-font))
+    (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
 ;; C-down-mouse-2 is bound in facemenu.el.
 (global-set-key [C-down-mouse-3]
   '(menu-item "Menu Bar" ignore