From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] master 188f657: Fix false negatives in tex--prettify-symbols-compose-p. Date: Tue, 29 Sep 2015 21:46:49 +0200 Message-ID: <87y4fphuty.fsf@gnu.org> References: <20150925210512.18505.12538@vcs.savannah.gnu.org> <8737xxjtkq.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1443646438 23797 80.91.229.3 (30 Sep 2015 20:53:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 30 Sep 2015 20:53:58 +0000 (UTC) Cc: emacs-devel To: Artur Malabarba Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 30 22:53:45 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 1ZhONi-0000jq-VB for ged-emacs-devel@m.gmane.org; Wed, 30 Sep 2015 22:53:43 +0200 Original-Received: from localhost ([::1]:33013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhONi-0001hQ-6R for ged-emacs-devel@m.gmane.org; Wed, 30 Sep 2015 16:53:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zh0rc-00026J-8t for emacs-devel@gnu.org; Tue, 29 Sep 2015 15:47:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zh0rX-0004DE-1n for emacs-devel@gnu.org; Tue, 29 Sep 2015 15:47:00 -0400 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:41002) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zh0rW-0004Ct-KA for emacs-devel@gnu.org; Tue, 29 Sep 2015 15:46:54 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4E76B2027A for ; Tue, 29 Sep 2015 15:46:54 -0400 (EDT) Original-Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Tue, 29 Sep 2015 15:46:54 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=N8cFWLE9tZb05+5blFyyNshidbc=; b=F6gz7 Eg882ac73Fd70nTMlv+QKU8wlVui4jHBnYUfm1KNAC5o+ZdZCYZWKSFwYGsngKGC QCxsVY38UUMseChEZ42YqJ50oxzuUMrRFq2pH6FO/uPnSABT5VYhJa9VbYIgdRMH koN4Rw9lgyoFCsForKff030sdDIFldGn62XQBA= X-Sasl-enc: Q9knaG8oOWCMq5XHzkSpSFI7CWKGG4LLw7HlwPre8f+w 1443556013 Original-Received: from thinkpad-t440p (unknown [2.162.29.221]) by mail.messagingengine.com (Postfix) with ESMTPA id 190E4C0001A; Tue, 29 Sep 2015 15:46:52 -0400 (EDT) Mail-Followup-To: Artur Malabarba , emacs-devel In-Reply-To: <8737xxjtkq.fsf@gnu.org> (Tassilo Horn's message of "Tue, 29 Sep 2015 14:31:01 +0200") User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 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:190484 Archived-At: Tassilo Horn writes: Hi Artur, >> Would it be possible to also use `tex--prettify-symbols-compose-p' to >> avoid composing the symbol-at-point? (perhaps by checking >> window-point or something). That would toggleable by a user-option, >> of course. > > You mean, when point enters a prettified symbol the original text > would be shown? Indeed, that sounds like a neat idea. If I think > about it, I don't use prettification in LaTeX exactly because there > are so many prettified symbols which partly overlap and then editing > becomes cumbersome, e.g., when deleting a char from the prettified > integral \int you'll get the prettification of the set membership > relation \in. > >> Or maybe that feature should be implemented in `prettify-symbols-mode' >> itself. > > Yes, I think the only thing to be done would be to change the > > (if (funcall prettify-symbols-compose-predicate start end match) ... > > in `prettify-symbols--compose-symbol' to > > (if (and (or prettify-symbols-compose-at-point > (< (window-point) start) > (> (window-point) end)) > (funcall prettify-symbols-compose-predicate start end match))) > > where `prettify-symbols-compose-at-point' would be the user option. Well, this approach didn't work because during font-lock both `point' and `window-point' equal `end', i.e., the end of the match of the search font-lock performed. Then I experimented with the `point-entered' and `point-left' text properties but apparently the functions I added there were never ever called. On the internets I have read that these two props are much more low-level than what one would expect and in general it would be better to track point in a `post-command-hook'. So that's what I did, and the following patch works fine for me. Comments welcome! --8<---------------cut here---------------start------------->8--- prettify-symbols-ext 7c2ef9b8948df4c05d0c0aa28d85a128f975e453 Author: Tassilo Horn AuthorDate: Tue Sep 29 21:34:18 2015 +0200 Commit: Tassilo Horn CommitDate: Tue Sep 29 21:34:18 2015 +0200 Parent: 888d644 * net/shr.el (shr-colorize-region): Don't do it on a system not supporting 256 above colors (bug#21557). Merged: master prettify-symbols-ext Containing: prettify-symbols-ext Follows: emacs-24.5-rc3-fixed (6045) Implement unprettification of symbol at point * lisp/progmodes/prog-mode.el: Implement feature for unprettifying the symbol at point. (prettify-symbols--current-symbol-bounds): New variable. (prettify-symbols--post-command-hook): New function. (prettify-symbols-unprettify-at-point): New defcustom. (prettify-symbols-mode): Use it. (prettify-symbols--compose-symbol): Use them. 1 file changed, 36 insertions(+), 3 deletions(-) lisp/progmodes/prog-mode.el | 39 ++++++++++++++++++++++++++++++++++++--- modified lisp/progmodes/prog-mode.el @@ -161,13 +161,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 +186,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 ((_ (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,6 +236,9 @@ 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 (when prettify-symbols--keywords --8<---------------cut here---------------end--------------->8--- Bye, Tassilo