aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog26
-rw-r--r--lisp/emacs-lisp/lisp-mode.el23
-rw-r--r--lisp/progmodes/cfengine.el19
-rw-r--r--lisp/progmodes/perl-mode.el68
-rw-r--r--lisp/simple.el42
5 files changed, 133 insertions, 45 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 14ac40dee5b..b82b07fa303 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,29 @@
12013-06-05 Teodor Zlatanov <tzz@lifelogs.com>
2
3 Generalize symbol prettify support to prog-mode and implement it
4 for perl-mode, cfengine3-mode, and emacs-lisp-mode.
5 * simple.el (prog-prettify-symbols-alist, prog-prettify-symbols)
6 (prog--prettify-font-lock-compose-symbol)
7 (prog-prettify-font-lock-symbols-keywords): New variables and
8 functions to support symbol prettification.
9 * emacs-lisp/lisp-mode.el (lisp--augmented-font-lock-keywords)
10 (lisp--augmented-font-lock-keywords-1)
11 (lisp--augmented-font-lock-keywords-2, lisp-mode-variables)
12 (lisp--prettify-symbols-alist): Implement prettify of lambda.
13 * progmodes/cfengine.el (cfengine3--augmented-font-lock-keywords)
14 (cfengine3--prettify-symbols-alist, cfengine3-mode): Implement
15 prettify of -> => :: strings.
16 * progmodes/perl-mode.el (perl-prettify-symbols)
17 (perl--font-lock-compose-symbol)
18 (perl--font-lock-symbols-keywords): Move to prog-mode.
19 (perl--prettify-symbols-alist): Prettify -> => :: strings.
20 (perl-font-lock-keywords-1)
21 (perl-font-lock-keywords-2): Remove explicit prettify support.
22 (perl--augmented-font-lock-keywords)
23 (perl--augmented-font-lock-keywords-1)
24 (perl--augmented-font-lock-keywords-2, perl-mode): Implement
25 prettify support.
26
12013-06-05 Leo Liu <sdl.web@gmail.com> 272013-06-05 Leo Liu <sdl.web@gmail.com>
2 28
3 Re-implement smie matching block highlight using 29 Re-implement smie matching block highlight using
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 02b020fa241..6e1f8291771 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -187,6 +187,11 @@ It has `lisp-mode-abbrev-table' as its parent."
187 font-lock-string-face)))) 187 font-lock-string-face))))
188 font-lock-comment-face)) 188 font-lock-comment-face))
189 189
190;; Temporary variables used to add font-lock keywords dynamically.
191(defvar lisp--augmented-font-lock-keywords)
192(defvar lisp--augmented-font-lock-keywords-1)
193(defvar lisp--augmented-font-lock-keywords-2)
194
190(defun lisp-mode-variables (&optional lisp-syntax keywords-case-insensitive) 195(defun lisp-mode-variables (&optional lisp-syntax keywords-case-insensitive)
191 "Common initialization routine for lisp modes. 196 "Common initialization routine for lisp modes.
192The LISP-SYNTAX argument is used by code in inf-lisp.el and is 197The LISP-SYNTAX argument is used by code in inf-lisp.el and is
@@ -223,9 +228,20 @@ font-lock keywords will not be case sensitive."
223 (setq-local imenu-generic-expression lisp-imenu-generic-expression) 228 (setq-local imenu-generic-expression lisp-imenu-generic-expression)
224 (setq-local multibyte-syntax-as-symbol t) 229 (setq-local multibyte-syntax-as-symbol t)
225 (setq-local syntax-begin-function 'beginning-of-defun) 230 (setq-local syntax-begin-function 'beginning-of-defun)
231 (setq-local prog-prettify-symbols-alist lisp--prettify-symbols-alist)
232 (setq lisp--augmented-font-lock-keywords
233 (append lisp-font-lock-keywords
234 (prog-prettify-font-lock-symbols-keywords)))
235 (setq lisp--augmented-font-lock-keywords-1
236 (append lisp-font-lock-keywords-1
237 (prog-prettify-font-lock-symbols-keywords)))
238 (setq lisp--augmented-font-lock-keywords-2
239 (append lisp-font-lock-keywords-2
240 (prog-prettify-font-lock-symbols-keywords)))
226 (setq font-lock-defaults 241 (setq font-lock-defaults
227 `((lisp-font-lock-keywords 242 `((lisp--augmented-font-lock-keywords
228 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) 243 lisp--augmented-font-lock-keywords-1
244 lisp--augmented-font-lock-keywords-2)
229 nil ,keywords-case-insensitive nil nil 245 nil ,keywords-case-insensitive nil nil
230 (font-lock-mark-block-function . mark-defun) 246 (font-lock-mark-block-function . mark-defun)
231 (font-lock-syntactic-face-function 247 (font-lock-syntactic-face-function
@@ -448,6 +464,9 @@ All commands in `lisp-mode-shared-map' are inherited by this map.")
448 :type 'hook 464 :type 'hook
449 :group 'lisp) 465 :group 'lisp)
450 466
467(defconst lisp--prettify-symbols-alist
468 '(("lambda" . ?λ)))
469
451(define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp" 470(define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp"
452 "Major mode for editing Lisp code to run in Emacs. 471 "Major mode for editing Lisp code to run in Emacs.
453Commands: 472Commands:
diff --git a/lisp/progmodes/cfengine.el b/lisp/progmodes/cfengine.el
index 11eb0eeaf49..88177a8db10 100644
--- a/lisp/progmodes/cfengine.el
+++ b/lisp/progmodes/cfengine.el
@@ -527,6 +527,13 @@ Intended as the value of `indent-line-function'."
527 ;; Doze path separators. 527 ;; Doze path separators.
528 (modify-syntax-entry ?\\ "." table)) 528 (modify-syntax-entry ?\\ "." table))
529 529
530(defconst cfengine3--prettify-symbols-alist
531 '(("->" . ?→)
532 ("=>" . ?⇒)
533 ("::" . ?∷)))
534
535(defvar cfengine3--augmented-font-lock-keywords)
536
530;;;###autoload 537;;;###autoload
531(define-derived-mode cfengine3-mode prog-mode "CFE3" 538(define-derived-mode cfengine3-mode prog-mode "CFE3"
532 "Major mode for editing CFEngine3 input. 539 "Major mode for editing CFEngine3 input.
@@ -538,8 +545,18 @@ to the action header."
538 (cfengine-common-syntax cfengine3-mode-syntax-table) 545 (cfengine-common-syntax cfengine3-mode-syntax-table)
539 546
540 (set (make-local-variable 'indent-line-function) #'cfengine3-indent-line) 547 (set (make-local-variable 'indent-line-function) #'cfengine3-indent-line)
548
549 ;; Define the symbols to be prettified
550 (setq-local prog-prettify-symbols-alist cfengine3--prettify-symbols-alist)
551
552 ;; Tell font-lock.el how to handle cfengine3 keywords..
553 (setq cfengine3--augmented-font-lock-keywords
554 (append cfengine3-font-lock-keywords
555 (prog-prettify-font-lock-symbols-keywords)))
556
541 (setq font-lock-defaults 557 (setq font-lock-defaults
542 '(cfengine3-font-lock-keywords nil nil nil beginning-of-defun)) 558 '(cfengine3--augmented-font-lock-keywords
559 nil nil nil beginning-of-defun))
543 560
544 ;; Use defuns as the essential syntax block. 561 ;; Use defuns as the essential syntax block.
545 (set (make-local-variable 'beginning-of-defun-function) 562 (set (make-local-variable 'beginning-of-defun-function)
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 01ac8584e19..fb3839a5fbc 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -158,44 +158,10 @@
158;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and 158;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and
159;; Jim Campbell <jec@murzim.ca.boeing.com>. 159;; Jim Campbell <jec@murzim.ca.boeing.com>.
160 160
161(defcustom perl-prettify-symbols t
162 "If non-nil, some symbols will be displayed using Unicode chars."
163 :version "24.4"
164 :type 'boolean)
165
166(defconst perl--prettify-symbols-alist 161(defconst perl--prettify-symbols-alist
167 '(;;("andalso" . ?∧) ("orelse" . ?∨) ("as" . ?≡)("not" . ?¬) 162 '(("->" . ?→)
168 ;;("div" . ?÷) ("*" . ?×) ("o" . ?○)
169 ("->" . ?→)
170 ("=>" . ?⇒) 163 ("=>" . ?⇒)
171 ;;("<-" . ?←) ("<>" . ?≠) (">=" . ?≥) ("<=" . ?≤) ("..." . ?⋯) 164 ("::" . ?∷)))
172 ("::" . ?∷)
173 ))
174
175(defun perl--font-lock-compose-symbol ()
176 "Compose a sequence of ascii chars into a symbol.
177Regexp match data 0 points to the chars."
178 ;; Check that the chars should really be composed into a symbol.
179 (let* ((start (match-beginning 0))
180 (end (match-end 0))
181 (syntaxes (if (eq (char-syntax (char-after start)) ?w)
182 '(?w) '(?. ?\\))))
183 (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
184 (memq (char-syntax (or (char-after end) ?\ )) syntaxes)
185 (nth 8 (syntax-ppss)))
186 ;; No composition for you. Let's actually remove any composition
187 ;; we may have added earlier and which is now incorrect.
188 (remove-text-properties start end '(composition))
189 ;; That's a symbol alright, so add the composition.
190 (compose-region start end (cdr (assoc (match-string 0)
191 perl--prettify-symbols-alist)))))
192 ;; Return nil because we're not adding any face property.
193 nil)
194
195(defun perl--font-lock-symbols-keywords ()
196 (when perl-prettify-symbols
197 `((,(regexp-opt (mapcar 'car perl--prettify-symbols-alist) t)
198 (0 (perl--font-lock-compose-symbol))))))
199 165
200(defconst perl-font-lock-keywords-1 166(defconst perl-font-lock-keywords-1
201 '(;; What is this for? 167 '(;; What is this for?
@@ -243,13 +209,17 @@ Regexp match data 0 points to the chars."
243 ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'. 209 ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'.
244 ("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?" 210 ("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?"
245 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) 211 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
246 ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face) 212 ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face)))
247 ,@(perl--font-lock-symbols-keywords)))
248 "Gaudy level highlighting for Perl mode.") 213 "Gaudy level highlighting for Perl mode.")
249 214
250(defvar perl-font-lock-keywords perl-font-lock-keywords-1 215(defvar perl-font-lock-keywords perl-font-lock-keywords-1
251 "Default expressions to highlight in Perl mode.") 216 "Default expressions to highlight in Perl mode.")
252 217
218;; Temporary variables used to add font-lock keywords dynamically.
219(defvar perl--augmented-font-lock-keywords)
220(defvar perl--augmented-font-lock-keywords-1)
221(defvar perl--augmented-font-lock-keywords-2)
222
253(defvar perl-quote-like-pairs 223(defvar perl-quote-like-pairs
254 '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}) (?\< . ?\>))) 224 '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}) (?\< . ?\>)))
255 225
@@ -685,11 +655,25 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
685 (setq-local comment-start-skip "\\(^\\|\\s-\\);?#+ *") 655 (setq-local comment-start-skip "\\(^\\|\\s-\\);?#+ *")
686 (setq-local comment-indent-function #'perl-comment-indent) 656 (setq-local comment-indent-function #'perl-comment-indent)
687 (setq-local parse-sexp-ignore-comments t) 657 (setq-local parse-sexp-ignore-comments t)
658
659 ;; Define the symbols to be prettified.
660 (setq-local prog-prettify-symbols-alist perl--prettify-symbols-alist)
661
688 ;; Tell font-lock.el how to handle Perl. 662 ;; Tell font-lock.el how to handle Perl.
689 (setq font-lock-defaults '((perl-font-lock-keywords 663 (setq perl--augmented-font-lock-keywords
690 perl-font-lock-keywords-1 664 (append perl-font-lock-keywords
691 perl-font-lock-keywords-2) 665 (prog-prettify-font-lock-symbols-keywords)))
692 nil nil ((?\_ . "w")) nil 666 (setq perl--augmented-font-lock-keywords-1
667 (append perl-font-lock-keywords-1
668 (prog-prettify-font-lock-symbols-keywords)))
669 (setq perl--augmented-font-lock-keywords-2
670 (append perl-font-lock-keywords-2
671 (prog-prettify-font-lock-symbols-keywords)))
672
673 (setq font-lock-defaults '((perl--augmented-font-lock-keywords
674 perl--augmented-font-lock-keywords-1
675 perl--augmented-font-lock-keywords-2)
676 nil nil ((?\_ . "w")) nil
693 (font-lock-syntactic-face-function 677 (font-lock-syntactic-face-function
694 . perl-font-lock-syntactic-face-function))) 678 . perl-font-lock-syntactic-face-function)))
695 (setq-local syntax-propertize-function #'perl-syntax-propertize-function) 679 (setq-local syntax-propertize-function #'perl-syntax-propertize-function)
diff --git a/lisp/simple.el b/lisp/simple.el
index 18a360faa61..2564645e42c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -397,9 +397,51 @@ instead."
397 "Major mode for editing programming language source code." 397 "Major mode for editing programming language source code."
398 (set (make-local-variable 'require-final-newline) mode-require-final-newline) 398 (set (make-local-variable 'require-final-newline) mode-require-final-newline)
399 (set (make-local-variable 'parse-sexp-ignore-comments) t) 399 (set (make-local-variable 'parse-sexp-ignore-comments) t)
400 (make-local-variable 'prog-prettify-symbols-alist)
400 ;; Any programming language is always written left to right. 401 ;; Any programming language is always written left to right.
401 (setq bidi-paragraph-direction 'left-to-right)) 402 (setq bidi-paragraph-direction 'left-to-right))
402 403
404(defvar prog-prettify-symbols-alist nil)
405
406(defcustom prog-prettify-symbols nil
407 "Whether symbols should be prettified.
408When set to an alist in the form `(STRING . CHARACTER)' it will
409augment the mode's native prettify alist."
410 :type '(choice
411 (const :tag "No thanks" nil)
412 (const :tag "Mode defaults" t)
413 (alist :tag "Mode defaults augmented with your own list"
414 :key-type string :value-type character))
415 :group 'languages)
416
417(defun prog--prettify-font-lock-compose-symbol (alist)
418 "Compose a sequence of ascii chars into a symbol.
419Regexp match data 0 points to the chars."
420 ;; Check that the chars should really be composed into a symbol.
421 (let* ((start (match-beginning 0))
422 (end (match-end 0))
423 (syntaxes (if (eq (char-syntax (char-after start)) ?w)
424 '(?w) '(?. ?\\))))
425 (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
426 (memq (char-syntax (or (char-after end) ?\ )) syntaxes)
427 (nth 8 (syntax-ppss)))
428 ;; No composition for you. Let's actually remove any composition
429 ;; we may have added earlier and which is now incorrect.
430 (remove-text-properties start end '(composition))
431 ;; That's a symbol alright, so add the composition.
432 (compose-region start end (cdr (assoc (match-string 0) alist)))))
433 ;; Return nil because we're not adding any face property.
434 nil)
435
436(defun prog-prettify-font-lock-symbols-keywords ()
437 (when prog-prettify-symbols
438 (let ((alist (append prog-prettify-symbols-alist
439 (if (listp prog-prettify-symbols)
440 prog-prettify-symbols
441 nil))))
442 `((,(regexp-opt (mapcar 'car alist) t)
443 (0 (prog--prettify-font-lock-compose-symbol ',alist)))))))
444
403;; Making and deleting lines. 445;; Making and deleting lines.
404 446
405(defvar hard-newline (propertize "\n" 'hard t 'rear-nonsticky '(hard)) 447(defvar hard-newline (propertize "\n" 'hard t 'rear-nonsticky '(hard))