+(defcustom perl-prettify-symbols t
+ "If non-nil, some symbols will be displayed using Unicode chars."
+ :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))))))
+