diff options
| author | Chong Yidong | 2008-06-15 20:04:33 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-06-15 20:04:33 +0000 |
| commit | 3db09e26fd1c332473cec81821a377c7fa53a067 (patch) | |
| tree | 22530b67278f809dca6cc45ca28018d0bc2e40e9 | |
| parent | 41d61331ec29407d6c5473a7314a71cc22c555a5 (diff) | |
| download | emacs-3db09e26fd1c332473cec81821a377c7fa53a067.tar.gz emacs-3db09e26fd1c332473cec81821a377c7fa53a067.zip | |
(mouse-appearance-menu-map): New var.
(mouse-appearance-menu): New function. Bind it to S-down-mouse-1.
| -rw-r--r-- | lisp/mouse.el | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el index 678bce2279e..7e6a9a13f93 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -2439,6 +2439,8 @@ and selects that 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 |
| @@ -2467,6 +2469,73 @@ choose a font." | |||
| 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 | ||
| @@ -2494,7 +2563,7 @@ choose a font." | |||
| 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 |