diff options
| author | Juanma Barranquero | 2013-06-19 00:13:25 +0200 |
|---|---|---|
| committer | Juanma Barranquero | 2013-06-19 00:13:25 +0200 |
| commit | 14dd22d2cedad0e1babcce0fea868a0c01294fa2 (patch) | |
| tree | 49f91c1cf89ab6ea0dcc92234bb6988d62d404d5 | |
| parent | ec9295aeaa0ca3616507b66bd6e2f81dce05e820 (diff) | |
| download | emacs-14dd22d2cedad0e1babcce0fea868a0c01294fa2.tar.gz emacs-14dd22d2cedad0e1babcce0fea868a0c01294fa2.zip | |
Convert symbol prettification into minor mode and global minor mode.
* etc/NEWS: Document new Prettify Symbols mode.
* lisp/progmodes/prog-mode.el (prettify-symbols-alist): Rename from
`prog-prettify-symbols', and make a local defvar instead of defcustom.
(prettify-symbols--keywords): Rename from `prog-prettify-symbols-alist'
and make a local defvar.
(prettify-symbols--compose-symbol): Rename from
`prog--prettify-font-lock-compose-symbol'.
(prettify-symbols--make-keywords): Rename from
`prog-prettify-font-lock-symbols-keywords' and simplify.
(prog-prettify-install): Remove.
(prettify-symbols-mode): New minor mode, based on `prog-prettify-install'.
(turn-on-prettify-symbols-mode): New function.
(global-prettify-symbols-mode): New globalized minor mode.
* lisp/emacs-lisp/lisp-mode.el (lisp-mode-variables):
* lisp/progmodes/cfengine.el (cfengine3-mode):
* lisp/progmodes/perl-mode.el (perl-mode): Don't call `prog-prettify-install';
set `prettify-symbols-alist' instead.
| -rw-r--r-- | etc/ChangeLog | 4 | ||||
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/cfengine.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/perl-mode.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/prog-mode.el | 99 |
7 files changed, 96 insertions, 44 deletions
diff --git a/etc/ChangeLog b/etc/ChangeLog index 1892d5fbb58..676e67860cc 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2013-06-18 Juanma Barranquero <lekktu@gmail.com> | ||
| 2 | |||
| 3 | * NEWS: Document new Prettify Symbols mode. | ||
| 4 | |||
| 1 | 2013-06-14 Stefan Monnier <monnier@iro.umontreal.ca> | 5 | 2013-06-14 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 6 | ||
| 3 | * NEWS (utf-8 for el): Move to the incompatible section. | 7 | * NEWS (utf-8 for el): Move to the incompatible section. |
| @@ -2873,10 +2873,10 @@ should be derived. | |||
| 2873 | modes, e.g. (add-hook 'prog-mode-hook 'flyspell-prog-mode) to enable | 2873 | modes, e.g. (add-hook 'prog-mode-hook 'flyspell-prog-mode) to enable |
| 2874 | on-the-fly spell checking for comments and strings. | 2874 | on-the-fly spell checking for comments and strings. |
| 2875 | 2875 | ||
| 2876 | **** New option, `prog-prettify-symbols' lets the user control symbol | 2876 | **** New minor modes `prettify-symbols-mode' and |
| 2877 | prettify (replacing a string like "lambda" with the Greek lambda | 2877 | `global-prettify-symbols-mode' let the user enable symbol |
| 2878 | character). The mode derived from `prog-mode' must call | 2878 | prettification (replacing a string like "lambda" with the Greek lambda |
| 2879 | `prog-prettify-install' with its own custom alist, which can be empty. | 2879 | character). |
| 2880 | 2880 | ||
| 2881 | *** New hook `change-major-mode-after-body-hook', run by | 2881 | *** New hook `change-major-mode-after-body-hook', run by |
| 2882 | `run-mode-hooks' just before any other mode hooks. | 2882 | `run-mode-hooks' just before any other mode hooks. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index abd9e9da3ae..44d8a2a82bd 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2013-06-18 Juanma Barranquero <lekktu@gmail.com> | ||
| 2 | |||
| 3 | Convert symbol prettification into minor mode and global minor mode. | ||
| 4 | |||
| 5 | * progmodes/prog-mode.el (prettify-symbols-alist): Rename from | ||
| 6 | `prog-prettify-symbols', and make a local defvar instead of defcustom. | ||
| 7 | (prettify-symbols--keywords): Rename from | ||
| 8 | `prog-prettify-symbols-alist' and make a local defvar. | ||
| 9 | (prettify-symbols--compose-symbol): Rename from | ||
| 10 | `prog--prettify-font-lock-compose-symbol'. | ||
| 11 | (prettify-symbols--make-keywords): Rename from | ||
| 12 | `prog-prettify-font-lock-symbols-keywords' and simplify. | ||
| 13 | (prog-prettify-install): Remove. | ||
| 14 | (prettify-symbols-mode): New minor mode, based on | ||
| 15 | `prog-prettify-install'. | ||
| 16 | (turn-on-prettify-symbols-mode): New function. | ||
| 17 | (global-prettify-symbols-mode): New globalized minor mode. | ||
| 18 | |||
| 19 | * emacs-lisp/lisp-mode.el (lisp-mode-variables): | ||
| 20 | * progmodes/cfengine.el (cfengine3-mode): | ||
| 21 | * progmodes/perl-mode.el (perl-mode): Don't call | ||
| 22 | `prog-prettify-install'; set `prettify-symbols-alist' instead. | ||
| 23 | |||
| 1 | 2013-06-18 Juri Linkov <juri@jurta.org> | 24 | 2013-06-18 Juri Linkov <juri@jurta.org> |
| 2 | 25 | ||
| 3 | * files-x.el (modify-file-local-variable-message): New function. | 26 | * files-x.el (modify-file-local-variable-message): New function. |
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index b8e12b63061..af30deca4cc 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -231,7 +231,7 @@ font-lock keywords will not be case sensitive." | |||
| 231 | (font-lock-mark-block-function . mark-defun) | 231 | (font-lock-mark-block-function . mark-defun) |
| 232 | (font-lock-syntactic-face-function | 232 | (font-lock-syntactic-face-function |
| 233 | . lisp-font-lock-syntactic-face-function))) | 233 | . lisp-font-lock-syntactic-face-function))) |
| 234 | (prog-prettify-install lisp--prettify-symbols-alist)) | 234 | (setq-local prettify-symbols-alist lisp--prettify-symbols-alist)) |
| 235 | 235 | ||
| 236 | (defun lisp-outline-level () | 236 | (defun lisp-outline-level () |
| 237 | "Lisp mode `outline-level' function." | 237 | "Lisp mode `outline-level' function." |
diff --git a/lisp/progmodes/cfengine.el b/lisp/progmodes/cfengine.el index 01b5faef5b3..55d5b8b0be7 100644 --- a/lisp/progmodes/cfengine.el +++ b/lisp/progmodes/cfengine.el | |||
| @@ -547,7 +547,7 @@ to the action header." | |||
| 547 | (setq font-lock-defaults | 547 | (setq font-lock-defaults |
| 548 | '(cfengine3-font-lock-keywords | 548 | '(cfengine3-font-lock-keywords |
| 549 | nil nil nil beginning-of-defun)) | 549 | nil nil nil beginning-of-defun)) |
| 550 | (prog-prettify-install cfengine3--prettify-symbols-alist) | 550 | (setq-local prettify-symbols-alist cfengine3--prettify-symbols-alist) |
| 551 | 551 | ||
| 552 | ;; Use defuns as the essential syntax block. | 552 | ;; Use defuns as the essential syntax block. |
| 553 | (set (make-local-variable 'beginning-of-defun-function) | 553 | (set (make-local-variable 'beginning-of-defun-function) |
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index 1d5052bede4..8955c64aa9e 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el | |||
| @@ -658,7 +658,7 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'." | |||
| 658 | nil nil ((?\_ . "w")) nil | 658 | nil nil ((?\_ . "w")) nil |
| 659 | (font-lock-syntactic-face-function | 659 | (font-lock-syntactic-face-function |
| 660 | . perl-font-lock-syntactic-face-function))) | 660 | . perl-font-lock-syntactic-face-function))) |
| 661 | (prog-prettify-install perl--prettify-symbols-alist) | 661 | (setq-local prettify-symbols-alist perl--prettify-symbols-alist) |
| 662 | (setq-local syntax-propertize-function #'perl-syntax-propertize-function) | 662 | (setq-local syntax-propertize-function #'perl-syntax-propertize-function) |
| 663 | (add-hook 'syntax-propertize-extend-region-functions | 663 | (add-hook 'syntax-propertize-extend-region-functions |
| 664 | #'syntax-propertize-multiline 'append 'local) | 664 | #'syntax-propertize-multiline 'append 'local) |
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el index 6498ba51e45..b3ed328bd72 100644 --- a/lisp/progmodes/prog-mode.el +++ b/lisp/progmodes/prog-mode.el | |||
| @@ -54,21 +54,14 @@ instead." | |||
| 54 | (end (progn (forward-sexp 1) (point)))) | 54 | (end (progn (forward-sexp 1) (point)))) |
| 55 | (indent-region start end nil)))) | 55 | (indent-region start end nil)))) |
| 56 | 56 | ||
| 57 | (defvar prog-prettify-symbols-alist nil) | 57 | (defvar-local prettify-symbols-alist nil |
| 58 | 58 | "Alist of symbol prettifications. | |
| 59 | (defcustom prog-prettify-symbols nil | 59 | Each element looks like (SYMBOL . CHARACTER), where the symbol |
| 60 | "Whether symbols should be prettified. | 60 | matching SYMBOL (a string, not a regexp) will be shown as |
| 61 | When set to an alist in the form `((STRING . CHARACTER)...)' it | 61 | CHARACTER instead.") |
| 62 | will augment the mode's native prettify alist." | 62 | |
| 63 | :type '(choice | 63 | (defun prettify-symbols--compose-symbol (alist) |
| 64 | (const :tag "No thanks" nil) | 64 | "Compose a sequence of characters into a symbol. |
| 65 | (const :tag "Mode defaults" t) | ||
| 66 | (alist :tag "Mode defaults augmented with your own list" | ||
| 67 | :key-type string :value-type character)) | ||
| 68 | :version "24.4") | ||
| 69 | |||
| 70 | (defun prog--prettify-font-lock-compose-symbol (alist) | ||
| 71 | "Compose a sequence of ascii chars into a symbol. | ||
| 72 | Regexp match data 0 points to the chars." | 65 | Regexp match data 0 points to the chars." |
| 73 | ;; Check that the chars should really be composed into a symbol. | 66 | ;; Check that the chars should really be composed into a symbol. |
| 74 | (let* ((start (match-beginning 0)) | 67 | (let* ((start (match-beginning 0)) |
| @@ -88,28 +81,60 @@ Regexp match data 0 points to the chars." | |||
| 88 | ;; Return nil because we're not adding any face property. | 81 | ;; Return nil because we're not adding any face property. |
| 89 | nil) | 82 | nil) |
| 90 | 83 | ||
| 91 | (defun prog-prettify-font-lock-symbols-keywords () | 84 | (defun prettify-symbols--make-keywords () |
| 92 | (when prog-prettify-symbols | 85 | (if prettify-symbols-alist |
| 93 | (let ((alist (append prog-prettify-symbols-alist | 86 | `((,(regexp-opt (mapcar 'car prettify-symbols-alist) t) |
| 94 | (if (listp prog-prettify-symbols) | 87 | (0 (prettify-symbols--compose-symbol ',prettify-symbols-alist)))) |
| 95 | prog-prettify-symbols | 88 | nil)) |
| 96 | nil)))) | 89 | |
| 97 | `((,(regexp-opt (mapcar 'car alist) t) | 90 | (defvar-local prettify-symbols--keywords nil) |
| 98 | (0 (prog--prettify-font-lock-compose-symbol ',alist))))))) | 91 | |
| 99 | 92 | ;;;###autoload | |
| 100 | (defun prog-prettify-install (alist) | 93 | (define-minor-mode prettify-symbols-mode |
| 101 | "Install prog-mode support to prettify symbols according to ALIST. | 94 | "Toggle Prettify Symbols mode. |
| 102 | 95 | With a prefix argument ARG, enable Prettify Symbols mode if ARG is | |
| 103 | ALIST is in the format `((STRING . CHARACTER)...)' like | 96 | positive, and disable it otherwise. If called from Lisp, enable |
| 104 | `prog-prettify-symbols'. | 97 | the mode if ARG is omitted or nil. |
| 105 | 98 | ||
| 106 | Internally, `font-lock-add-keywords' is called." | 99 | When Prettify Symbols mode and font-locking are enabled, symbols are |
| 107 | (setq-local prog-prettify-symbols-alist alist) | 100 | prettified (displayed as composed characters) according to the rules |
| 108 | (let ((keywords (prog-prettify-font-lock-symbols-keywords))) | 101 | in `prettify-symbols-alist' (which see), which are locally defined |
| 109 | (when keywords | 102 | by major modes supporting prettifying. To add further customizations |
| 110 | (font-lock-add-keywords nil keywords) | 103 | for a given major mode, you can modify `prettify-symbols-alist' thus: |
| 111 | (setq-local font-lock-extra-managed-props | 104 | |
| 112 | (cons 'composition font-lock-extra-managed-props))))) | 105 | (add-hook 'emacs-lisp-mode-hook |
| 106 | (lambda () | ||
| 107 | (push '(\"<=\" . ?≤) prettify-symbols-alist))) | ||
| 108 | |||
| 109 | You can enable this mode locally in desired buffers, or use | ||
| 110 | `global-prettify-symbols-mode' to enable it for all modes that | ||
| 111 | support it." | ||
| 112 | :init-value nil | ||
| 113 | (if prettify-symbols-mode | ||
| 114 | ;; Turn on | ||
| 115 | (when (setq prettify-symbols--keywords (prettify-symbols--make-keywords)) | ||
| 116 | (font-lock-add-keywords nil prettify-symbols--keywords) | ||
| 117 | (setq-local font-lock-extra-managed-props | ||
| 118 | (cons 'composition font-lock-extra-managed-props)) | ||
| 119 | (font-lock-fontify-buffer)) | ||
| 120 | ;; Turn off | ||
| 121 | (when prettify-symbols--keywords | ||
| 122 | (font-lock-remove-keywords nil prettify-symbols--keywords) | ||
| 123 | (setq prettify-symbols--keywords nil)) | ||
| 124 | (when (memq 'composition font-lock-extra-managed-props) | ||
| 125 | (setq font-lock-extra-managed-props (delq 'composition | ||
| 126 | font-lock-extra-managed-props)) | ||
| 127 | (with-silent-modifications | ||
| 128 | (remove-text-properties (point-min) (point-max) '(composition nil)))))) | ||
| 129 | |||
| 130 | (defun turn-on-prettify-symbols-mode () | ||
| 131 | (when (and (not prettify-symbols-mode) | ||
| 132 | (local-variable-p 'prettify-symbols-alist)) | ||
| 133 | (prettify-symbols-mode 1))) | ||
| 134 | |||
| 135 | ;;;###autoload | ||
| 136 | (define-globalized-minor-mode global-prettify-symbols-mode | ||
| 137 | prettify-symbols-mode turn-on-prettify-symbols-mode) | ||
| 113 | 138 | ||
| 114 | ;;;###autoload | 139 | ;;;###autoload |
| 115 | (define-derived-mode prog-mode fundamental-mode "Prog" | 140 | (define-derived-mode prog-mode fundamental-mode "Prog" |