From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] master 188f657: Fix false negatives in tex--prettify-symbols-compose-p. Date: Wed, 30 Sep 2015 08:48:14 +0100 Message-ID: References: <20150925210512.18505.12538@vcs.savannah.gnu.org> <8737xxjtkq.fsf@gnu.org> <87twqcwgiw.fsf@gnu.org> Reply-To: bruce.connor.am@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11333e2222c1210520f22748 X-Trace: ger.gmane.org 1443675520 16137 80.91.229.3 (1 Oct 2015 04:58:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 Oct 2015 04:58:40 +0000 (UTC) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 01 06:58:40 2015 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 1ZhVx0-0006gD-Cc for ged-emacs-devel@m.gmane.org; Thu, 01 Oct 2015 06:58:38 +0200 Original-Received: from localhost ([::1]:37770 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhVwz-0000gc-SW for ged-emacs-devel@m.gmane.org; Thu, 01 Oct 2015 00:58:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhC7g-0006y4-DY for emacs-devel@gnu.org; Wed, 30 Sep 2015 03:48:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhC7b-0003SZ-Ij for emacs-devel@gnu.org; Wed, 30 Sep 2015 03:48:20 -0400 Original-Received: from mail-la0-x22c.google.com ([2a00:1450:4010:c03::22c]:36380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhC7b-0003SI-62 for emacs-devel@gnu.org; Wed, 30 Sep 2015 03:48:15 -0400 Original-Received: by laclj5 with SMTP id lj5so35914021lac.3 for ; Wed, 30 Sep 2015 00:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=tlcbipdk2FAgSswd+czsEexFlHYQPcexDexEpvmlLKA=; b=IT9z1p+hq1ueTJcH22PPhTjlCuEo73c5XdAZ3txyi5aFX6VYskqxoyZoSZ52nLdQmj eFWbIk9qezcTWIX9gCRRu8YScGxu1+EEPeGlgCBuM//2Wm7UieR0KYtfnZQcbf/Ecaf6 bCrLwlQS6/V/d4yrIAG5FjBw+60h7N1Hrm6R8lHrO7T/fdgH/leuz2ZC7sxG5p6ypRSb RLY5sopQw0iYn0x6USIY/OnNCjJymvi1KXqa9Ylb6s9vV5Ajhide+dZVh0sMjXtK6FQc ojg2VECrU9tFrKLlh65Un8RuDq4o49bkxklAXDpotJEHMEDQcCvosXy8cpZjA4MBa3IN UOfA== X-Received: by 10.152.10.241 with SMTP id l17mr694568lab.35.1443599294311; Wed, 30 Sep 2015 00:48:14 -0700 (PDT) Original-Received: by 10.25.27.78 with HTTP; Wed, 30 Sep 2015 00:48:14 -0700 (PDT) Original-Received: by 10.25.27.78 with HTTP; Wed, 30 Sep 2015 00:48:14 -0700 (PDT) In-Reply-To: <87twqcwgiw.fsf@gnu.org> X-Google-Sender-Auth: A5aa3XrF_MoHAFhf6opNEO3XePg X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::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:190494 Archived-At: --001a11333e2222c1210520f22748 Content-Type: text/plain; charset=UTF-8 Hi Tassilo, Nice! The code looks good to me, I'll give it a try later today. Looks like you went a bit further than me to overcome the traps. On 30 Sep 2015 7:46 am, "Tassilo Horn" wrote: > Artur Malabarba writes: > > Hi Artur, > > >> where `prettify-symbols-compose-at-point' would be the user option. > > > > I tried something similar, and unfortunately it's not that simple. > > Firstly, (window-point) didn't seem to work as expected here, so I had > > to define a variable in font-lock-mode to hold the value of (point) > > before fontification started. > > > > After doing that, the feature sort of works while you're writing. That > > is, it doesn't prettify a symbol you've just written, but it does > > prettify a symbol after you hit SPC, which is nice. However, it does > > not work while navigating. That is, when you move point to a > > prettified symbol, it doesn't get decomposed. > > > > Then I tried adding a post-command-hook function to invalidate the > > font-locking at point. This correctly decomposes a symbol when you > > move the cursor to it, but it's still not perfect. When you move the > > cursor *out* of the symbol, if you move far enough, the symbol doesn't > > get prettified again until you edit something close to it. > > Hehe, seems we tried implementing that feature at the same time and both > fell into the very same traps. Did you see my other mail? I have > gotten it working nicely right yesterday. Right now I did some minor > changes, and that's the current version of the patch: > > Comments welcome! > > --8<---------------cut here---------------start------------->8--- > 1 file changed, 39 insertions(+), 4 deletions(-) > lisp/progmodes/prog-mode.el | 43 +++++++++++++++++++++++++++++++++++++++---- > > modified lisp/progmodes/prog-mode.el > @@ -29,7 +29,8 @@ > > ;;; Code: > > -(eval-when-compile (require 'cl-lib)) > +(eval-when-compile (require 'cl-lib) > + (require 'subr-x)) > > (defgroup prog-mode nil > "Generic programming mode, from which others derive." > @@ -161,13 +162,20 @@ prettify-symbols--compose-symbol > (let ((start (match-beginning 0)) > (end (match-end 0)) > (match (match-string 0))) > - (if (funcall prettify-symbols-compose-predicate start end match) > + (if (and (not (equal prettify-symbols--current-symbol-bounds (list start end))) > + (funcall prettify-symbols-compose-predicate start end match)) > ;; That's a symbol alright, so add the composition. > - (compose-region start end (cdr (assoc match alist))) > + (progn > + (compose-region start end (cdr (assoc match alist))) > + (add-text-properties > + start end > + `(prettify-symbols-start ,start prettify-symbols-end ,end))) > ;; 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)))) > + (remove-text-properties start end '(composition > + prettify-symbols-start > + prettify-symbols-end)))) > ;; Return nil because we're not adding any face property. > nil) > > @@ -179,6 +187,29 @@ prettify-symbols--make-keywords > > (defvar-local prettify-symbols--keywords nil) > > +(defvar-local prettify-symbols--current-symbol-bounds nil) > + > +(defun prettify-symbols--post-command-hook () > + (if-let ((c (get-text-property (point) 'composition)) > + (s (get-text-property (point) 'prettify-symbols-start)) > + (e (get-text-property (point) 'prettify-symbols-end))) > + (progn > + (setq prettify-symbols--current-symbol-bounds (list s e)) > + (remove-text-properties s e '(composition))) > + (when (and prettify-symbols--current-symbol-bounds > + (or (< (point) (car prettify-symbols--current-symbol-bounds)) > + (>= (point) (cadr prettify-symbols--current-symbol-bounds)))) > + (apply #'font-lock-flush prettify-symbols--current-symbol-bounds) > + (setq prettify-symbols--current-symbol-bounds nil)))) > + > +(defcustom prettify-symbols-unprettify-at-point t > + "If non-nil, show the non-prettified version of a symbol when point is on it. > +The prettification will be reapplied as soon as point moves away > +from the symbol. If set to nil, the prettification persists even > +when point is on the symbol." > + :type 'boolean > + :group 'prog-mode) > + > ;;;###autoload > (define-minor-mode prettify-symbols-mode > "Toggle Prettify Symbols mode. > @@ -206,8 +237,12 @@ prettify-symbols-mode > (font-lock-add-keywords nil prettify-symbols--keywords) > (setq-local font-lock-extra-managed-props > (cons 'composition font-lock-extra-managed-props)) > + (when prettify-symbols-unprettify-at-point > + (add-hook 'post-command-hook > + #'prettify-symbols--post-command-hook nil t)) > (font-lock-flush)) > ;; Turn off > + (remove-hook 'post-command-hook #'prettify-symbols--post-command-hook t) > (when prettify-symbols--keywords > (font-lock-remove-keywords nil prettify-symbols--keywords) > (setq prettify-symbols--keywords nil)) > --8<---------------cut here---------------end--------------->8--- > > Bye, > Tassilo --001a11333e2222c1210520f22748 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Hi Tassilo,

Nice!

The code looks good to me, I'll give it a try later toda= y. Looks like you went a bit further than me to overcome the traps.

On 30 Sep 2015 7:46 am, "Tassilo Horn" <tsdh@gnu.org> wrote:

> Artur Malabarba <bruce.connor.am@gmail.com> writes:
>
> Hi Artur,
>
> >> where `prettify-symbols-compose-at-point' would be the us= er option.
> >
> > I tried something similar, and unfortunately it's not that si= mple.
> > Firstly, (window-point) didn't seem to work as expected here,= so I had
> > to define a variable in font-lock-mode to hold the value of (poin= t)
> > before fontification started.
> >
> > After doing that, the feature sort of works while you're writ= ing. That
> > is, it doesn't prettify a symbol you've just written, but= it does
> > prettify a symbol after you hit SPC, which is nice.=C2=A0 However= , it does
> > not work while navigating. That is, when you move point to a
> > prettified symbol, it doesn't get decomposed.
> >
> > Then I tried adding a post-command-hook function to invalidate th= e
> > font-locking at point. This correctly decomposes a symbol when yo= u
> > move the cursor to it, but it's still not perfect. When you m= ove the
> > cursor *out* of the symbol, if you move far enough, the symbol do= esn't
> > get prettified again until you edit something close to it.
>
> Hehe, seems we tried implementing that feature at the same time and bo= th
> fell into the very same traps.=C2=A0 Did you see my other mail?=C2=A0 = I have
> gotten it working nicely right yesterday.=C2=A0 Right now I did some m= inor
> changes, and that's the current version of the patch:
>
> Comments welcome!
>
> --8<---------------cut here---------------start------------->8--= -
> 1 file changed, 39 insertions(+), 4 deletions(-)
> lisp/progmodes/prog-mode.el | 43 +++++++++++++++++++++++++++++++++++++= ++----
>
> modified=C2=A0 =C2=A0lisp/progmodes/prog-mode.el
> @@ -29,7 +29,8 @@
>
> =C2=A0;;; Code:
>
> -(eval-when-compile (require 'cl-lib))
> +(eval-when-compile (require 'cl-lib)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (require 'subr-x))
>
> =C2=A0(defgroup prog-mode nil
> =C2=A0 =C2=A0"Generic programming mode, from which others derive.= "
> @@ -161,13 +162,20 @@ prettify-symbols--compose-symbol
> =C2=A0 =C2=A0(let ((start (match-beginning 0))
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(end (match-end 0))
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(match (match-string 0)))
> -=C2=A0 =C2=A0 (if (funcall prettify-symbols-compose-predicate start e= nd match)
> +=C2=A0 =C2=A0 (if (and (not (equal prettify-symbols--current-symbol-b= ounds (list start end)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(funcall prettify-sym= bols-compose-predicate start end match))
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; That's a symbol alright, so a= dd the composition.
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 (compose-region start end (cdr (assoc mat= ch alist)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (compose-region start end (cdr (as= soc match alist)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (add-text-properties
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0start end
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0`(prettify-symbols-start ,st= art prettify-symbols-end ,end)))
> =C2=A0 =C2=A0 =C2=A0 =C2=A0;; No composition for you.=C2=A0 Let's = actually remove any
> =C2=A0 =C2=A0 =C2=A0 =C2=A0;; composition we may have added earlier an= d which is now
> =C2=A0 =C2=A0 =C2=A0 =C2=A0;; incorrect.
> -=C2=A0 =C2=A0 =C2=A0 (remove-text-properties start end '(composit= ion))))
> +=C2=A0 =C2=A0 =C2=A0 (remove-text-properties start end '(composit= ion
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 prettify-symbols-start
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 prettify-symbols-end))))
> =C2=A0 =C2=A0;; Return nil because we're not adding any face prope= rty.
> =C2=A0 =C2=A0nil)
>
> @@ -179,6 +187,29 @@ prettify-symbols--make-keywords
>
> =C2=A0(defvar-local prettify-symbols--keywords nil)
>
> +(defvar-local prettify-symbols--current-symbol-bounds nil)
> +
> +(defun prettify-symbols--post-command-hook ()
> +=C2=A0 (if-let ((c (get-text-property (point) 'composition))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(s (get-text-property (point= ) 'prettify-symbols-start))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(e (get-text-property (point= ) 'prettify-symbols-end)))
> +=C2=A0 =C2=A0 =C2=A0 (progn
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq prettify-symbols--current-symbol-bo= unds (list s e))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 (remove-text-properties s e '(composi= tion)))
> +=C2=A0 =C2=A0 (when (and prettify-symbols--current-symbol-bounds
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or (< (poi= nt) (car prettify-symbols--current-symbol-bounds))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (>=3D (point) (cadr prettify-symbols--current-symbol-bounds))))
> +=C2=A0 =C2=A0 =C2=A0 (apply #'font-lock-flush prettify-symbols--c= urrent-symbol-bounds)
> +=C2=A0 =C2=A0 =C2=A0 (setq prettify-symbols--current-symbol-bounds ni= l))))
> +
> +(defcustom prettify-symbols-unprettify-at-point t
> +=C2=A0 "If non-nil, show the non-prettified version of a symbol = when point is on it.
> +The prettification will be reapplied as soon as point moves away
> +from the symbol.=C2=A0 If set to nil, the prettification persists eve= n
> +when point is on the symbol."
> +=C2=A0 :type 'boolean
> +=C2=A0 :group 'prog-mode)
> +
> =C2=A0;;;###autoload
> =C2=A0(define-minor-mode prettify-symbols-mode
> =C2=A0 =C2=A0"Toggle Prettify Symbols mode.
> @@ -206,8 +237,12 @@ prettify-symbols-mode
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(font-lock-add-keywords nil prettify= -symbols--keywords)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq-local font-lock-extra-managed-= props
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(cons 'composition font-lock-extra-managed-props))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 (when prettify-symbols-unprettify-at-poin= t
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (add-hook 'post-command-hook > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= #'prettify-symbols--post-command-hook nil t))
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(font-lock-flush))
> =C2=A0 =C2=A0 =C2=A0;; Turn off
> +=C2=A0 =C2=A0 (remove-hook 'post-command-hook #'prettify-symb= ols--post-command-hook t)
> =C2=A0 =C2=A0 =C2=A0(when prettify-symbols--keywords
> =C2=A0 =C2=A0 =C2=A0 =C2=A0(font-lock-remove-keywords nil prettify-sym= bols--keywords)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq prettify-symbols--keywords nil))
> --8<---------------cut here---------------end--------------->8--= -
>
> Bye,
> Tassilo

--001a11333e2222c1210520f22748--