diff options
| -rw-r--r-- | lisp/progmodes/prog-mode.el | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el index 994eaaf926f..b8cd9d93912 100644 --- a/lisp/progmodes/prog-mode.el +++ b/lisp/progmodes/prog-mode.el | |||
| @@ -133,26 +133,41 @@ Each element looks like (SYMBOL . CHARACTER), where the symbol | |||
| 133 | matching SYMBOL (a string, not a regexp) will be shown as | 133 | matching SYMBOL (a string, not a regexp) will be shown as |
| 134 | CHARACTER instead.") | 134 | CHARACTER instead.") |
| 135 | 135 | ||
| 136 | (defun prettify-symbols-default-compose-p (start end _match) | ||
| 137 | "Return true iff the symbol MATCH should be composed. | ||
| 138 | The symbol starts at position START and ends at position END. | ||
| 139 | This is default `prettify-symbols-compose-predicate' which is | ||
| 140 | suitable for most programming languages such as C or Lisp." | ||
| 141 | ;; Check that the chars should really be composed into a symbol. | ||
| 142 | (let* ((syntaxes-beg (if (memq (char-syntax (char-after start)) '(?w ?_)) | ||
| 143 | '(?w ?_) '(?. ?\\))) | ||
| 144 | (syntaxes-end (if (memq (char-syntax (char-before end)) '(?w ?_)) | ||
| 145 | '(?w ?_) '(?. ?\\)))) | ||
| 146 | (not (or (memq (char-syntax (or (char-before start) ?\s)) syntaxes-beg) | ||
| 147 | (memq (char-syntax (or (char-after end) ?\s)) syntaxes-end) | ||
| 148 | (nth 8 (syntax-ppss)))))) | ||
| 149 | |||
| 150 | (defvar-local prettify-symbols-compose-predicate | ||
| 151 | #'prettify-symbols-default-compose-p | ||
| 152 | "A predicate deciding if the currently matched symbol is to be composed. | ||
| 153 | The matched symbol is the car of one entry in `prettify-symbols-alist'. | ||
| 154 | The predicate receives the match's start and end position as well | ||
| 155 | as the match-string as arguments.") | ||
| 156 | |||
| 136 | (defun prettify-symbols--compose-symbol (alist) | 157 | (defun prettify-symbols--compose-symbol (alist) |
| 137 | "Compose a sequence of characters into a symbol. | 158 | "Compose a sequence of characters into a symbol. |
| 138 | Regexp match data 0 points to the chars." | 159 | Regexp match data 0 points to the chars." |
| 139 | ;; Check that the chars should really be composed into a symbol. | 160 | ;; Check that the chars should really be composed into a symbol. |
| 140 | (let* ((start (match-beginning 0)) | 161 | (let ((start (match-beginning 0)) |
| 141 | (end (match-end 0)) | 162 | (end (match-end 0)) |
| 142 | (syntaxes-beg (if (memq (char-syntax (char-after start)) '(?w ?_)) | 163 | (match (match-string 0))) |
| 143 | '(?w ?_) '(?. ?\\))) | 164 | (if (funcall prettify-symbols-compose-predicate start end match) |
| 144 | (syntaxes-end (if (memq (char-syntax (char-before end)) '(?w ?_)) | 165 | ;; That's a symbol alright, so add the composition. |
| 145 | '(?w ?_) '(?. ?\\))) | 166 | (compose-region start end (cdr (assoc match alist))) |
| 146 | match) | 167 | ;; No composition for you. Let's actually remove any |
| 147 | (if (or (memq (char-syntax (or (char-before start) ?\s)) syntaxes-beg) | 168 | ;; composition we may have added earlier and which is now |
| 148 | (memq (char-syntax (or (char-after end) ?\s)) syntaxes-end) | 169 | ;; incorrect. |
| 149 | ;; syntax-ppss could modify the match data (bug#14595) | 170 | (remove-text-properties start end '(composition)))) |
| 150 | (progn (setq match (match-string 0)) (nth 8 (syntax-ppss)))) | ||
| 151 | ;; No composition for you. Let's actually remove any composition | ||
| 152 | ;; we may have added earlier and which is now incorrect. | ||
| 153 | (remove-text-properties start end '(composition)) | ||
| 154 | ;; That's a symbol alright, so add the composition. | ||
| 155 | (compose-region start end (cdr (assoc match alist))))) | ||
| 156 | ;; Return nil because we're not adding any face property. | 171 | ;; Return nil because we're not adding any face property. |
| 157 | nil) | 172 | nil) |
| 158 | 173 | ||