Mercurial > emacs
comparison lisp/mouse.el @ 95977:d76373886395
(mouse-appearance-menu-map): New var.
(mouse-appearance-menu): New function. Bind it to S-down-mouse-1.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 15 Jun 2008 20:04:33 +0000 |
parents | b4e36ff621b3 |
children | ab77bad0093c |
comparison
equal
deleted
inserted
replaced
95976:75f86f6e4fc7 | 95977:d76373886395 |
---|---|
2437 last-nonmenu-event | 2437 last-nonmenu-event |
2438 (list '(0 0) (selected-window))) | 2438 (list '(0 0) (selected-window))) |
2439 (append x-fixed-font-alist | 2439 (append x-fixed-font-alist |
2440 (list (generate-fontset-menu))))) | 2440 (list (generate-fontset-menu))))) |
2441 | 2441 |
2442 (declare-function text-scale-mode "face-remap") | |
2443 | |
2442 (defun mouse-set-font (&rest fonts) | 2444 (defun mouse-set-font (&rest fonts) |
2443 "Set the default font for the selected frame. | 2445 "Set the default font for the selected frame. |
2444 The argument FONTS is a list of font names; the first valid font | 2446 The argument FONTS is a list of font names; the first valid font |
2445 in this list is used. | 2447 in this list is used. |
2446 | 2448 |
2465 (setq fonts nil)) | 2467 (setq fonts nil)) |
2466 (error | 2468 (error |
2467 (setq fonts (cdr fonts))))) | 2469 (setq fonts (cdr fonts))))) |
2468 (if (null font) | 2470 (if (null font) |
2469 (error "Font not found"))))) | 2471 (error "Font not found"))))) |
2472 | |
2473 (defvar mouse-appearance-menu-map nil) | |
2474 | |
2475 (defun mouse-appearance-menu (event) | |
2476 (interactive "@e") | |
2477 (require 'face-remap) | |
2478 (when (display-multi-font-p) | |
2479 (with-selected-window (car (event-start event)) | |
2480 (if mouse-appearance-menu-map | |
2481 nil ; regenerate new fonts | |
2482 ;; Initialize mouse-appearance-menu-map | |
2483 (setq mouse-appearance-menu-map | |
2484 (make-sparse-keymap "Change Default Buffer Face")) | |
2485 (define-key mouse-appearance-menu-map [face-remap-reset-base] | |
2486 '(menu-item "Reset to Default" face-remap-reset-base)) | |
2487 (define-key mouse-appearance-menu-map [text-scale-decrease] | |
2488 '(menu-item "Decrease Buffer Text Size" text-scale-decrease)) | |
2489 (define-key mouse-appearance-menu-map [text-scale-increase] | |
2490 '(menu-item "Increase Buffer Text Size" text-scale-increase)) | |
2491 ;; Font selector | |
2492 (if (functionp 'x-select-font) | |
2493 (define-key mouse-appearance-menu-map [x-select-font] | |
2494 '(menu-item "Change Buffer Font..." x-select-font)) | |
2495 ;; If the select-font is unavailable, construct a menu. | |
2496 (let ((font-submenu (make-sparse-keymap "Change Text Font")) | |
2497 (font-alist (cdr (append x-fixed-font-alist | |
2498 (list (generate-fontset-menu)))))) | |
2499 (dolist (family font-alist) | |
2500 (let* ((submenu-name (car family)) | |
2501 (submenu-map (make-sparse-keymap submenu-name))) | |
2502 (dolist (font (cdr family)) | |
2503 (let ((font-name (car font)) | |
2504 font-symbol) | |
2505 (if (string= font-name "") | |
2506 (define-key submenu-map [space] | |
2507 '("--")) | |
2508 (setq font-symbol (intern (cadr font))) | |
2509 (define-key submenu-map (vector font-symbol) | |
2510 (list 'menu-item (car font) font-symbol))))) | |
2511 (define-key font-submenu (vector (intern submenu-name)) | |
2512 (list 'menu-item submenu-name submenu-map)))) | |
2513 (define-key mouse-appearance-menu-map [font-submenu] | |
2514 (list 'menu-item "Change Text Font" font-submenu))))) | |
2515 (let ((choice (x-popup-menu event mouse-appearance-menu-map))) | |
2516 (setq choice (nth (1- (length choice)) choice)) | |
2517 (cond ((eq choice 'text-scale-increase) | |
2518 (text-scale-increase 1)) | |
2519 ((eq choice 'text-scale-decrease) | |
2520 (text-scale-increase -1)) | |
2521 ((eq choice 'face-remap-reset-base) | |
2522 (text-scale-mode 0) | |
2523 (let ((entry (assq 'default face-remapping-alist))) | |
2524 (when entry | |
2525 (setq face-remapping-alist | |
2526 (remq entry face-remapping-alist)) | |
2527 (force-window-update (current-buffer))))) | |
2528 (t | |
2529 ;; Either choice == 'x-select-font, or choice is a | |
2530 ;; symbol whose name is a font. | |
2531 (make-local-variable 'face-remapping-alist) | |
2532 (apply 'face-remap-add-relative | |
2533 'default | |
2534 (font-face-attributes | |
2535 (if (eq choice 'x-select-font) | |
2536 (x-select-font) | |
2537 (symbol-name choice)))))))))) | |
2538 | |
2470 | 2539 |
2471 ;;; Bindings for mouse commands. | 2540 ;;; Bindings for mouse commands. |
2472 | 2541 |
2473 (define-key global-map [down-mouse-1] 'mouse-drag-region) | 2542 (define-key global-map [down-mouse-1] 'mouse-drag-region) |
2474 (global-set-key [mouse-1] 'mouse-set-point) | 2543 (global-set-key [mouse-1] 'mouse-set-point) |
2492 | 2561 |
2493 ;; By binding these to down-going events, we let the user use the up-going | 2562 ;; By binding these to down-going events, we let the user use the up-going |
2494 ;; event to make the selection, saving a click. | 2563 ;; event to make the selection, saving a click. |
2495 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu) | 2564 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu) |
2496 (if (not (eq system-type 'ms-dos)) | 2565 (if (not (eq system-type 'ms-dos)) |
2497 (global-set-key [S-down-mouse-1] 'mouse-set-font)) | 2566 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu)) |
2498 ;; C-down-mouse-2 is bound in facemenu.el. | 2567 ;; C-down-mouse-2 is bound in facemenu.el. |
2499 (global-set-key [C-down-mouse-3] | 2568 (global-set-key [C-down-mouse-3] |
2500 '(menu-item "Menu Bar" ignore | 2569 '(menu-item "Menu Bar" ignore |
2501 :filter (lambda (_) | 2570 :filter (lambda (_) |
2502 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0)) | 2571 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0)) |