diff options
author | Ted Zlatanov <tzz@lifelogs.com> | 2013-06-05 10:26:50 -0400 |
---|---|---|
committer | Ted Zlatanov <tzz@lifelogs.com> | 2013-06-05 10:26:50 -0400 |
commit | 3ca0d0b437e006f7b83b92b2d4fe99eeafcb9adf (patch) | |
tree | 0b81e651c8d88dfd5a9784693a67b7d276c04fbb /lisp/progmodes | |
parent | 3caa391f0abbddadb08170667a6b10ff08070575 (diff) | |
download | emacs-3ca0d0b437e006f7b83b92b2d4fe99eeafcb9adf.tar.gz |
Symbol prettify in prog-mode; added to perl-mode, cfengine3-mode, and emacs-lisp-mode.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r-- | lisp/progmodes/cfengine.el | 19 | ||||
-rw-r--r-- | lisp/progmodes/perl-mode.el | 68 |
2 files changed, 44 insertions, 43 deletions
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'." ;; Doze path separators. (modify-syntax-entry ?\\ "." table)) +(defconst cfengine3--prettify-symbols-alist + '(("->" . ?→) + ("=>" . ?⇒) + ("::" . ?∷))) + +(defvar cfengine3--augmented-font-lock-keywords) + ;;;###autoload (define-derived-mode cfengine3-mode prog-mode "CFE3" "Major mode for editing CFEngine3 input. @@ -538,8 +545,18 @@ to the action header." (cfengine-common-syntax cfengine3-mode-syntax-table) (set (make-local-variable 'indent-line-function) #'cfengine3-indent-line) + + ;; Define the symbols to be prettified + (setq-local prog-prettify-symbols-alist cfengine3--prettify-symbols-alist) + + ;; Tell font-lock.el how to handle cfengine3 keywords.. + (setq cfengine3--augmented-font-lock-keywords + (append cfengine3-font-lock-keywords + (prog-prettify-font-lock-symbols-keywords))) + (setq font-lock-defaults - '(cfengine3-font-lock-keywords nil nil nil beginning-of-defun)) + '(cfengine3--augmented-font-lock-keywords + nil nil nil beginning-of-defun)) ;; Use defuns as the essential syntax block. (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 @@ ;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and ;; Jim Campbell <jec@murzim.ca.boeing.com>. -(defcustom perl-prettify-symbols t - "If non-nil, some symbols will be displayed using Unicode chars." - :version "24.4" - :type 'boolean) - (defconst perl--prettify-symbols-alist - '(;;("andalso" . ?∧) ("orelse" . ?∨) ("as" . ?≡)("not" . ?¬) - ;;("div" . ?÷) ("*" . ?×) ("o" . ?○) - ("->" . ?→) + '(("->" . ?→) ("=>" . ?⇒) - ;;("<-" . ?←) ("<>" . ?≠) (">=" . ?≥) ("<=" . ?≤) ("..." . ?⋯) - ("::" . ?∷) - )) - -(defun perl--font-lock-compose-symbol () - "Compose a sequence of ascii chars into a symbol. -Regexp match data 0 points to the chars." - ;; Check that the chars should really be composed into a symbol. - (let* ((start (match-beginning 0)) - (end (match-end 0)) - (syntaxes (if (eq (char-syntax (char-after start)) ?w) - '(?w) '(?. ?\\)))) - (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes) - (memq (char-syntax (or (char-after end) ?\ )) syntaxes) - (nth 8 (syntax-ppss))) - ;; No composition for you. Let's actually remove any composition - ;; we may have added earlier and which is now incorrect. - (remove-text-properties start end '(composition)) - ;; That's a symbol alright, so add the composition. - (compose-region start end (cdr (assoc (match-string 0) - perl--prettify-symbols-alist))))) - ;; Return nil because we're not adding any face property. - nil) - -(defun perl--font-lock-symbols-keywords () - (when perl-prettify-symbols - `((,(regexp-opt (mapcar 'car perl--prettify-symbols-alist) t) - (0 (perl--font-lock-compose-symbol)))))) + ("::" . ?∷))) (defconst perl-font-lock-keywords-1 '(;; What is this for? @@ -243,13 +209,17 @@ Regexp match data 0 points to the chars." ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'. ("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?" (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) - ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face) - ,@(perl--font-lock-symbols-keywords))) + ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face))) "Gaudy level highlighting for Perl mode.") (defvar perl-font-lock-keywords perl-font-lock-keywords-1 "Default expressions to highlight in Perl mode.") +;; Temporary variables used to add font-lock keywords dynamically. +(defvar perl--augmented-font-lock-keywords) +(defvar perl--augmented-font-lock-keywords-1) +(defvar perl--augmented-font-lock-keywords-2) + (defvar perl-quote-like-pairs '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}) (?\< . ?\>))) @@ -685,11 +655,25 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'." (setq-local comment-start-skip "\\(^\\|\\s-\\);?#+ *") (setq-local comment-indent-function #'perl-comment-indent) (setq-local parse-sexp-ignore-comments t) + + ;; Define the symbols to be prettified. + (setq-local prog-prettify-symbols-alist perl--prettify-symbols-alist) + ;; Tell font-lock.el how to handle Perl. - (setq font-lock-defaults '((perl-font-lock-keywords - perl-font-lock-keywords-1 - perl-font-lock-keywords-2) - nil nil ((?\_ . "w")) nil + (setq perl--augmented-font-lock-keywords + (append perl-font-lock-keywords + (prog-prettify-font-lock-symbols-keywords))) + (setq perl--augmented-font-lock-keywords-1 + (append perl-font-lock-keywords-1 + (prog-prettify-font-lock-symbols-keywords))) + (setq perl--augmented-font-lock-keywords-2 + (append perl-font-lock-keywords-2 + (prog-prettify-font-lock-symbols-keywords))) + + (setq font-lock-defaults '((perl--augmented-font-lock-keywords + perl--augmented-font-lock-keywords-1 + perl--augmented-font-lock-keywords-2) + nil nil ((?\_ . "w")) nil (font-lock-syntactic-face-function . perl-font-lock-syntactic-face-function))) (setq-local syntax-propertize-function #'perl-syntax-propertize-function) |