diff options
| author | Po Lu | 2022-02-09 11:26:47 +0800 |
|---|---|---|
| committer | Po Lu | 2022-02-09 11:27:15 +0800 |
| commit | d41a5e7e33067eb38b147ee2f8a1615f6faed7a4 (patch) | |
| tree | 96cde35b1d35bcf68a9126605558fcc7c08b407b | |
| parent | 59ff15e3502e44d7ae7ea23cd882fc18a766d989 (diff) | |
| download | emacs-d41a5e7e33067eb38b147ee2f8a1615f6faed7a4.tar.gz emacs-d41a5e7e33067eb38b147ee2f8a1615f6faed7a4.zip | |
Improve selection of fonts available from `mouse-set-font'
People get confused on a build without font dialogs (such as a
Lucid build) if `menu-set-font' and `mouse-set-font' don't
present them a list of the fonts actually available on their
system.
* lisp/mouse.el (mouse-generate-font-name-for-menu)
(mouse-generate-font-menu): New functions.
(mouse-select-font): Allow the user to select from all fonts
available on the system.
(mouse-set-font): Use `mouse-select-font' to display font menu.
| -rw-r--r-- | lisp/mouse.el | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el index 502683d3d1e..acaf6611af5 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -2755,18 +2755,72 @@ and selects that window." | |||
| 2755 | 2755 | ||
| 2756 | (declare-function generate-fontset-menu "fontset" ()) | 2756 | (declare-function generate-fontset-menu "fontset" ()) |
| 2757 | 2757 | ||
| 2758 | (defun mouse-generate-font-name-for-menu (entity) | ||
| 2759 | "Return a short name for font entity ENTITY. | ||
| 2760 | The name should be used to describe ENTITY in the case that its | ||
| 2761 | family is already known, such as in a pane generated by | ||
| 2762 | `mouse-generate-font-menu'." | ||
| 2763 | (let ((weight (font-get entity :weight)) | ||
| 2764 | (slant (font-get entity :slant)) | ||
| 2765 | (width (font-get entity :width)) | ||
| 2766 | (size (font-get entity :size)) | ||
| 2767 | (adstyle (font-get entity :adstyle)) | ||
| 2768 | (name "")) | ||
| 2769 | (when weight | ||
| 2770 | (setq name (concat name (symbol-name weight) " "))) | ||
| 2771 | (when (and slant | ||
| 2772 | (not (eq slant 'normal))) | ||
| 2773 | (setq name (concat name (symbol-name slant) " "))) | ||
| 2774 | (when (and width (not (eq width 'normal))) | ||
| 2775 | (setq name (concat name (symbol-name width) " "))) | ||
| 2776 | (when (and size (not (zerop size))) | ||
| 2777 | (setq name (concat name (number-to-string size) " "))) | ||
| 2778 | (when adstyle | ||
| 2779 | (setq name (concat name (if (symbolp adstyle) | ||
| 2780 | (symbol-name adstyle) | ||
| 2781 | (number-to-string adstyle)) | ||
| 2782 | " "))) | ||
| 2783 | (string-trim-right name))) | ||
| 2784 | |||
| 2785 | (defun mouse-generate-font-menu () | ||
| 2786 | "Return a list of menu panes for each font family." | ||
| 2787 | (let ((families (font-family-list)) | ||
| 2788 | (panes (list "Font families"))) | ||
| 2789 | (dolist (family families) | ||
| 2790 | (when family | ||
| 2791 | (let* ((fonts (list-fonts (font-spec :family family))) | ||
| 2792 | (pane (if fonts (list family) | ||
| 2793 | (list family (cons family family))))) | ||
| 2794 | (when fonts | ||
| 2795 | (dolist (font fonts) | ||
| 2796 | (setq pane | ||
| 2797 | (nconc pane | ||
| 2798 | (list (list (or (font-get font :name) | ||
| 2799 | (mouse-generate-font-name-for-menu font)) | ||
| 2800 | (font-xlfd-name font))))))) | ||
| 2801 | (setq panes (nconc panes (list pane)))))) | ||
| 2802 | panes)) | ||
| 2803 | |||
| 2758 | (defun mouse-select-font () | 2804 | (defun mouse-select-font () |
| 2759 | "Prompt for a font name, using `x-popup-menu', and return it." | 2805 | "Prompt for a font name, using `x-popup-menu', and return it." |
| 2760 | (interactive) | 2806 | (interactive) |
| 2761 | (unless (display-multi-font-p) | 2807 | (unless (display-multi-font-p) |
| 2762 | (error "Cannot change fonts on this display")) | 2808 | (error "Cannot change fonts on this display")) |
| 2763 | (car | 2809 | (let ((result (car |
| 2764 | (x-popup-menu | 2810 | (x-popup-menu |
| 2765 | (if (listp last-nonmenu-event) | 2811 | (if (listp last-nonmenu-event) |
| 2766 | last-nonmenu-event | 2812 | last-nonmenu-event |
| 2767 | (list '(0 0) (selected-window))) | 2813 | (list '(0 0) (selected-window))) |
| 2768 | (append x-fixed-font-alist | 2814 | (append x-fixed-font-alist |
| 2769 | (list (generate-fontset-menu)))))) | 2815 | (list (generate-fontset-menu)) |
| 2816 | '(("More Fonts" ("By Family" more)))))))) | ||
| 2817 | (if (eq result 'more) | ||
| 2818 | (car (x-popup-menu | ||
| 2819 | (if (listp last-nonmenu-event) | ||
| 2820 | last-nonmenu-event | ||
| 2821 | (list '(0 0) (selected-window))) | ||
| 2822 | (mouse-generate-font-menu))) | ||
| 2823 | result))) | ||
| 2770 | 2824 | ||
| 2771 | (declare-function text-scale-mode "face-remap") | 2825 | (declare-function text-scale-mode "face-remap") |
| 2772 | 2826 | ||
| @@ -2780,12 +2834,7 @@ choose a font." | |||
| 2780 | (interactive | 2834 | (interactive |
| 2781 | (progn (unless (display-multi-font-p) | 2835 | (progn (unless (display-multi-font-p) |
| 2782 | (error "Cannot change fonts on this display")) | 2836 | (error "Cannot change fonts on this display")) |
| 2783 | (x-popup-menu | 2837 | (list (mouse-select-font)))) |
| 2784 | (if (listp last-nonmenu-event) | ||
| 2785 | last-nonmenu-event | ||
| 2786 | (list '(0 0) (selected-window))) | ||
| 2787 | ;; Append list of fontsets currently defined. | ||
| 2788 | (append x-fixed-font-alist (list (generate-fontset-menu)))))) | ||
| 2789 | (if fonts | 2838 | (if fonts |
| 2790 | (let (font) | 2839 | (let (font) |
| 2791 | (while fonts | 2840 | (while fonts |