From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: Re: Interface of prog-prettification Date: Tue, 18 Jun 2013 01:08:13 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1371510539 7723 80.91.229.3 (17 Jun 2013 23:08:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 17 Jun 2013 23:08:59 +0000 (UTC) Cc: Ted Zlatanov , Emacs developers To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 18 01:09:00 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UoiXj-0007Hi-Vd for ged-emacs-devel@m.gmane.org; Tue, 18 Jun 2013 01:09:00 +0200 Original-Received: from localhost ([::1]:47394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoiXj-0008UO-GF for ged-emacs-devel@m.gmane.org; Mon, 17 Jun 2013 19:08:59 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoiXf-0008SR-TD for emacs-devel@gnu.org; Mon, 17 Jun 2013 19:08:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UoiXe-0000I5-Fc for emacs-devel@gnu.org; Mon, 17 Jun 2013 19:08:55 -0400 Original-Received: from mail-ee0-x22c.google.com ([2a00:1450:4013:c00::22c]:51800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoiXe-0000I1-6E for emacs-devel@gnu.org; Mon, 17 Jun 2013 19:08:54 -0400 Original-Received: by mail-ee0-f44.google.com with SMTP id c13so2151844eek.3 for ; Mon, 17 Jun 2013 16:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=Cid4ZKV+0q6Ajam1Tc6YDtIivIshCZVy3SaDjNu+x7U=; b=CE88hZej4Dv17nJebSp70KsPjmzKBocNTRpLfF8IohLi8qXpZOB9e3ItCvLHK1QkgF XVF61+ruZtSVXDBl0F4CoIgc39uEmnsR1oHsjuUebSg7uGA3l4sPZlCsJQQpCshsZ3uf QZrhIQ9gF1R7zbXwhIwthUnLdtCyX2CUCt+KG+9fY0ilV1B44L8u5YzmygwgKXMOJOrk QlbtuR9rMsq6Mvo2PsN7t06vtOFfXZZGbloMwcfxqeb6/zsK60bIYEzPRRk7H7vYr0FF mgRVXVGfqscqfvAyz8aR82i4fB+L2UCZDTJHZn4rpvx/omzHFmBm9RiQ6sYQ1FgNmhsc uMug== X-Received: by 10.15.36.133 with SMTP id i5mr19446262eev.52.1371510533323; Mon, 17 Jun 2013 16:08:53 -0700 (PDT) Original-Received: by 10.14.142.4 with HTTP; Mon, 17 Jun 2013 16:08:13 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::22c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160538 Archived-At: On Mon, Jun 17, 2013 at 6:27 PM, Stefan Monnier wrote: > Accident, mostly. Feel free to make it into a minor mode. > > The important part is that the actual symbols to handle vary > between languages (e.g. mapping \ to =CE=BB makes sense for Haskell, but = not > for most other languages). On Mon, Jun 17, 2013 at 9:13 PM, Ted Zlatanov wrote: > But it would work as a > minor mode, sure. If you'd like to implement it that way, feel free. > Just remove the old defcustom and whatever else you don't need anymore. Without ChangeLogs (and prettify-symbols-mode is still in prog-mode.el, though it is not really prog-mode specific). =3D=3D=3D modified file 'etc/NEWS' --- etc/NEWS 2013-06-17 15:28:22 +0000 +++ etc/NEWS 2013-06-17 22:33:14 +0000 @@ -2873,10 +2873,9 @@ modes, e.g. (add-hook 'prog-mode-hook 'flyspell-prog-mode) to enable on-the-fly spell checking for comments and strings. -**** New option, `prog-prettify-symbols' lets the user control symbol -prettify (replacing a string like "lambda" with the Greek lambda -character). The mode derived from `prog-mode' must call -`prog-prettify-install' with its own custom alist, which can be empty. +**** New minor mode, `prettify-symbols-mode', lets the user enable +symbol prettification (replacing a string like "lambda" with the Greek +lambda character). *** New hook `change-major-mode-after-body-hook', run by `run-mode-hooks' just before any other mode hooks. =3D=3D=3D modified file 'lisp/emacs-lisp/lisp-mode.el' --- lisp/emacs-lisp/lisp-mode.el 2013-06-15 09:16:49 +0000 +++ lisp/emacs-lisp/lisp-mode.el 2013-06-17 22:53:23 +0000 @@ -231,7 +231,7 @@ (font-lock-mark-block-function . mark-defun) (font-lock-syntactic-face-function . lisp-font-lock-syntactic-face-function))) - (prog-prettify-install lisp--prettify-symbols-alist)) + (setq prettify-symbols-alist lisp--prettify-symbols-alist)) (defun lisp-outline-level () "Lisp mode `outline-level' function." =3D=3D=3D modified file 'lisp/progmodes/cfengine.el' --- lisp/progmodes/cfengine.el 2013-06-05 17:48:50 +0000 +++ lisp/progmodes/cfengine.el 2013-06-17 22:53:51 +0000 @@ -547,7 +547,7 @@ (setq font-lock-defaults '(cfengine3-font-lock-keywords nil nil nil beginning-of-defun)) - (prog-prettify-install cfengine3--prettify-symbols-alist) + (setq prettify-symbols-alist cfengine3--prettify-symbols-alist) ;; Use defuns as the essential syntax block. (set (make-local-variable 'beginning-of-defun-function) =3D=3D=3D modified file 'lisp/progmodes/perl-mode.el' --- lisp/progmodes/perl-mode.el 2013-06-05 17:48:50 +0000 +++ lisp/progmodes/perl-mode.el 2013-06-17 22:52:38 +0000 @@ -658,7 +658,7 @@ nil nil ((?\_ . "w")) nil (font-lock-syntactic-face-function . perl-font-lock-syntactic-face-function))) - (prog-prettify-install perl--prettify-symbols-alist) + (setq prettify-symbols-alist perl--prettify-symbols-alist) (setq-local syntax-propertize-function #'perl-syntax-propertize-function= ) (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline 'append 'local) =3D=3D=3D modified file 'lisp/progmodes/prog-mode.el' --- lisp/progmodes/prog-mode.el 2013-06-17 01:09:13 +0000 +++ lisp/progmodes/prog-mode.el 2013-06-17 23:07:03 +0000 @@ -54,21 +54,14 @@ (end (progn (forward-sexp 1) (point)))) (indent-region start end nil)))) -(defvar prog-prettify-symbols-alist nil) - -(defcustom prog-prettify-symbols nil - "Whether symbols should be prettified. -When set to an alist in the form `((STRING . CHARACTER)...)' it -will augment the mode's native prettify alist." - :type '(choice - (const :tag "No thanks" nil) - (const :tag "Mode defaults" t) - (alist :tag "Mode defaults augmented with your own list" - :key-type string :value-type character)) - :version "24.4") - -(defun prog--prettify-font-lock-compose-symbol (alist) - "Compose a sequence of ascii chars into a symbol. +(defvar-local prettify-symbols-alist nil + "Alist of symbol prettifications. +Each element looks like (SYMBOL . CHARACTER), where the symbol +matching SYMBOL (a string, not a regexp) will be shown as +CHARACTER instead.") + +(defun prettify-symbols--compose-symbol (alist) + "Compose a sequence of characters 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)) @@ -88,28 +81,48 @@ ;; Return nil because we're not adding any face property. nil) -(defun prog-prettify-font-lock-symbols-keywords () - (when prog-prettify-symbols - (let ((alist (append prog-prettify-symbols-alist - (if (listp prog-prettify-symbols) - prog-prettify-symbols - nil)))) - `((,(regexp-opt (mapcar 'car alist) t) - (0 (prog--prettify-font-lock-compose-symbol ',alist))))))) - -(defun prog-prettify-install (alist) -"Install prog-mode support to prettify symbols according to ALIST. - -ALIST is in the format `((STRING . CHARACTER)...)' like -`prog-prettify-symbols'. - -Internally, `font-lock-add-keywords' is called." - (setq-local prog-prettify-symbols-alist alist) - (let ((keywords (prog-prettify-font-lock-symbols-keywords))) - (when keywords - (font-lock-add-keywords nil keywords) - (setq-local font-lock-extra-managed-props - (cons 'composition font-lock-extra-managed-props))))) +(defun prettify-symbols--make-keywords () + (if prettify-symbols-alist + `((,(regexp-opt (mapcar 'car prettify-symbols-alist) t) + (0 (prettify-symbols--compose-symbol ',prettify-symbols-alist)))) + nil)) + +(defvar-local prettify-symbols--keywords nil) + +(define-minor-mode prettify-symbols-mode + "Toggle Prettify Symbols mode. +With a prefix argument ARG, enable Prettify Symbols mode if ARG is +positive, and disable it otherwise. If called from Lisp, enable +the mode if ARG is omitted or nil. + +When Prettify Symbols mode and font-locking are enabled, symbols are +prettified (displayed as composed characters) according to the rules +in `prettify-symbols-alist' (which see), which are locally defined +by major modes supporting prettifying. To use this mode, you should +enable it in the major mode hook, and optionally extend the default +set of prettifications, like this: + + (add-hook 'emacs-lisp-mode-hook + (lambda () + (push '(\"<=3D\" . ?=E2=89=A4) prettify-symbols-alist) + (prettify-symbols-mode 1)))" + :init-value nil + (if prettify-symbols-mode + ;; Turn on + (when (setq prettify-symbols--keywords (prettify-symbols--make-keywo= rds)) + (font-lock-add-keywords nil prettify-symbols--keywords) + (setq-local font-lock-extra-managed-props + (cons 'composition font-lock-extra-managed-props)) + (font-lock-fontify-buffer)) + ;; Turn off + (when prettify-symbols--keywords + (font-lock-remove-keywords nil prettify-symbols--keywords) + (setq prettify-symbols--keywords nil)) + (when (memq 'composition font-lock-extra-managed-props) + (setq font-lock-extra-managed-props (delq 'composition + font-lock-extra-managed-pr= ops)) + (with-silent-modifications + (remove-text-properties (point-min) (point-max) '(composition nil)= ))))) ;;;###autoload (define-derived-mode prog-mode fundamental-mode "Prog"