all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Problem Undoing Text Properties In Gnu Emacs 24,  Is this a bug?
@ 2014-12-12 22:02 gtr289
  2014-12-14  5:06 ` Michael Heerdegen
       [not found] ` <mailman.16016.1418533637.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: gtr289 @ 2014-12-12 22:02 UTC (permalink / raw)
  To: help-gnu-emacs


Hello All,

I'm seeing a problem in Gnu Emacs 24.3.1 with undoing some text properties from some lisp code I wrote years ago as a light-weight C/C++ syntax highlighter that grays out C comments.  I never had a problem with Gnu Emacs 19, 20, 21 versions. I've tested this in Gnu Emacs 21.2.1 . 

I work under Redhat 5 and also Cygwin and the problem exists in both. For some reason, after turning on rear-nonsticky the undo ring breaks. 

 To illustrate the problem I've included a skimmed down .el file that shows the basis of how it functions. 

Put it as test.el in $HOME directory and run:

"emacs -l ~/test.el"

Set a buffer in c++-mode and type some junk after a start comment BUT DON'T CLOSE THE COMMENT:

---->  /* wejhjhjkr hjw hwre

I used "red" for the comment color..

Now start hitting undo (f12) until all is gone and everything works fine.

Now, in c++-mode do it again and CLOSE THE COMMENT AND PUT SOME JUNK AROUND BOTH SIDES

--->  eqwe eqweqwe eqwqe    /* rrwrwr ewr rwrwe  */  ewqeq eqeqeqw eqwe

Start undoing with f12 key. It may not bug the first time but after a few attempts the undo ring will get stuck..  Try it multiple times..


Is this a bug ?  Why does it work in Emacs 21 ?   Is there a fix for this ?  Or a remedy ?

Any help is greatly appreciated..

Joe


Below is the example code:


;;;;;;;;;;;;;;;;;;;;;;;;;;
; Disable font-lock-mode ;
;;;;;;;;;;;;;;;;;;;;;;;;;;

(set-variable 'global-font-lock-mode  nil) 
(global-font-lock-mode 0)

;;;;;;;;;;;;;;;;;
; f12 is undo.. ;
;;;;;;;;;;;;;;;;;

(global-unset-key [f12] )
(global-set-key   [f12] 'undo)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Functions for setting text properties (maintain modify status) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun jk-set-text-properties (p1 p2 state)
    (interactive)
    (let ( (modflag (buffer-modified-p)) )
       (set-text-properties p1 p2 state)
       (if (not modflag)
	   (set-buffer-modified-p nil))))

(defun jk-add-text-properties (p1 p2 prop) 
    (interactive)
    (let ( (modflag (buffer-modified-p)) )
       (add-text-properties p1 p2 prop)
       (if (not modflag)
	   (set-buffer-modified-p nil))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;  do-syntax looks for c+ comments --> /* ... */   ;
1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun do-syntax ()    
  (interactive)
  (let ()
    (cond
      (  (and (>= (point) 3)                          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	     (equal (char-after (- (point) 2)) ?/ )       ;; we just type a start of comment -->  /*   ;
	     (equal (char-after (- (point) 1)) ?* ) )     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
	 
	     (setq savepos (point))
	     (save-excursion                                                                    ;;;;;;;;;;;;;;;;; 
		    (jk-set-text-properties (- savepos 2)  savepos '(face '(:foreground  "red") ))  ;; turn on red  ;
         )                                                                                  ;;;;;;;;;;;;;;;;;
      )

      (  (and (> (point) 2)                        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	     (equal (char-after (- (point) 2)) ?* )    ;; we just typed close of comment -->  */  ;
	     (equal (char-after (- (point) 1)) ?/ ) )  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
           
	     (setq savepos (point))
	     (save-excursion                                                       ;;;;;;;;;;;;;;;;;;;;;;
	       (jk-add-text-properties  (-(point)1) (point) '(rear-nonsticky t ))  ;; End the comment   ;
         )                                                                     ;;;;;;;;;;;;;;;;;;;;;;
      ) 
    )  ;; cond
  ) ;; let
  nil          
) ;; end do-syntax


(setq  post-command-hook  nil)

(add-hook 'post-command-hook
     (function 
       (lambda ()
	 (do-syntax))))



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problem Undoing Text Properties In Gnu Emacs 24,  Is this a bug?
  2014-12-12 22:02 Problem Undoing Text Properties In Gnu Emacs 24, Is this a bug? gtr289
@ 2014-12-14  5:06 ` Michael Heerdegen
       [not found] ` <mailman.16016.1418533637.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2014-12-14  5:06 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: gtr289

Hello,

> (add-hook 'post-command-hook
>      (function 
>        (lambda ()
> 	 (do-syntax))))

With this code, after you undo, `do-syntax' is called immediately and
may add the text properties anew where the undo may have had removed
them, so it is no surprise if you encounter a "loop" sometimes, I guess.

BTW, what is the purpose of your code, and why is font-lock-mode not
sufficient for your needs?


Michael.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problem Undoing Text Properties In Gnu Emacs 24,  Is this a bug?
       [not found] ` <mailman.16016.1418533637.1147.help-gnu-emacs@gnu.org>
@ 2014-12-15 21:43   ` gtr289
  2014-12-16 12:51     ` Michael Heerdegen
  2014-12-17  1:53     ` Robert Thorpe
  0 siblings, 2 replies; 5+ messages in thread
From: gtr289 @ 2014-12-15 21:43 UTC (permalink / raw)
  To: help-gnu-emacs

On Sunday, December 14, 2014 12:07:20 AM UTC-5, Michael Heerdegen wrote:
> Hello,
> 
> > (add-hook 'post-command-hook
> >      (function 
> >        (lambda ()
> > 	 (do-syntax))))
> 
> With this code, after you undo, `do-syntax' is called immediately and
> may add the text properties anew where the undo may have had removed
> them, so it is no surprise if you encounter a "loop" sometimes, I guess.
> 
> BTW, what is the purpose of your code, and why is font-lock-mode not
> sufficient for your needs?
> 
> 
> Michael.


Hello Michael,

Thank you for the response. Yes, that definitely was the problem. My routine is called after an undo and thus would reverse and re-apply the text properties. Gnu Emacs 21 did not behave like this. It was easy to fix by examining the value of last-input-event..

The reason I use it is because I've noticed performance issues with font-lock-mode on large C/C++ files (which I have some huge ones). Also, I only prefer the comments to be highlighted. I don't need the different constructs, strings, keywords..  Over the years I've had good performance commenting the entire file on the find-file-hook then supporting real-time commenting as I type.

Perhaps I will re-visit font-lock-mode again when I have some time. If it can be configured to highlight only comments with good performance, I would want to head in that directions..

Thanks again for your help..

Joe


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problem Undoing Text Properties In Gnu Emacs 24,  Is this a bug?
  2014-12-15 21:43   ` gtr289
@ 2014-12-16 12:51     ` Michael Heerdegen
  2014-12-17  1:53     ` Robert Thorpe
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2014-12-16 12:51 UTC (permalink / raw)
  To: help-gnu-emacs

gtr289@gmail.com writes:

> The reason I use it is because I've noticed performance issues with
> font-lock-mode on large C/C++ files (which I have some huge
> ones).

I don't use C or C++.  Maybe the issues have been fixed in the meantime.

If performance is still a problem and you can reproduce it with some
files, maybe file a bug report.

> Perhaps I will re-visit font-lock-mode again when I have some time. If
> it can be configured to highlight only comments with good performance,
> I would want to head in that directions..

You would probably need to redefine `font-lock-defaults' variable to do
that.  Have a look at the `c-font-lock-keywords' related stuff in
"cc-fonts.el".


Regards,

Michael.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problem Undoing Text Properties In Gnu Emacs 24,  Is this a bug?
  2014-12-15 21:43   ` gtr289
  2014-12-16 12:51     ` Michael Heerdegen
@ 2014-12-17  1:53     ` Robert Thorpe
  1 sibling, 0 replies; 5+ messages in thread
From: Robert Thorpe @ 2014-12-17  1:53 UTC (permalink / raw)
  To: gtr289; +Cc: help-gnu-emacs

gtr289@gmail.com writes:
> Perhaps I will re-visit font-lock-mode again when I have some time. If
> it can be configured to highlight only comments with good performance,
> I would want to head in that directions..

If you use large buffers it can be useful to use the command
jit-lock-stealth-fontify.  If you leave Emacs idle it will use that time
to fontify the off-screen text.  Normally Emacs doesn't do
this, it only fontifies as you move through text looking at the context
around point.

There's a variable jit-lock-stealth-time that specifies how many seconds
of idle time Emacs will wait before doing this.  If you're the kind of
person who loads up Emacs with everything he needs in the morning then
goes to get a cup of coffee then everything should be fontified by the
time you've got back.

BR,
Robert Thorpe



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-12-17  1:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-12 22:02 Problem Undoing Text Properties In Gnu Emacs 24, Is this a bug? gtr289
2014-12-14  5:06 ` Michael Heerdegen
     [not found] ` <mailman.16016.1418533637.1147.help-gnu-emacs@gnu.org>
2014-12-15 21:43   ` gtr289
2014-12-16 12:51     ` Michael Heerdegen
2014-12-17  1:53     ` Robert Thorpe

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.